Skip to content

Commit 8d07517

Browse files
svc-reach-platform-supportEvergreen
authored andcommitted
[Port] [6000.4] URP: Fix screen-space decals in Deferred
1 parent 53d665a commit 8d07517

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

Packages/com.unity.render-pipelines.universal/Editor/Decal/DecalPass.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ Pass
7575
#endif
7676
#if _RENDER_PASS_ENABLED
7777
#define GBUFFER3 0
78+
FRAMEBUFFER_INPUT_X_FLOAT(GBUFFER3);
7879
#define GBUFFER4 1
79-
FRAMEBUFFER_INPUT_X_HALF(GBUFFER3);
8080
FRAMEBUFFER_INPUT_X_UINT(GBUFFER4);
8181
#endif
8282

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,21 @@ void Frag(PackedVaryings packedInput,
242242
#endif
243243

244244
#if defined(DECAL_RECONSTRUCT_NORMAL)
245-
#if defined(_DECAL_NORMAL_BLEND_HIGH)
245+
#if defined(_RENDER_PASS_ENABLED)
246+
half3 normalWS = half3(ReconstructNormalDerivative(input.positionCS.xy, LOAD_FRAMEBUFFER_X_INPUT(GBUFFER3, positionCS.xy).x));
247+
#elif defined(_DECAL_NORMAL_BLEND_HIGH)
246248
half3 normalWS = half3(ReconstructNormalTap9(positionCS.xy));
247249
#elif defined(_DECAL_NORMAL_BLEND_MEDIUM)
248250
half3 normalWS = half3(ReconstructNormalTap5(positionCS.xy));
249251
#else
250252
half3 normalWS = half3(ReconstructNormalDerivative(input.positionCS.xy));
251253
#endif
252254
#elif defined(DECAL_LOAD_NORMAL)
253-
half3 normalWS = half3(LoadSceneNormals(positionCS.xy));
255+
#if defined(_RENDER_PASS_ENABLED)
256+
half3 normalWS = normalize(LOAD_FRAMEBUFFER_X_INPUT(GBUFFER2, positionCS.xy).rgb);
257+
#else
258+
half3 normalWS = normalize(LoadSceneNormals(positionCS.xy).rgb);
259+
#endif
254260
#endif
255261

256262
float2 positionSS = FoveatedRemapNonUniformToLinearCS(input.positionCS.xy) * _ScreenSize.zw;

Packages/com.unity.render-pipelines.universal/Editor/VFXGraph/Shaders/Templates/URPDecal/PassGBuffer.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ Pass
4444

4545
#if _RENDER_PASS_ENABLED
4646
#define GBUFFER3 0
47+
FRAMEBUFFER_INPUT_X_FLOAT(GBUFFER3);
4748
#define GBUFFER4 1
48-
FRAMEBUFFER_INPUT_X_HALF(GBUFFER3);
4949
FRAMEBUFFER_INPUT_X_UINT(GBUFFER4);
5050
#endif
5151

Packages/com.unity.render-pipelines.universal/ShaderLibrary/NormalReconstruction.hlsl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ float GetRawDepth(float2 uv)
2020
// https://github.com/keijiro/DepthInverseProjection
2121
// constructs view space ray at the far clip plane from the screen uv
2222
// then multiplies that ray by the linear 01 depth
23+
float3 ViewSpacePosAtScreenUV(float2 uv, float deviceDepth)
24+
{
25+
float3 viewSpaceRay = mul(_NormalReconstructionMatrix[unity_eyeIndex], float4(uv * 2.0 - 1.0, 1.0, 1.0) * _ProjectionParams.z).xyz;
26+
return viewSpaceRay * Linear01Depth(deviceDepth, _ZBufferParams);
27+
}
28+
29+
float3 ViewSpacePosAtPixelPosition(float2 positionSS, float deviceDepth)
30+
{
31+
float2 uv = positionSS * _ScreenSize.zw;
32+
return ViewSpacePosAtScreenUV(uv, deviceDepth);
33+
}
34+
35+
half3 ReconstructNormalDerivative(float2 positionSS, float deviceDepth)
36+
{
37+
float3 viewSpacePos = ViewSpacePosAtPixelPosition(positionSS, deviceDepth);
38+
float3 hDeriv = ddy(viewSpacePos);
39+
float3 vDeriv = ddx(viewSpacePos);
40+
return half3(SafeNormalize(cross(hDeriv, vDeriv)));
41+
}
42+
2343
float3 ViewSpacePosAtScreenUV(float2 uv)
2444
{
2545
float3 viewSpaceRay = mul(_NormalReconstructionMatrix[unity_eyeIndex], float4(uv * 2.0 - 1.0, 1.0, 1.0) * _ProjectionParams.z).xyz;

0 commit comments

Comments
 (0)