Skip to content

Commit

Permalink
fix lightmap specular incorrectly using specular occlusion
Browse files Browse the repository at this point in the history
  • Loading branch information
z3y committed Jan 17, 2025
1 parent b759265 commit 8e7725f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Editor/Targets/Lit/FragmentForward.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ half4 frag(Varyings varyings) : SV_Target

GIOutput giOutput = GIOutput::New();

half3 lmSpecular = 0;

#if defined(LIGHTMAP_ON)
float2 lightmapUV = fragData.lightmapUV;
#if defined(_BICUBIC_LIGHTMAP) && !defined(QUALITY_LOW)
Expand Down Expand Up @@ -127,9 +129,9 @@ half4 frag(Varyings varyings) : SV_Target
#ifdef _ANISOTROPY
// half at = max(roughnessLm * (1.0 + surf.Anisotropy), 0.001);
// half ab = max(roughnessLm * (1.0 - surf.Anisotropy), 0.001);
// giOutput.indirectSpecular += max(Filament::D_GGX_Anisotropic(nh, halfDir, sd.tangentWS, sd.bitangentWS, at, ab) * sh, 0.0);
// lmSpecular += max(Filament::D_GGX_Anisotropic(nh, halfDir, sd.tangentWS, sd.bitangentWS, at, ab) * sh, 0.0);
#else
giOutput.indirectSpecular += max(spec * sh, 0.0);
lmSpecular += max(spec * sh, 0.0);
#endif
}
#endif
Expand Down Expand Up @@ -252,6 +254,7 @@ half4 frag(Varyings varyings) : SV_Target
half3 fr;
fr = giInput.energyCompensation * giInput.brdf;
giOutput.indirectSpecular *= fr;
lmSpecular *= fr;

#if defined(QUALITY_LOW)
giInput.specularAO = surf.Occlusion;
Expand All @@ -263,6 +266,7 @@ half4 frag(Varyings varyings) : SV_Target

half indirectOcclusionIntensity = _SpecularOcclusion;
giOutput.indirectSpecular *= giInput.specularAO * saturate(lerp(1.0, saturate(sqrt(dot(giOutput.indirectOcclusion + giOutput.directDiffuse, 1.0))), indirectOcclusionIntensity));
giOutput.indirectSpecular += lmSpecular;
giOutput.directSpecular *= giInput.specularAO;

half4 color = half4(surf.Albedo * (1.0 - surf.Metallic) * (giOutput.indirectDiffuse * surf.Occlusion + giOutput.directDiffuse), surf.Alpha);
Expand Down

0 comments on commit 8e7725f

Please sign in to comment.