Skip to content

Commit

Permalink
feature: backface shadow alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlum committed Oct 1, 2023
1 parent d68d3a1 commit 0ed1e46
Showing 1 changed file with 58 additions and 57 deletions.
115 changes: 58 additions & 57 deletions package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

# if defined(SCREEN_SPACE_SHADOWS)
float dirLightSShadow = PrepassScreenSpaceShadows(input.WorldPosition.xyz);
dirLightSShadow = lerp(dirLightSShadow, 1.0, !frontFace * 0.2);
dirLightColor *= dirLightSShadow;
# endif // SCREEN_SPACE_SHADOWS

Expand Down Expand Up @@ -1529,17 +1530,17 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
float dirLightAngle = dot(modelNormal.xyz, DirLightDirection.xyz);
float3 dirDiffuseColor = dirLightColor * saturate(dirLightAngle.xxx);

# if defined(SOFT_LIGHTING)
# if defined(SOFT_LIGHTING)
lightsDiffuseColor += nsDirLightColor.xyz * GetSoftLightMultiplier(dirLightAngle) * rimSoftLightColor.xyz;
# endif
# endif

# if defined(RIM_LIGHTING)
# if defined(RIM_LIGHTING)
lightsDiffuseColor += nsDirLightColor.xyz * GetRimLightMultiplier(DirLightDirection, viewDirection, modelNormal.xyz) * rimSoftLightColor.xyz;
# endif
# endif

# if defined(BACK_LIGHTING)
# if defined(BACK_LIGHTING)
lightsDiffuseColor += nsDirLightColor.xyz * (saturate(-dirLightAngle) * backLightColor.xyz);
# endif
# endif

if (useSnowSpecular && useSnowDecalSpecular) {
# if defined(SNOW)
Expand Down Expand Up @@ -1602,9 +1603,9 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
float3 normalizedLightDirectionVS = WorldToView(normalizedLightDirectionWS, true, eyeIndex);
# if defined(SKINNED) || !defined(MODELSPACENORMALS)
float shadowIntensityFactor = saturate(dot(vertexNormal, normalizedLightDirection.xyz) * PI);
lightColor *= lerp(1.0, ContactShadows(viewPosition, screenUV, screenNoise, normalizedLightDirectionVS, 1.0, 0.0, eyeIndex), shadowIntensityFactor);
lightColor *= lerp(lerp(1.0, ContactShadows(viewPosition, screenUV, screenNoise, normalizedLightDirectionVS, 1.0, 0.0, eyeIndex), shadowIntensityFactor), 1.0, !frontFace * 0.2);
# else
lightColor *= ContactShadows(viewPosition, screenUV, screenNoise, normalizedLightDirectionVS, 1.0, 0.0, eyeIndex);
lightColor *= lerp(ContactShadows(viewPosition, screenUV, screenNoise, normalizedLightDirectionVS, 1.0, 0.0, eyeIndex), 1.0, !frontFace * 0.2);
# endif
}
# endif
Expand Down Expand Up @@ -1634,17 +1635,17 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
float lightAngle = dot(modelNormal.xyz, normalizedLightDirection.xyz);
float3 lightDiffuseColor = lightColor * saturate(lightAngle.xxx);

# if defined(SOFT_LIGHTING)
# if defined(SOFT_LIGHTING)
lightDiffuseColor += nsLightColor * GetSoftLightMultiplier(dot(modelNormal.xyz, lightDirection.xyz)) * rimSoftLightColor.xyz;
# endif // SOFT_LIGHTING
# endif // SOFT_LIGHTING

# if defined(RIM_LIGHTING)
# if defined(RIM_LIGHTING)
lightDiffuseColor += nsLightColor * GetRimLightMultiplier(normalizedLightDirection, viewDirection, modelNormal.xyz) * rimSoftLightColor.xyz;
# endif // RIM_LIGHTING
# endif // RIM_LIGHTING

# if defined(BACK_LIGHTING)
# if defined(BACK_LIGHTING)
lightDiffuseColor += (saturate(-lightAngle) * backLightColor.xyz) * nsLightColor;
# endif // BACK_LIGHTING
# endif // BACK_LIGHTING

# if defined(SPECULAR) || (defined(SPARKLE) && !defined(SNOW))
lightsSpecularColor += GetLightSpecularInput(input, normalizedLightDirection, viewDirection, modelNormal.xyz, lightColor, shininess, uv) * intensityMultiplier.xxx;
Expand Down Expand Up @@ -1712,9 +1713,9 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
} else if (perPassLLF[0].EnableContactShadows) {
# if defined(SKINNED) || !defined(MODELSPACENORMALS)
float shadowIntensityFactor = saturate(dot(worldSpaceVertexNormal, normalizedLightDirection.xyz) * PI);
lightColor *= lerp(1.0, ContactShadows(viewPosition, screenUV, screenNoise, normalizedLightDirectionVS, shadowQualityScale, 0.0, eyeIndex), shadowIntensityFactor);
lightColor *= lerp(lerp(1.0, ContactShadows(viewPosition, screenUV, screenNoise, normalizedLightDirectionVS, shadowQualityScale, 0.0, eyeIndex), shadowIntensityFactor), 1.0, !frontFace * 0.2);
# else
lightColor *= ContactShadows(viewPosition, screenUV, screenNoise, normalizedLightDirectionVS, shadowQualityScale, 0.0, eyeIndex);
lightColor *= lerp(ContactShadows(viewPosition, screenUV, screenNoise, normalizedLightDirectionVS, shadowQualityScale, 0.0, eyeIndex), 1.0, !frontFace * 0.2);
# endif
}
}
Expand All @@ -1739,17 +1740,17 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
float lightAngle = dot(worldSpaceNormal.xyz, normalizedLightDirection.xyz);
float3 lightDiffuseColor = lightColor * saturate(lightAngle.xxx);

