shader refactors

This commit is contained in:
turanszkij
2019-05-14 21:30:56 +01:00
parent 51440d3076
commit e840f61942
17 changed files with 573 additions and 406 deletions
+3
View File
@@ -882,6 +882,9 @@ void MaterialWindow::SetEntity(Entity entity)
ss << material->uvset_surfaceMap;
texture_surface_uvset_Field->SetText(ss.str());
ss.str("");
ss << material->uvset_displacementMap;
texture_displacement_uvset_Field->SetText(ss.str());
ss.str("");
ss << material->uvset_emissiveMap;
texture_emissive_uvset_Field->SetText(ss.str());
ss.str("");
+10 -10
View File
@@ -95,13 +95,13 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex)
float4 pos_nor2 = asfloat(meshVertexBuffer_POS.Load4(i2 * xTraceBVHMeshVertexPOSStride));
uint nor_u = asuint(pos_nor0.w);
uint materialIndex;
uint subsetIndex;
float3 nor0;
{
nor0.x = (float)((nor_u >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
nor0.y = (float)((nor_u >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
nor0.z = (float)((nor_u >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
materialIndex = (nor_u >> 24) & 0x000000FF;
subsetIndex = (nor_u >> 24) & 0x000000FF;
}
nor_u = asuint(pos_nor1.w);
float3 nor1;
@@ -122,6 +122,8 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex)
// Transform triangle into world space and store:
float4x4 WORLD = xTraceBVHWorld;
const uint materialIndex = xTraceBVHMaterialOffset + subsetIndex;
TracedRenderingMaterial material = materialBuffer[materialIndex];
BVHMeshTriangle prim;
prim.v0 = mul(WORLD, float4(pos_nor0.xyz, 1)).xyz;
@@ -130,20 +132,18 @@ void main(uint3 DTid : SV_DispatchThreadID, uint groupIndex : SV_GroupIndex)
prim.n0 = mul((float3x3)WORLD, nor0);
prim.n1 = mul((float3x3)WORLD, nor1);
prim.n2 = mul((float3x3)WORLD, nor2);
prim.u0 = float4(meshVertexBuffer_UV0[i0], meshVertexBuffer_UV1[i0]);
prim.u1 = float4(meshVertexBuffer_UV0[i1], meshVertexBuffer_UV1[i1]);
prim.u2 = float4(meshVertexBuffer_UV0[i2], meshVertexBuffer_UV1[i2]);
prim.materialIndex = xTraceBVHMaterialOffset + materialIndex;
prim.u0 = float4(meshVertexBuffer_UV0[i0] * material.texMulAdd.xy + material.texMulAdd.zw, meshVertexBuffer_UV1[i0]);
prim.u1 = float4(meshVertexBuffer_UV0[i1] * material.texMulAdd.xy + material.texMulAdd.zw, meshVertexBuffer_UV1[i1]);
prim.u2 = float4(meshVertexBuffer_UV0[i2] * material.texMulAdd.xy + material.texMulAdd.zw, meshVertexBuffer_UV1[i2]);
prim.materialIndex = materialIndex;
TracedRenderingMaterial mat = materialBuffer[prim.materialIndex];
float4 color = xTraceBVHInstanceColor * mat.baseColor;
float4 color = xTraceBVHInstanceColor * material.baseColor;
prim.c0 = color;
prim.c1 = color;
prim.c2 = color;
[branch]
if (mat.useVertexColors)
if (material.useVertexColors)
{
prim.c0 *= meshVertexBuffer_COL[i0];
prim.c1 *= meshVertexBuffer_COL[i1];
+12 -3
View File
@@ -2,9 +2,18 @@
float4 main(PixelInputType input) : SV_Target0
{
const float2 UV_baseColorMap = g_xMat_uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
float4 color = xBaseColorMap.Sample(sampler_objectshader, UV_baseColorMap);
color.rgb = DEGAMMA(color.rgb);
float4 color;
[branch]
if (g_xMat_uvset_baseColorMap >= 0)
{
const float2 UV_baseColorMap = g_xMat_uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
color = xBaseColorMap.Sample(sampler_objectshader, UV_baseColorMap);
color.rgb = DEGAMMA(color.rgb);
}
else
{
color = 1;
}
color *= input.color;
ALPHATEST(color.a);
color.a = 1;
+7 -3
View File
@@ -7,9 +7,13 @@ float4 main(PixelInputType input) : SV_Target0
float3x3 TBN = compute_tangent_frame(N, P, input.uvsets.xy);
float3 bumpColor;
const float2 UV_normalMap = g_xMat_uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw;
NormalMapping(UV_normalMap, P, N, TBN, bumpColor);
[branch]
if (g_xMat_uvset_normalMap >= 0)
{
float3 bumpColor;
const float2 UV_normalMap = g_xMat_uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw;
NormalMapping(UV_normalMap, P, N, TBN, bumpColor);
}
return float4(N * 0.5f + 0.5f, 1);
}
+14 -5
View File
@@ -2,12 +2,21 @@
float4 main(PixelInputType input) : SV_Target0
{
const float2 UV_surfaceMap = g_xMat_uvset_surfaceMap == 0 ? input.uvsets.xy : input.uvsets.zw;
float4 surface_occlusion_roughness_metallic_reflectance = xSurfaceMap.Sample(sampler_objectshader, UV_surfaceMap);
if (g_xMat_specularGlossinessWorkflow)
float4 surface_occlusion_roughness_metallic_reflectance;
[branch]
if (g_xMat_uvset_surfaceMap >= 0)
{
ConvertToSpecularGlossiness(surface_occlusion_roughness_metallic_reflectance);
const float2 UV_surfaceMap = g_xMat_uvset_surfaceMap == 0 ? input.uvsets.xy : input.uvsets.zw;
surface_occlusion_roughness_metallic_reflectance = xSurfaceMap.Sample(sampler_objectshader, UV_surfaceMap);
if (g_xMat_specularGlossinessWorkflow)
{
ConvertToSpecularGlossiness(surface_occlusion_roughness_metallic_reflectance);
}
}
else
{
surface_occlusion_roughness_metallic_reflectance = 1;
}
float4 surface;
File diff suppressed because it is too large Load Diff
+7 -4
View File
@@ -124,10 +124,13 @@ PixelInputType main(ConstantOutputType input, float3 uvwCoord : SV_DomainLocatio
vertexNormal = PhongNormal(fU, fV, fW, input);
// Displacement
const float2 UV_displacementMap = g_xMat_uvset_displacementMap == 0 ? vertexUvsets.xy : vertexUvsets.zw;
float3 displacement = 1 - xDisplacementMap.SampleLevel(sampler_linear_wrap, UV_displacementMap, 0).rrr;
displacement *= vertexNormal.xyz;
displacement *= -g_xMat_displacementMapping;
float3 displacement = -g_xMat_displacementMapping * vertexNormal.xyz;
[branch]
if (g_xMat_uvset_displacementMap >= 0)
{
const float2 UV_displacementMap = g_xMat_uvset_displacementMap == 0 ? vertexUvsets.xy : vertexUvsets.zw;
displacement *= 1 - xDisplacementMap.SampleLevel(sampler_linear_wrap, UV_displacementMap, 0).rrr;
}
vertexPosition.xyz += displacement;
vertexPositionPrev.xyz += displacement;
+46 -22
View File
@@ -752,9 +752,18 @@ GBUFFEROutputType_Thin main(PIXELINPUT input)
ParallaxOcclusionMapping(input.uvsets, surface.V, TBN);
#endif // POM
const float2 UV_baseColorMap = g_xMat_uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
float4 color = xBaseColorMap.Sample(sampler_objectshader, UV_baseColorMap);
color.rgb = DEGAMMA(color.rgb);
float4 color;
[branch]
if (g_xMat_uvset_baseColorMap >= 0)
{
const float2 UV_baseColorMap = g_xMat_uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
color = xBaseColorMap.Sample(sampler_objectshader, UV_baseColorMap);
color.rgb = DEGAMMA(color.rgb);
}
else
{
color = 1;
}
color *= input.color;
ALPHATEST(color.a);
@@ -783,21 +792,31 @@ GBUFFEROutputType_Thin main(PIXELINPUT input)
NormalMapping(UV_normalMap, surface.P, surface.N, TBN, bumpColor);
#endif // NORMALMAP
const float2 UV_surfaceMap = g_xMat_uvset_surfaceMap == 0 ? input.uvsets.xy : input.uvsets.zw;
float4 surface_occlusion_roughness_metallic_reflectance = xSurfaceMap.Sample(sampler_objectshader, UV_surfaceMap);
if (g_xMat_occlusion_primary == 0)
// Surface map:
float4 surface_occlusion_roughness_metallic_reflectance;
[branch]
if (g_xMat_uvset_surfaceMap >= 0)
{
surface_occlusion_roughness_metallic_reflectance.r = 1;
}
if (g_xMat_specularGlossinessWorkflow)
{
ConvertToSpecularGlossiness(surface_occlusion_roughness_metallic_reflectance);
const float2 UV_surfaceMap = g_xMat_uvset_surfaceMap == 0 ? input.uvsets.xy : input.uvsets.zw;
surface_occlusion_roughness_metallic_reflectance = xSurfaceMap.Sample(sampler_objectshader, UV_surfaceMap);
if (g_xMat_occlusion_primary == 0)
{
surface_occlusion_roughness_metallic_reflectance.r = 1;
}
if (g_xMat_specularGlossinessWorkflow)
{
ConvertToSpecularGlossiness(surface_occlusion_roughness_metallic_reflectance);
}
}
else
{
surface_occlusion_roughness_metallic_reflectance = 1;
}
// Emissive map:
float4 emissiveColor;
[branch]
if (g_xMat_emissiveColor.a > 0)
if (g_xMat_emissiveColor.a > 0 && g_xMat_uvset_emissiveMap >= 0)
{
const float2 UV_emissiveMap = g_xMat_uvset_emissiveMap == 0 ? input.uvsets.xy : input.uvsets.zw;
emissiveColor = xEmissiveMap.Sample(sampler_objectshader, UV_emissiveMap);
@@ -809,29 +828,30 @@ GBUFFEROutputType_Thin main(PIXELINPUT input)
emissiveColor = 0;
}
float occlusion = 1;
if (g_xMat_occlusion_secondary)
// Secondary occlusion map:
[branch]
if (g_xMat_occlusion_secondary && g_xMat_uvset_occlusionMap >= 0)
{
const float2 UV_occlusionMap = g_xMat_uvset_occlusionMap == 0 ? input.uvsets.xy : input.uvsets.zw;
occlusion = xOcclusionMap.Sample(sampler_objectshader, UV_occlusionMap).r;
surface_occlusion_roughness_metallic_reflectance.r *= xOcclusionMap.Sample(sampler_objectshader, UV_occlusionMap).r;
}
#ifndef SIMPLE_INPUT
#ifndef ENVMAPRENDERING
#ifndef TRANSPARENT
const float ssao = xSSAO.SampleLevel(sampler_linear_clamp, ReprojectedScreenCoord, 0).r;
occlusion *= ssao;
surface_occlusion_roughness_metallic_reflectance.r *= ssao;
#endif // TRANSPARENT
#endif // ENVMAPRENDERING
#endif // SIMPLE_INPUT
surface = CreateSurface(
surface.P,
surface.N,
surface.V,
color,
surface_occlusion_roughness_metallic_reflectance.r * occlusion,
surface_occlusion_roughness_metallic_reflectance.r,
g_xMat_roughness * surface_occlusion_roughness_metallic_reflectance.g,
g_xMat_metalness * surface_occlusion_roughness_metallic_reflectance.b,
g_xMat_reflectance * surface_occlusion_roughness_metallic_reflectance.a,
@@ -851,9 +871,13 @@ GBUFFEROutputType_Thin main(PIXELINPUT input)
float2 bumpColor0 = 0;
float2 bumpColor1 = 0;
float2 bumpColor2 = 0;
const float2 UV_normalMap = g_xMat_uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw;
bumpColor0 = 2.0f * xNormalMap.Sample(sampler_objectshader, UV_normalMap - g_xMat_texMulAdd.ww).rg - 1.0f;
bumpColor1 = 2.0f * xNormalMap.Sample(sampler_objectshader, UV_normalMap + g_xMat_texMulAdd.zw).rg - 1.0f;
[branch]
if (g_xMat_uvset_normalMap >= 0)
{
const float2 UV_normalMap = g_xMat_uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw;
bumpColor0 = 2.0f * xNormalMap.Sample(sampler_objectshader, UV_normalMap - g_xMat_texMulAdd.ww).rg - 1.0f;
bumpColor1 = 2.0f * xNormalMap.Sample(sampler_objectshader, UV_normalMap + g_xMat_texMulAdd.zw).rg - 1.0f;
}
bumpColor2 = xWaterRipples.Sample(sampler_objectshader, ScreenCoord).rg;
bumpColor = float3(bumpColor0 + bumpColor1 + bumpColor2, 1) * g_xMat_refractionIndex;
surface.N = normalize(lerp(surface.N, mul(normalize(bumpColor), TBN), g_xMat_normalMapStrength));
+18 -18
View File
@@ -71,7 +71,7 @@ struct VertexSurface
float2 atlas;
float4 color;
float3 normal;
uint materialIndex;
uint subsetIndex;
float4 prevPos;
};
inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_POS input)
@@ -82,11 +82,11 @@ inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_POS input)
surface.color = g_xMat_baseColor * input.inst.color;
uint normal_wind_matID = asuint(input.pos.w);
surface.normal.x = (float)((normal_wind_matID >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.y = (float)((normal_wind_matID >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.z = (float)((normal_wind_matID >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.materialIndex = (normal_wind_matID >> 24) & 0x000000FF;
uint normal_subsetIndex = asuint(input.pos.w);
surface.normal.x = (float)((normal_subsetIndex >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.y = (float)((normal_subsetIndex >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.z = (float)((normal_subsetIndex >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.subsetIndex = (normal_subsetIndex >> 24) & 0x000000FF;
return surface;
}
@@ -98,13 +98,13 @@ inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_POS_TEX input)
surface.color = g_xMat_baseColor * input.inst.color;
uint normal_wind_matID = asuint(input.pos.w);
surface.normal.x = (float)((normal_wind_matID >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.y = (float)((normal_wind_matID >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.z = (float)((normal_wind_matID >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.materialIndex = (normal_wind_matID >> 24) & 0x000000FF;
uint normal_subsetIndex = asuint(input.pos.w);
surface.normal.x = (float)((normal_subsetIndex >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.y = (float)((normal_subsetIndex >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.z = (float)((normal_subsetIndex >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.subsetIndex = (normal_subsetIndex >> 24) & 0x000000FF;
surface.uvsets = float4(input.uv0, input.uv1) * g_xMat_texMulAdd.xyxy + g_xMat_texMulAdd.zwzw;
surface.uvsets = float4(input.uv0 * g_xMat_texMulAdd.xy + g_xMat_texMulAdd.zw, input.uv1);
return surface;
}
@@ -121,13 +121,13 @@ inline VertexSurface MakeVertexSurfaceFromInput(Input_Object_ALL input)
surface.color *= input.col;
}
uint normal_wind_matID = asuint(input.pos.w);
surface.normal.x = (float)((normal_wind_matID >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.y = (float)((normal_wind_matID >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.z = (float)((normal_wind_matID >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.materialIndex = (normal_wind_matID >> 24) & 0x000000FF;
uint normal_subsetIndex = asuint(input.pos.w);
surface.normal.x = (float)((normal_subsetIndex >> 0) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.y = (float)((normal_subsetIndex >> 8) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.normal.z = (float)((normal_subsetIndex >> 16) & 0x000000FF) / 255.0f * 2.0f - 1.0f;
surface.subsetIndex = (normal_subsetIndex >> 24) & 0x000000FF;
surface.uvsets = float4(input.uv0, input.uv1) * g_xMat_texMulAdd.xyxy + g_xMat_texMulAdd.zwzw;
surface.uvsets = float4(input.uv0 * g_xMat_texMulAdd.xy + g_xMat_texMulAdd.zw, input.uv1);
surface.atlas = input.atl * input.instAtlas.atlasMulAdd.xy + input.instAtlas.atlasMulAdd.zw;
+13 -4
View File
@@ -2,10 +2,19 @@
float4 main(PixelInputType input) : SV_TARGET
{
const float2 UV_baseColorMap = g_xMat_uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
float4 color = xBaseColorMap.Sample(sampler_objectshader, UV_baseColorMap);
color.rgb = DEGAMMA(color.rgb);
color.rgb = max(color.r, max(color.g, color.b));
float4 color;
[branch]
if (g_xMat_uvset_baseColorMap >= 0)
{
const float2 UV_baseColorMap = g_xMat_uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
color = xBaseColorMap.Sample(sampler_objectshader, UV_baseColorMap);
color.rgb = DEGAMMA(color.rgb);
color.rgb = max(color.r, max(color.g, color.b));
}
else
{
color = 1;
}
color *= input.color;
float time = g_xFrame_Time;
+13 -4
View File
@@ -23,14 +23,23 @@ void main(PSInput input)
[branch]
if (is_saturated(uvw))
{
const float2 UV_baseColorMap = g_xMat_uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
float4 baseColor = xBaseColorMap.Sample(sampler_linear_wrap, UV_baseColorMap);
baseColor.rgb = DEGAMMA(baseColor.rgb);
float4 baseColor;
[branch]
if (g_xMat_uvset_baseColorMap >= 0)
{
const float2 UV_baseColorMap = g_xMat_uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
baseColor = xBaseColorMap.Sample(sampler_linear_wrap, UV_baseColorMap);
baseColor.rgb = DEGAMMA(baseColor.rgb);
}
else
{
baseColor = 1;
}
baseColor *= input.color;
float4 color = baseColor;
float4 emissiveColor;
[branch]
if (g_xMat_emissiveColor.a > 0)
if (g_xMat_emissiveColor.a > 0 && g_xMat_uvset_emissiveMap >= 0)
{
const float2 UV_emissiveMap = g_xMat_uvset_emissiveMap == 0 ? input.uvsets.xy : input.uvsets.zw;
emissiveColor = xEmissiveMap.Sample(sampler_linear_wrap, UV_emissiveMap);
+36 -20
View File
@@ -294,36 +294,52 @@ inline float3 Shade(inout Ray ray, inout RayHit hit, inout float seed, in float2
hit.color = tri.c0 * w + tri.c1 * u + tri.c2 * v;
hit.materialIndex = tri.materialIndex;
TracedRenderingMaterial mat = materialBuffer[hit.materialIndex];
TracedRenderingMaterial material = materialBuffer[hit.materialIndex];
hit.uvsets = frac(hit.uvsets); // emulate wrap
const float2 UV_baseColorMap = mat.uvset_baseColorMap == 0 ? hit.uvsets.xy : hit.uvsets.zw;
float4 baseColorMap = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV_baseColorMap * mat.baseColorAtlasMulAdd.xy + mat.baseColorAtlasMulAdd.zw, 0);
const float2 UV_surfaceMap = mat.uvset_surfaceMap == 0 ? hit.uvsets.xy : hit.uvsets.zw;
float4 surface_occlusion_roughness_metallic_reflectance = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV_surfaceMap * mat.surfaceMapAtlasMulAdd.xy + mat.surfaceMapAtlasMulAdd.zw, 0);
if (mat.specularGlossinessWorkflow)
float4 baseColor;
[branch]
if (material.uvset_baseColorMap >= 0)
{
ConvertToSpecularGlossiness(surface_occlusion_roughness_metallic_reflectance);
const float2 UV_baseColorMap = material.uvset_baseColorMap == 0 ? hit.uvsets.xy : hit.uvsets.zw;
baseColor = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV_baseColorMap * material.baseColorAtlasMulAdd.xy + material.baseColorAtlasMulAdd.zw, 0);
baseColor.rgb = DEGAMMA(baseColor.rgb);
}
else
{
baseColor = 1;
}
baseColor *= hit.color;
float4 surface_occlusion_roughness_metallic_reflectance;
[branch]
if (material.uvset_surfaceMap >= 0)
{
const float2 UV_surfaceMap = material.uvset_surfaceMap == 0 ? hit.uvsets.xy : hit.uvsets.zw;
surface_occlusion_roughness_metallic_reflectance = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV_surfaceMap * material.surfaceMapAtlasMulAdd.xy + material.surfaceMapAtlasMulAdd.zw, 0);
if (material.specularGlossinessWorkflow)
{
ConvertToSpecularGlossiness(surface_occlusion_roughness_metallic_reflectance);
}
}
else
{
surface_occlusion_roughness_metallic_reflectance = 1;
}
float4 baseColor = baseColorMap;
baseColor.rgb = DEGAMMA(baseColor.rgb);
baseColor *= hit.color;
float roughness = mat.roughness * surface_occlusion_roughness_metallic_reflectance.g;
float metalness = mat.metalness * surface_occlusion_roughness_metallic_reflectance.b;
float reflectance = mat.reflectance * surface_occlusion_roughness_metallic_reflectance.a;
float roughness = material.roughness * surface_occlusion_roughness_metallic_reflectance.g;
float metalness = material.metalness * surface_occlusion_roughness_metallic_reflectance.b;
float reflectance = material.reflectance * surface_occlusion_roughness_metallic_reflectance.a;
roughness = sqr(roughness); // convert linear roughness to cone aperture
float4 emissiveColor;
[branch]
if (mat.emissiveColor.a > 0)
if (material.emissiveColor.a > 0 && material.uvset_emissiveMap >= 0)
{
const float2 UV_emissiveMap = mat.uvset_emissiveMap == 0 ? hit.uvsets.xy : hit.uvsets.zw;
emissiveColor = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV_emissiveMap * mat.emissiveMapAtlasMulAdd.xy + mat.emissiveMapAtlasMulAdd.zw, 0);
const float2 UV_emissiveMap = material.uvset_emissiveMap == 0 ? hit.uvsets.xy : hit.uvsets.zw;
emissiveColor = materialTextureAtlas.SampleLevel(sampler_linear_clamp, UV_emissiveMap * material.emissiveMapAtlasMulAdd.xy + material.emissiveMapAtlasMulAdd.zw, 0);
emissiveColor.rgb = DEGAMMA(emissiveColor.rgb);
emissiveColor *= mat.emissiveColor;
emissiveColor *= material.emissiveColor;
}
else
{
@@ -340,7 +356,7 @@ inline float3 Shade(inout Ray ray, inout RayHit hit, inout float seed, in float2
if (roulette < refractChance)
{
// Refraction
float3 R = refract(ray.direction, hit.N, 1 - mat.refractionIndex);
float3 R = refract(ray.direction, hit.N, 1 - material.refractionIndex);
ray.direction = lerp(R, SampleHemisphere(R, seed, pixel), roughness);
ray.energy *= lerp(baseColor.rgb, 1, refractChance);
+24 -11
View File
@@ -12,9 +12,18 @@ float4 main(VertextoPixel input) : SV_TARGET
{
float2 pixel = input.pos.xy;
const float2 UV_baseColorMap = g_xMat_uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
float4 color = xBaseColorMap.Sample(sampler_objectshader, UV_baseColorMap);
color.rgb = DEGAMMA(color.rgb);
float4 color;
[branch]
if (g_xMat_uvset_baseColorMap >= 0)
{
const float2 UV_baseColorMap = g_xMat_uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
color = xBaseColorMap.Sample(sampler_objectshader, UV_baseColorMap);
color.rgb = DEGAMMA(color.rgb);
}
else
{
color = 1;
}
color *= input.color;
ALPHATEST(color.a);
float opacity = color.a;
@@ -22,15 +31,19 @@ float4 main(VertextoPixel input) : SV_TARGET
color.rgb *= 1 - opacity;
// Use the alpha channel for refraction caustics effect:
float3 bumpColor;
[branch]
if (g_xMat_uvset_normalMap >= 0)
{
float3 bumpColor;
const float2 UV_normalMap = g_xMat_uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw;
bumpColor = float3(2.0f * xNormalMap.Sample(sampler_objectshader, UV_normalMap - g_xMat_texMulAdd.ww).rg - 1.0f, 1);
bumpColor.rg *= g_xMat_refractionIndex;
bumpColor.rg *= g_xMat_normalMapStrength;
bumpColor = normalize(max(bumpColor, float3(0, 0, 0.0001f)));
color.a = 1 - saturate(dot(bumpColor, float3(0, 0, 1)));
const float2 UV_normalMap = g_xMat_uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw;
bumpColor = float3(2.0f * xNormalMap.Sample(sampler_objectshader, UV_normalMap - g_xMat_texMulAdd.ww).rg - 1.0f, 1);
bumpColor.rg *= g_xMat_refractionIndex;
bumpColor.rg *= g_xMat_normalMapStrength;
bumpColor = normalize(max(bumpColor, float3(0, 0, 0.0001f)));
color.a = 1 - saturate(dot(bumpColor, float3(0, 0, 1)));
}
return color;
}
+27 -14
View File
@@ -12,9 +12,18 @@ float4 main(VertextoPixel input) : SV_TARGET
{
float2 pixel = input.pos.xy;
const float2 UV_baseColorMap = g_xMat_uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
float4 color = xBaseColorMap.Sample(sampler_objectshader, UV_baseColorMap);
color.rgb = DEGAMMA(color.rgb);
float4 color;
[branch]
if (g_xMat_uvset_baseColorMap >= 0)
{
const float2 UV_baseColorMap = g_xMat_uvset_baseColorMap == 0 ? input.uvsets.xy : input.uvsets.zw;
color = xBaseColorMap.Sample(sampler_objectshader, UV_baseColorMap);
color.rgb = DEGAMMA(color.rgb);
}
else
{
color = 1;
}
color *= input.color;
ALPHATEST(color.a);
float opacity = color.a;
@@ -25,19 +34,23 @@ float4 main(VertextoPixel input) : SV_TARGET
color.rgb = 1;
// Use the alpha channel for refraction caustics effect:
float3 bumpColor;
[branch]
if (g_xMat_uvset_normalMap >= 0)
{
float3 bumpColor;
float2 bumpColor0 = 0;
float2 bumpColor1 = 0;
float2 bumpColor2 = 0;
const float2 UV_normalMap = g_xMat_uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw;
bumpColor0 = 2.0f * xNormalMap.Sample(sampler_objectshader, UV_normalMap - g_xMat_texMulAdd.ww).rg - 1.0f;
bumpColor1 = 2.0f * xNormalMap.Sample(sampler_objectshader, UV_normalMap + g_xMat_texMulAdd.zw).rg - 1.0f;
bumpColor = float3(bumpColor0 + bumpColor1 + bumpColor2, 1) * g_xMat_refractionIndex;
bumpColor.rg *= g_xMat_normalMapStrength;
bumpColor = normalize(max(bumpColor, float3(0, 0, 0.0001f)));
float2 bumpColor0 = 0;
float2 bumpColor1 = 0;
float2 bumpColor2 = 0;
const float2 UV_normalMap = g_xMat_uvset_normalMap == 0 ? input.uvsets.xy : input.uvsets.zw;
bumpColor0 = 2.0f * xNormalMap.Sample(sampler_objectshader, UV_normalMap - g_xMat_texMulAdd.ww).rg - 1.0f;
bumpColor1 = 2.0f * xNormalMap.Sample(sampler_objectshader, UV_normalMap + g_xMat_texMulAdd.zw).rg - 1.0f;
bumpColor = float3(bumpColor0 + bumpColor1 + bumpColor2, 1) * g_xMat_refractionIndex;
bumpColor.rg *= g_xMat_normalMapStrength;
bumpColor = normalize(max(bumpColor, float3(0, 0, 0.0001f)));
color.a = 1 - saturate(abs(dot(bumpColor, float3(0, 0, 1))));
color.a = 1 - saturate(abs(dot(bumpColor, float3(0, 0, 1))));
}
return color;
}
+6 -6
View File
@@ -154,12 +154,12 @@ void wiGPUBVH::UpdateGlobalMaterialResources(const Scene& scene, GRAPHICSTHREAD
global_material.parallaxOcclusionMapping = material.parallaxOcclusionMapping;
global_material.displacementMapping = material.displacementMapping;
global_material.useVertexColors = material.IsUsingVertexColors() ? 1 : 0;
global_material.uvset_baseColorMap = material.uvset_baseColorMap;
global_material.uvset_surfaceMap = material.uvset_surfaceMap;
global_material.uvset_normalMap = material.uvset_normalMap;
global_material.uvset_displacementMap = material.uvset_displacementMap;
global_material.uvset_emissiveMap = material.uvset_emissiveMap;
global_material.uvset_occlusionMap = material.uvset_occlusionMap;
global_material.uvset_baseColorMap = material.baseColorMap == nullptr ? -1 : material.uvset_baseColorMap;
global_material.uvset_surfaceMap = material.surfaceMap == nullptr ? -1 : material.uvset_surfaceMap;
global_material.uvset_normalMap = material.normalMap == nullptr ? -1 : material.uvset_normalMap;
global_material.uvset_displacementMap = material.displacementMap == nullptr ? -1 : material.uvset_displacementMap;
global_material.uvset_emissiveMap = material.emissiveMap == nullptr ? -1 : material.uvset_emissiveMap;
global_material.uvset_occlusionMap = material.occlusionMap == nullptr ? -1 : material.uvset_occlusionMap;
global_material.specularGlossinessWorkflow = material.IsUsingSpecularGlossinessWorkflow() ? 1 : 0;
global_material.occlusion_primary = material.IsOcclusionEnabled_Primary() ? 1 : 0;
global_material.occlusion_secondary = material.IsOcclusionEnabled_Secondary() ? 1 : 0;
+6 -6
View File
@@ -3842,12 +3842,12 @@ void UpdateRenderData(GRAPHICSTHREAD threadID)
materialGPUData.g_xMat_parallaxOcclusionMapping = material.parallaxOcclusionMapping;
materialGPUData.g_xMat_displacementMapping = material.displacementMapping;
materialGPUData.g_xMat_useVertexColors = material.IsUsingVertexColors() ? 1 : 0;
materialGPUData.g_xMat_uvset_baseColorMap = material.uvset_baseColorMap;
materialGPUData.g_xMat_uvset_surfaceMap = material.uvset_surfaceMap;
materialGPUData.g_xMat_uvset_normalMap = material.uvset_normalMap;
materialGPUData.g_xMat_uvset_displacementMap = material.uvset_displacementMap;
materialGPUData.g_xMat_uvset_emissiveMap = material.uvset_emissiveMap;
materialGPUData.g_xMat_uvset_occlusionMap = material.uvset_occlusionMap;
materialGPUData.g_xMat_uvset_baseColorMap = material.baseColorMap == nullptr ? -1 : material.uvset_baseColorMap;
materialGPUData.g_xMat_uvset_surfaceMap = material.surfaceMap == nullptr ? -1 : material.uvset_surfaceMap;
materialGPUData.g_xMat_uvset_normalMap = material.normalMap == nullptr ? -1 : material.uvset_normalMap;
materialGPUData.g_xMat_uvset_displacementMap = material.displacementMap == nullptr ? -1 : material.uvset_displacementMap;
materialGPUData.g_xMat_uvset_emissiveMap = material.emissiveMap == nullptr ? -1 : material.uvset_emissiveMap;
materialGPUData.g_xMat_uvset_occlusionMap = material.occlusionMap == nullptr ? -1 : material.uvset_occlusionMap;
materialGPUData.g_xMat_specularGlossinessWorkflow = material.IsUsingSpecularGlossinessWorkflow() ? 1 : 0;
materialGPUData.g_xMat_occlusion_primary = material.IsOcclusionEnabled_Primary() ? 1 : 0;
materialGPUData.g_xMat_occlusion_secondary = material.IsOcclusionEnabled_Secondary() ? 1 : 0;
+1 -1
View File
@@ -9,7 +9,7 @@ namespace wiVersion
// minor features, major updates
const int minor = 26;
// minor bug fixes, alterations, refactors, updates
const int revision = 24;
const int revision = 25;
long GetVersion()