Skip to content

Commit b2ca1bd

Browse files
skip-pettyEvergreen
authored and
Evergreen
committed
[URP][2023.2] Backport UUM-47142 Screen Space Decal Ambient Lighting
- 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.
1 parent 3d760ab commit b2ca1bd

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPassDecal.hlsl

+9-9
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,12 @@ void Frag(PackedVaryings packedInput,
328328
outColor = color;
329329
#elif defined(DECAL_GBUFFER)
330330

331+
// Need to reconstruct normal here for inputData.bakedGI, but also save off surfaceData.normalWS for correct GBuffer blending
332+
half3 normalToPack = surfaceData.normalWS.xyz;
333+
#ifdef DECAL_RECONSTRUCT_NORMAL
334+
surfaceData.normalWS.xyz = normalize(lerp(normalWS.xyz, surfaceData.normalWS.xyz, surfaceData.normalWS.w));
335+
#endif
336+
331337
InputData inputData;
332338
InitializeInputData(input, positionWS, surfaceData.normalWS.xyz, viewDirectionWS, inputData);
333339

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

340346
// Skip GI if there is no abledo
341347
#ifdef _MATERIAL_AFFECTS_ALBEDO
342-
343-
// GI needs blended normal
344-
#ifdef DECAL_RECONSTRUCT_NORMAL
345-
half3 normalGI = normalize(lerp(normalWS.xyz, surfaceData.normalWS.xyz, surfaceData.normalWS.w));
346-
#endif
347-
348348
Light mainLight = GetMainLight(inputData.shadowCoord, inputData.positionWS, inputData.shadowMask);
349-
MixRealtimeAndBakedGI(mainLight, normalGI, inputData.bakedGI, inputData.shadowMask);
350-
half3 color = GlobalIllumination(brdfData, inputData.bakedGI, surface.occlusion, normalGI, inputData.viewDirectionWS);
349+
MixRealtimeAndBakedGI(mainLight, surfaceData.normalWS.xyz, inputData.bakedGI, inputData.shadowMask);
350+
half3 color = GlobalIllumination(brdfData, inputData.bakedGI, surface.occlusion, surfaceData.normalWS.xyz, inputData.viewDirectionWS);
351351
#else
352352
half3 color = 0;
353353
#endif
354354

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

0 commit comments

Comments
 (0)