# if defined(SOFT_LIGHTING)
# if defined(SOFT_LIGHTING)
lightDiffuseColor += nsLightColor * GetSoftLightMultiplier(dot(worldSpaceNormal.xyz, lightDirection.xyz)) * rimSoftLightColor.xyz;
# endif
# endif

# if defined(RIM_LIGHTING)
# if defined(RIM_LIGHTING)
lightDiffuseColor += nsLightColor * GetRimLightMultiplier(normalizedLightDirection, worldSpaceViewDirection, worldSpaceNormal.xyz) * rimSoftLightColor.xyz;
# endif
# endif

# if defined(BACK_LIGHTING)
# if defined(BACK_LIGHTING)
lightDiffuseColor += (saturate(-lightAngle) * backLightColor.xyz) * nsLightColor;
# endif
# endif

# if defined(SPECULAR) || (defined(SPARKLE) && !defined(SNOW))
lightsSpecularColor += GetLightSpecularInput(input, normalizedLightDirection, worldSpaceViewDirection, worldSpaceNormal.xyz, lightColor, shininess, uv) * intensityMultiplier.xxx;
Expand Down Expand Up @@ -1808,7 +1809,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
float3 vertexColor = (input.Color.yyy * (TintColor.xyz - 1.0.xxx) + 1.0.xxx) * color.xyz;
# else
float3 vertexColor = input.Color.xyz * color.xyz;
# endif // defined (HAIR)
# endif // defined (HAIR)

# if defined(MULTI_LAYER_PARALLAX)
float layerValue = MultiLayerParallaxData.x * TexLayerSampler.Sample(SampLayerSampler, uv).w;
Expand Down Expand Up @@ -1872,52 +1873,52 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
psout.Albedo.w = 0;
# else
float alpha = baseColor.w;

if (shaderDescriptors[0].PixelShaderDescriptor & _AdditionalAlphaMask) {
alpha *= MaterialData.z;
} else {
uint2 alphaMask = input.Position.xy;
alphaMask.x = ((alphaMask.x << 2) & 12);
alphaMask.x = (alphaMask.y & 3) | (alphaMask.x & ~3);
const float maskValues[16] = {
0.003922,
0.533333,
0.133333,
0.666667,
0.800000,
0.266667,
0.933333,
0.400000,
0.200000,
0.733333,
0.066667,
0.600000,
0.996078,
0.466667,
0.866667,
0.333333,
};

float testTmp = 0;
if (MaterialData.z - maskValues[alphaMask.x] < 0)
discard;
}
if (shaderDescriptors[0].PixelShaderDescriptor & _AdditionalAlphaMask){
alpha *= MaterialData.z;
} else {
uint2 alphaMask = input.Position.xy;
alphaMask.x = ((alphaMask.x << 2) & 12);
alphaMask.x = (alphaMask.y & 3) | (alphaMask.x & ~3);
const float maskValues[16] = {
0.003922,
0.533333,
0.133333,
0.666667,
0.800000,
0.266667,
0.933333,
0.400000,
0.200000,
0.733333,
0.066667,
0.600000,
0.996078,
0.466667,
0.866667,
0.333333,
};

float testTmp = 0;
if (MaterialData.z - maskValues[alphaMask.x] < 0)
discard;
}
# if !(defined(TREE_ANIM) || defined(LODOBJECTSHD) || defined(LODOBJECTS))
alpha *= input.Color.w;
# endif // !(defined(TREE_ANIM) || defined(LODOBJECTSHD) || defined(LODOBJECTS))
# if defined(DO_ALPHA_TEST)
# if defined(HAIR)
if (shaderDescriptors[0].PixelShaderDescriptor & _DepthWriteDecals) {
if (shaderDescriptors[0].PixelShaderDescriptor & _DepthWriteDecals){
if (alpha - 0.0156862754 < 0)
discard;
alpha = saturate(1.05 * alpha);
}
# endif // defined(HAIR)
# endif // defined(HAIR)
if (alpha - AlphaThreshold < 0)
discard;
# endif // defined(DO_ALPHA_TEST)
# endif // defined(DO_ALPHA_TEST)
psout.Albedo.w = alpha;
# endif // defined(LANDSCAPE) && !defined(LOD_LAND_BLEND)
# endif // defined(LANDSCAPE) && !defined(LOD_LAND_BLEND)

# if defined(LIGHT_LIMIT_FIX)
if (perPassLLF[0].EnableLightsVisualisation) {
Expand Down

0 comments on commit 0ed1e46

Please sign in to comment.