Skip to content

Commit

Permalink
[URP][2023.2] Backport UUM-47142 Screen Space Decal Ambient Lighting
Browse files Browse the repository at this point in the history
- Fixes the following issue: [UUM-47142](https://jira.unity3d.com/browse/UUM-47142) Frag() in ShaderPassDecal.hlsl when using deferred rendering pipeline can potentially use an uninitialized world space normal when calculating inputData.bakedGI. So, as is done just above for screen space the normal is initialized ahead of time so GI can be calculated correctly and passed on to the final output data.
  • Loading branch information
skip-petty authored and Evergreen committed Nov 15, 2023
1 parent 3d760ab commit b2ca1bd
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,12 @@ void Frag(PackedVaryings packedInput,
outColor = color;
#elif defined(DECAL_GBUFFER)

// Need to reconstruct normal here for inputData.bakedGI, but also save off surfaceData.normalWS for correct GBuffer blending
half3 normalToPack = surfaceData.normalWS.xyz;
#ifdef DECAL_RECONSTRUCT_NORMAL
surfaceData.normalWS.xyz = normalize(lerp(normalWS.xyz, surfaceData.normalWS.xyz, surfaceData.normalWS.w));
#endif

InputData inputData;
InitializeInputData(input, positionWS, surfaceData.normalWS.xyz, viewDirectionWS, inputData);

Expand All @@ -339,21 +345,15 @@ void Frag(PackedVaryings packedInput,

// Skip GI if there is no abledo
#ifdef _MATERIAL_AFFECTS_ALBEDO

// GI needs blended normal
#ifdef DECAL_RECONSTRUCT_NORMAL
half3 normalGI = normalize(lerp(normalWS.xyz, surfaceData.normalWS.xyz, surfaceData.normalWS.w));
#endif

Light mainLight = GetMainLight(inputData.shadowCoord, inputData.positionWS, inputData.shadowMask);
MixRealtimeAndBakedGI(mainLight, normalGI, inputData.bakedGI, inputData.shadowMask);
half3 color = GlobalIllumination(brdfData, inputData.bakedGI, surface.occlusion, normalGI, inputData.viewDirectionWS);
MixRealtimeAndBakedGI(mainLight, surfaceData.normalWS.xyz, inputData.bakedGI, inputData.shadowMask);
half3 color = GlobalIllumination(brdfData, inputData.bakedGI, surface.occlusion, surfaceData.normalWS.xyz, inputData.viewDirectionWS);
#else
half3 color = 0;
#endif

// We can not use usual GBuffer functions (etc. BRDFDataToGbuffer) as we use alpha for blending
half3 packedNormalWS = PackNormal(surfaceData.normalWS.xyz);
half3 packedNormalWS = PackNormal(normalToPack);
fragmentOutput.GBuffer0 = half4(surfaceData.baseColor.rgb, surfaceData.baseColor.a);
fragmentOutput.GBuffer1 = 0;
fragmentOutput.GBuffer2 = half4(packedNormalWS, surfaceData.normalWS.a);
Expand Down

0 comments on commit b2ca1bd

Please sign in to comment.