From f16545ce1cd0a9b721c3f0dfbfd954ef69d680eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elvar=20=C3=96rn=20Unn=C3=BE=C3=B3rsson?= Date: Tue, 9 Jan 2024 20:46:02 +0000 Subject: [PATCH] [2023.2][URP] Various Shader fixes (UUM-59974) Backport of #42134 --- .../ShaderGraph/Includes/ShaderPassDecal.hlsl | 4 +- .../Targets/UniversalDecalSubTarget.cs | 12 --- .../Targets/UniversalLitSubTarget.cs | 9 +-- .../Targets/UniversalSixWaySubTarget.cs | 3 - .../ShaderGraph/Targets/UniversalTarget.cs | 73 ++++++------------- .../Targets/UniversalUnlitSubTarget.cs | 1 - .../Editor/VFXGraph/Shaders/VFXDecal.template | 2 +- .../ShaderLibrary/Shadows.hlsl | 2 +- .../Shaders/PostProcessing/Bloom.shader | 5 +- .../MotionVectorTestVisualization.shader | 2 +- 10 files changed, 35 insertions(+), 78 deletions(-) diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPassDecal.hlsl b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPassDecal.hlsl index 957739f405b..36259a3e395 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPassDecal.hlsl +++ b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPassDecal.hlsl @@ -218,7 +218,7 @@ void Frag(PackedVaryings packedInput, #if defined(DECAL_PROJECTOR) #if UNITY_REVERSED_Z #if _RENDER_PASS_ENABLED - float depth = LOAD_FRAMEBUFFER_INPUT(GBUFFER3, positionCS.xy); + float depth = LOAD_FRAMEBUFFER_INPUT(GBUFFER3, positionCS.xy).x; #else float depth = LoadSceneDepth(positionCS.xy); #endif @@ -353,6 +353,7 @@ void Frag(PackedVaryings packedInput, #endif // We can not use usual GBuffer functions (etc. BRDFDataToGbuffer) as we use alpha for blending + #pragma warning (disable : 3578) // The output value isn't completely initialized. half3 packedNormalWS = PackNormal(normalToPack); fragmentOutput.GBuffer0 = half4(surfaceData.baseColor.rgb, surfaceData.baseColor.a); fragmentOutput.GBuffer1 = 0; @@ -361,6 +362,7 @@ void Frag(PackedVaryings packedInput, #if OUTPUT_SHADOWMASK fragmentOutput.GBuffer4 = inputData.shadowMask; // will have unity_ProbesOcclusion value if subtractive lighting is used (baked) #endif + #pragma warning (default : 3578) // Restore output value isn't completely initialized. #elif defined(DECAL_FORWARD_EMISSIVE) // Emissive need to be pre-exposed diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalDecalSubTarget.cs b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalDecalSubTarget.cs index 45ab7c5e5b1..117133b1cd1 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalDecalSubTarget.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalDecalSubTarget.cs @@ -991,9 +991,6 @@ static class Descriptors { CoreKeywordDescriptors.AdditionalLights }, { CoreKeywordDescriptors.AdditionalLightShadows }, { CoreKeywordDescriptors.ShadowsSoft }, - { CoreKeywordDescriptors.ShadowsSoftLow }, - { CoreKeywordDescriptors.ShadowsSoftMedium }, - { CoreKeywordDescriptors.ShadowsSoftHigh }, { CoreKeywordDescriptors.LightmapShadowMixing }, { CoreKeywordDescriptors.ShadowsShadowmask }, { CoreKeywordDescriptors.ForwardPlus }, @@ -1015,9 +1012,6 @@ static class Descriptors { CoreKeywordDescriptors.AdditionalLights }, { CoreKeywordDescriptors.AdditionalLightShadows }, { CoreKeywordDescriptors.ShadowsSoft }, - { CoreKeywordDescriptors.ShadowsSoftLow }, - { CoreKeywordDescriptors.ShadowsSoftMedium }, - { CoreKeywordDescriptors.ShadowsSoftHigh }, { CoreKeywordDescriptors.ForwardPlus }, { CoreKeywordDescriptors.DebugDisplay }, { Descriptors.DecalsNormalBlend }, @@ -1031,9 +1025,6 @@ static class Descriptors { CoreKeywordDescriptors.DirectionalLightmapCombined }, { CoreKeywordDescriptors.MainLightShadows }, { CoreKeywordDescriptors.ShadowsSoft }, - { CoreKeywordDescriptors.ShadowsSoftLow }, - { CoreKeywordDescriptors.ShadowsSoftMedium }, - { CoreKeywordDescriptors.ShadowsSoftHigh }, { CoreKeywordDescriptors.LightmapShadowMixing }, { CoreKeywordDescriptors.MixedLightingSubtractive }, { Descriptors.DecalsNormalBlend }, @@ -1047,9 +1038,6 @@ static class Descriptors { { CoreKeywordDescriptors.MainLightShadows }, { CoreKeywordDescriptors.ShadowsSoft }, - { CoreKeywordDescriptors.ShadowsSoftLow }, - { CoreKeywordDescriptors.ShadowsSoftMedium }, - { CoreKeywordDescriptors.ShadowsSoftHigh }, { Descriptors.DecalsNormalBlend }, { Descriptors.DecalLayers }, { CoreKeywordDescriptors.GBufferNormalsOct }, diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs index 81bc3baca62..02aa9d7d37c 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalLitSubTarget.cs @@ -839,9 +839,6 @@ static class LitKeywords { CoreKeywordDescriptors.ReflectionProbeBlending }, { CoreKeywordDescriptors.ReflectionProbeBoxProjection }, { CoreKeywordDescriptors.ShadowsSoft }, - { CoreKeywordDescriptors.ShadowsSoftLow }, - { CoreKeywordDescriptors.ShadowsSoftMedium }, - { CoreKeywordDescriptors.ShadowsSoftHigh }, { CoreKeywordDescriptors.LightmapShadowMixing }, { CoreKeywordDescriptors.ShadowsShadowmask }, { CoreKeywordDescriptors.DBuffer }, @@ -849,8 +846,7 @@ static class LitKeywords { CoreKeywordDescriptors.DebugDisplay }, { CoreKeywordDescriptors.LightCookies }, { CoreKeywordDescriptors.ForwardPlus }, - { CoreKeywordDescriptors.EvaluateShVertex }, - { CoreKeywordDescriptors.EvaluateShMixed }, + { CoreKeywordDescriptors.EvaluateSh }, }; public static readonly KeywordCollection GBuffer = new KeywordCollection @@ -862,9 +858,6 @@ static class LitKeywords { CoreKeywordDescriptors.ReflectionProbeBlending }, { CoreKeywordDescriptors.ReflectionProbeBoxProjection }, { CoreKeywordDescriptors.ShadowsSoft }, - { CoreKeywordDescriptors.ShadowsSoftLow }, - { CoreKeywordDescriptors.ShadowsSoftMedium }, - { CoreKeywordDescriptors.ShadowsSoftHigh }, { CoreKeywordDescriptors.LightmapShadowMixing }, { CoreKeywordDescriptors.ShadowsShadowmask }, { CoreKeywordDescriptors.MixedLightingSubtractive }, diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSixWaySubTarget.cs b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSixWaySubTarget.cs index 70a6534de17..416b72d696d 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSixWaySubTarget.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalSixWaySubTarget.cs @@ -471,9 +471,6 @@ static class SixWayKeywords { CoreKeywordDescriptors.AdditionalLights }, { CoreKeywordDescriptors.AdditionalLightShadows }, { CoreKeywordDescriptors.ShadowsSoft }, - { CoreKeywordDescriptors.ShadowsSoftLow }, - { CoreKeywordDescriptors.ShadowsSoftMedium }, - { CoreKeywordDescriptors.ShadowsSoftHigh }, { CoreKeywordDescriptors.ShadowsShadowmask }, { CoreKeywordDescriptors.LightLayers }, { CoreKeywordDescriptors.DebugDisplay }, diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs index 8086efe4a88..5ac2ba45ccf 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalTarget.cs @@ -1663,7 +1663,7 @@ static class CoreIncludes const string kSelectionPickingPass = "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/SelectionPickingPass.hlsl"; const string kLODCrossFade = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/LODCrossFade.hlsl"; const string kFoveatedRenderingKeywords = "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"; - const string kFoveatedRendering = "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl"; + const string kFoveatedRendering = "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl"; // Files that are included with #include_with_pragmas const string kDOTS = "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DOTS.hlsl"; @@ -1898,22 +1898,19 @@ static class CoreKeywordDescriptors stages = KeywordShaderStage.Fragment, }; - public static readonly KeywordDescriptor EvaluateShMixed = new KeywordDescriptor() + public static readonly KeywordDescriptor EvaluateSh = new KeywordDescriptor() { - displayName = ShaderKeywordStrings.EVALUATE_SH_MIXED, - referenceName = ShaderKeywordStrings.EVALUATE_SH_MIXED, - type = KeywordType.Boolean, - definition = KeywordDefinition.MultiCompile, - scope = KeywordScope.Global, - }; - - public static readonly KeywordDescriptor EvaluateShVertex = new KeywordDescriptor() - { - displayName = ShaderKeywordStrings.EVALUATE_SH_VERTEX, - referenceName = ShaderKeywordStrings.EVALUATE_SH_VERTEX, - type = KeywordType.Boolean, + displayName = "Evaluate SH", + referenceName = "EVALUATE_SH", + type = KeywordType.Enum, definition = KeywordDefinition.MultiCompile, scope = KeywordScope.Global, + entries = new KeywordEntry[] + { + new KeywordEntry() { displayName = "Off", referenceName = "" }, + new KeywordEntry() { displayName = "Evaluate SH Mixed", referenceName = "MIXED" }, + new KeywordEntry() { displayName = "Evaluate SH Vertex", referenceName = "VERTEX" }, + } }; public static readonly KeywordDescriptor MainLightShadows = new KeywordDescriptor() @@ -2009,42 +2006,20 @@ static class CoreKeywordDescriptors public static readonly KeywordDescriptor ShadowsSoft = new KeywordDescriptor() { - displayName = "Shadows Soft", - referenceName = "_SHADOWS_SOFT", - type = KeywordType.Boolean, - definition = KeywordDefinition.MultiCompile, - scope = KeywordScope.Global, - stages = KeywordShaderStage.Fragment, - }; - - public static readonly KeywordDescriptor ShadowsSoftLow = new KeywordDescriptor() - { - displayName = "Shadows Soft Low Quality", - referenceName = "_SHADOWS_SOFT_LOW", - type = KeywordType.Boolean, - definition = KeywordDefinition.MultiCompile, - scope = KeywordScope.Global, - stages = KeywordShaderStage.Fragment, - }; - - public static readonly KeywordDescriptor ShadowsSoftMedium = new KeywordDescriptor() - { - displayName = "Shadows Soft Medium Quality", - referenceName = "_SHADOWS_SOFT_MEDIUM", - type = KeywordType.Boolean, - definition = KeywordDefinition.MultiCompile, - scope = KeywordScope.Global, - stages = KeywordShaderStage.Fragment, - }; - - public static readonly KeywordDescriptor ShadowsSoftHigh = new KeywordDescriptor() - { - displayName = "Shadows Soft High Quality", - referenceName = "_SHADOWS_SOFT_HIGH", - type = KeywordType.Boolean, + displayName = "Soft Shadows", + referenceName = "", + type = KeywordType.Enum, definition = KeywordDefinition.MultiCompile, scope = KeywordScope.Global, stages = KeywordShaderStage.Fragment, + entries = new KeywordEntry[] + { + new KeywordEntry() { displayName = "Off", referenceName = "" }, + new KeywordEntry() { displayName = "Soft Shadows Per Light", referenceName = "SHADOWS_SOFT" }, + new KeywordEntry() { displayName = "Soft Shadows Low", referenceName = "SHADOWS_SOFT_LOW" }, + new KeywordEntry() { displayName = "Soft Shadows Medium", referenceName = "SHADOWS_SOFT_MEDIUM" }, + new KeywordEntry() { displayName = "Soft Shadows High", referenceName = "SHADOWS_SOFT_HIGH" }, + } }; public static readonly KeywordDescriptor MixedLightingSubtractive = new KeywordDescriptor() @@ -2237,11 +2212,11 @@ static class CoreKeywordDescriptors referenceName = ShaderKeywordStrings.LOD_FADE_CROSSFADE, type = KeywordType.Boolean, definition = KeywordDefinition.MultiCompile, - + // Note: SpeedTree shaders used to have their own PS-based Crossfade, // as well as a VS-based smooth LOD transition effect. // These shaders need the LOD_FADE_CROSSFADE keyword in the VS - // to skip the VS-based effect. + // to skip the VS-based effect. scope = KeywordScope.Global }; diff --git a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalUnlitSubTarget.cs b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalUnlitSubTarget.cs index 4151ccb4f58..f32e1279c84 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalUnlitSubTarget.cs +++ b/Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Targets/UniversalUnlitSubTarget.cs @@ -379,7 +379,6 @@ static class UnlitKeywords public static readonly KeywordCollection GBuffer = new KeywordCollection { { CoreKeywordDescriptors.DBuffer }, - { CoreKeywordDescriptors.LODFadeCrossFade }, { CoreKeywordDescriptors.ScreenSpaceAmbientOcclusion }, }; } diff --git a/Packages/com.unity.render-pipelines.universal/Editor/VFXGraph/Shaders/VFXDecal.template b/Packages/com.unity.render-pipelines.universal/Editor/VFXGraph/Shaders/VFXDecal.template index c81efc6da2e..0ba2143f186 100644 --- a/Packages/com.unity.render-pipelines.universal/Editor/VFXGraph/Shaders/VFXDecal.template +++ b/Packages/com.unity.render-pipelines.universal/Editor/VFXGraph/Shaders/VFXDecal.template @@ -52,7 +52,7 @@ void VFXGetSurfaceDecalData(out DecalSurfaceData surfaceData, out PositionInputs #if _RENDER_PASS_ENABLED - float depth = LOAD_FRAMEBUFFER_INPUT(GBUFFER3, positionCS.xy); + float depth = LOAD_FRAMEBUFFER_INPUT(GBUFFER3, positionCS.xy).x; #else float depth = LoadSceneDepth(positionCS.xy); #endif diff --git a/Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl b/Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl index 4658f676f75..52012acb156 100644 --- a/Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl +++ b/Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl @@ -180,7 +180,7 @@ half4 GetAdditionalLightShadowParams(int lightIndex) half SampleScreenSpaceShadowmap(float4 shadowCoord) { - shadowCoord.xy /= shadowCoord.w; + shadowCoord.xy /= max(0.00001, shadowCoord.w); // Prevent division by zero. // The stereo transform has to happen after the manual perspective divide shadowCoord.xy = UnityStereoTransformScreenSpaceTex(shadowCoord.xy); diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/Bloom.shader b/Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/Bloom.shader index d15151c7eaf..9c378e66e76 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/Bloom.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/PostProcessing/Bloom.shader @@ -8,7 +8,6 @@ Shader "Hidden/Universal Render Pipeline/Bloom" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl" #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/DynamicScalingClamping.hlsl" - #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl" TEXTURE2D_X(_SourceTexLowMip); float4 _SourceTexLowMip_TexelSize; @@ -185,6 +184,7 @@ Shader "Hidden/Universal Render Pipeline/Bloom" #pragma fragment FragPrefilter #pragma multi_compile_local _ _BLOOM_HQ #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl" ENDHLSL } @@ -196,6 +196,7 @@ Shader "Hidden/Universal Render Pipeline/Bloom" #pragma vertex Vert #pragma fragment FragBlurH #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl" ENDHLSL } @@ -207,6 +208,7 @@ Shader "Hidden/Universal Render Pipeline/Bloom" #pragma vertex Vert #pragma fragment FragBlurV #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl" ENDHLSL } @@ -219,6 +221,7 @@ Shader "Hidden/Universal Render Pipeline/Bloom" #pragma fragment FragUpsample #pragma multi_compile_local _ _BLOOM_HQ #include_with_pragmas "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRenderingKeywords.hlsl" + #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/FoveatedRendering.hlsl" ENDHLSL } } diff --git a/Tests/SRPTests/Projects/UniversalGraphicsTest_Foundation/Assets/Scenes/210_Motion_Vectors/Shaders/MotionVectorTestVisualization.shader b/Tests/SRPTests/Projects/UniversalGraphicsTest_Foundation/Assets/Scenes/210_Motion_Vectors/Shaders/MotionVectorTestVisualization.shader index 343dfd3edbc..f68902a5182 100644 --- a/Tests/SRPTests/Projects/UniversalGraphicsTest_Foundation/Assets/Scenes/210_Motion_Vectors/Shaders/MotionVectorTestVisualization.shader +++ b/Tests/SRPTests/Projects/UniversalGraphicsTest_Foundation/Assets/Scenes/210_Motion_Vectors/Shaders/MotionVectorTestVisualization.shader @@ -33,7 +33,7 @@ Shader "MotionVectorTestVisualization" float2 SampleMotionVectors(float2 coord) { - return SAMPLE_TEXTURE2D_X(_MotionVectorTexture, sampler_MotionVectorTexture, coord); + return SAMPLE_TEXTURE2D_X(_MotionVectorTexture, sampler_MotionVectorTexture, coord).xy; } float DistanceToLine(float2 p, float2 p1, float2 p2)