Skip to content

Commit

Permalink
[2023.2][URP] Various Shader fixes (UUM-59974)
Browse files Browse the repository at this point in the history
Backport of #42134
  • Loading branch information
ellioman authored and Evergreen committed Jan 9, 2024
1 parent 354e86f commit f16545c
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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 },
Expand All @@ -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 },
Expand All @@ -1047,9 +1038,6 @@ static class Descriptors
{
{ CoreKeywordDescriptors.MainLightShadows },
{ CoreKeywordDescriptors.ShadowsSoft },
{ CoreKeywordDescriptors.ShadowsSoftLow },
{ CoreKeywordDescriptors.ShadowsSoftMedium },
{ CoreKeywordDescriptors.ShadowsSoftHigh },
{ Descriptors.DecalsNormalBlend },
{ Descriptors.DecalLayers },
{ CoreKeywordDescriptors.GBufferNormalsOct },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -839,18 +839,14 @@ static class LitKeywords
{ CoreKeywordDescriptors.ReflectionProbeBlending },
{ CoreKeywordDescriptors.ReflectionProbeBoxProjection },
{ CoreKeywordDescriptors.ShadowsSoft },
{ CoreKeywordDescriptors.ShadowsSoftLow },
{ CoreKeywordDescriptors.ShadowsSoftMedium },
{ CoreKeywordDescriptors.ShadowsSoftHigh },
{ CoreKeywordDescriptors.LightmapShadowMixing },
{ CoreKeywordDescriptors.ShadowsShadowmask },
{ CoreKeywordDescriptors.DBuffer },
{ CoreKeywordDescriptors.LightLayers },
{ CoreKeywordDescriptors.DebugDisplay },
{ CoreKeywordDescriptors.LightCookies },
{ CoreKeywordDescriptors.ForwardPlus },
{ CoreKeywordDescriptors.EvaluateShVertex },
{ CoreKeywordDescriptors.EvaluateShMixed },
{ CoreKeywordDescriptors.EvaluateSh },
};

public static readonly KeywordCollection GBuffer = new KeywordCollection
Expand All @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,6 @@ static class UnlitKeywords
public static readonly KeywordCollection GBuffer = new KeywordCollection
{
{ CoreKeywordDescriptors.DBuffer },
{ CoreKeywordDescriptors.LODFadeCrossFade },
{ CoreKeywordDescriptors.ScreenSpaceAmbientOcclusion },
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}

Expand All @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f16545c

Please sign in to comment.