Adjusting alpha on grazing angles so it doesn't affect the diffuse response. (#1599)

This commit is contained in:
Ken Pruiksma
2021-06-29 12:45:10 -05:00
committed by GitHub
parent 2d27c13b31
commit 1ee4f7b447
@@ -251,17 +251,21 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float
// Finalize Lighting
lightingData.FinalizeLighting();
if (o_opacity_mode == OpacityMode::Blended || o_opacity_mode == OpacityMode::TintedTransparent)
{
float fresnelAlpha = FresnelSchlickWithRoughness(lightingData.NdotV, alpha, surface.roughnessLinear).x; // Increase opacity at grazing angles.
alpha = lerp(fresnelAlpha, alpha, MaterialSrg::m_opacityAffectsSpecularFactor);
}
PbrLightingOutput lightingOutput = GetPbrLightingOutput(surface, lightingData, alpha);
// ------- Opacity -------
if (o_opacity_mode == OpacityMode::Blended || o_opacity_mode == OpacityMode::TintedTransparent)
{
// Increase opacity at grazing angles for surfaces with a low m_opacityAffectsSpecularFactor.
// For m_opacityAffectsSpecularFactor values close to 0, that indicates a transparent surface
// like glass, so it becomes less transparent at grazing angles. For m_opacityAffectsSpecularFactor
// values close to 1.0, that indicates the absence of a surface entirely, so this effect should
// not apply.
float fresnelAlpha = FresnelSchlickWithRoughness(lightingData.NdotV, alpha, surface.roughnessLinear).x;
alpha = lerp(fresnelAlpha, alpha, MaterialSrg::m_opacityAffectsSpecularFactor);
}
if (o_opacity_mode == OpacityMode::Blended)
{
// [GFX_TODO ATOM-13187] PbrLighting shouldn't be writing directly to render targets. It's confusing when
@@ -277,6 +281,8 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float
float3 specular = lightingOutput.m_specularColor.rgb;
specular = lerp(specular, specular * lightingOutput.m_diffuseColor.w, MaterialSrg::m_opacityAffectsSpecularFactor);
lightingOutput.m_diffuseColor.rgb += specular;
lightingOutput.m_diffuseColor.w = alpha;
}
else if (o_opacity_mode == OpacityMode::TintedTransparent)
{
@@ -299,7 +305,7 @@ PbrLightingOutput ForwardPassPS_Common(VSOutput IN, bool isFrontFace, out float
specular = lerp(specular, specular * lightingOutput.m_diffuseColor.w, MaterialSrg::m_opacityAffectsSpecularFactor);
lightingOutput.m_diffuseColor.rgb += specular;
lightingOutput.m_specularColor.rgb = baseColor * (1.0 - lightingOutput.m_diffuseColor.w);
lightingOutput.m_specularColor.rgb = baseColor * (1.0 - alpha);
}
else
{