Skip to content

Commit 980e79a

Browse files
committed
Updated files to match the changes done to the LIT shader for URP 14. No major changes other than adding LOD crossfade and alpha mask. Should still be backwards compatible with older versions.
1 parent a84b71a commit 980e79a

File tree

4 files changed

+194
-274
lines changed

4 files changed

+194
-274
lines changed

Editor/ShaderGraph/Includes/SimpleLitForwardPass.hlsl

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ void InitializeInputData(Varyings input, SurfaceDescription surfaceDescription,
2222
inputData.normalWS = input.normalWS;
2323
#endif
2424
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
25+
#if UNITY_VERSION >= 202220
26+
inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS);
27+
#else
2528
inputData.viewDirectionWS = SafeNormalize(GetWorldSpaceViewDir(input.positionWS));
29+
#endif
2630

2731
#if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
2832
inputData.shadowCoord = input.shadowCoord;
@@ -63,13 +67,42 @@ PackedVaryings vert(Attributes input)
6367
return packedOutput;
6468
}
6569

70+
#if UNITY_VERSION >= 202220
71+
void frag(
72+
PackedVaryings packedInput
73+
, out half4 outColor : SV_Target0
74+
#ifdef _WRITE_RENDERING_LAYERS
75+
, out float4 outRenderingLayers : SV_Target1
76+
#endif
77+
)
78+
#else
6679
half4 frag(PackedVaryings packedInput) : SV_TARGET
80+
#endif //UNITY_VERSION 202220
6781
{
6882
Varyings unpacked = UnpackVaryings(packedInput);
6983
UNITY_SETUP_INSTANCE_ID(unpacked);
7084
UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(unpacked);
7185
SurfaceDescription surfaceDescription = BuildSurfaceDescription(unpacked);
7286

87+
#if UNITY_VERSION >= 202220
88+
#if defined(_SURFACE_TYPE_TRANSPARENT)
89+
bool isTransparent = true;
90+
#else
91+
bool isTransparent = false;
92+
#endif
93+
94+
#if defined(_ALPHATEST_ON)
95+
half alpha = AlphaDiscard(surfaceDescription.Alpha, surfaceDescription.AlphaClipThreshold);
96+
#elif defined(_SURFACE_TYPE_TRANSPARENT)
97+
half alpha = surfaceDescription.Alpha;
98+
#else
99+
half alpha = half(1.0);
100+
#endif
101+
102+
#if defined(LOD_FADE_CROSSFADE) && USE_UNITY_CROSSFADE
103+
LODFadeCrossFade(unpacked.positionCS);
104+
#endif
105+
#else
73106
#if _ALPHATEST_ON
74107
half alpha = surfaceDescription.Alpha;
75108
clip(alpha - surfaceDescription.AlphaClipThreshold);
@@ -78,6 +111,7 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET
78111
#else
79112
half alpha = 1;
80113
#endif
114+
#endif //UNITY_VERSION 202220
81115

82116
InputData inputData;
83117
InitializeInputData(unpacked, surfaceDescription, inputData);
@@ -110,11 +144,6 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET
110144
surface.clearCoatMask = 0;
111145
surface.clearCoatSmoothness = 1;
112146

113-
//#ifdef _CLEARCOAT
114-
// surface.clearCoatMask = saturate(surfaceDescription.CoatMask);
115-
// surface.clearCoatSmoothness = saturate(surfaceDescription.CoatSmoothness);
116-
//#endif
117-
118147
#if UNITY_VERSION >= 202210
119148
surface.albedo = AlphaModulate(surface.albedo, surface.alpha);
120149
#endif
@@ -123,9 +152,21 @@ half4 frag(PackedVaryings packedInput) : SV_TARGET
123152
ApplyDecalToSurfaceData(unpacked.positionCS, surface, inputData);
124153
#endif
125154

126-
//half4 color = UniversalFragmentPBR(inputData, surface);
127155
half4 color = UniversalFragmentBlinnPhong(inputData, surface);
128156

129157
color.rgb = MixFog(color.rgb, inputData.fogCoord);
158+
#if UNITY_VERSION >= 202220
159+
160+
color.a = OutputAlpha(color.a, isTransparent);
161+
162+
outColor = color;
163+
164+
#ifdef _WRITE_RENDERING_LAYERS
165+
uint renderingLayers = GetMeshRenderingLayer();
166+
outRenderingLayers = float4(EncodeMeshRenderingLayer(renderingLayers), 0, 0, 0);
167+
#endif
168+
169+
#else
130170
return color;
171+
#endif //UNITY_VERSION 202220
131172
}

Editor/ShaderGraph/Includes/SimpleLitGBufferPass.hlsl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ void InitializeInputData(Varyings input, SurfaceDescription surfaceDescription,
2323
inputData.normalWS = input.normalWS;
2424
#endif
2525
inputData.normalWS = NormalizeNormalPerPixel(inputData.normalWS);
26+
#if UNITY_VERSION >= 202220
27+
inputData.viewDirectionWS = GetWorldSpaceNormalizeViewDir(input.positionWS);
28+
#else
2629
inputData.viewDirectionWS = SafeNormalize(GetWorldSpaceViewDir(input.positionWS));
30+
#endif
2731

2832
#if defined(MAIN_LIGHT_CALCULATE_SHADOWS)
2933
inputData.shadowCoord = TransformWorldToShadowCoord(inputData.positionWS);
@@ -78,6 +82,12 @@ FragmentOutput frag(PackedVaryings packedInput)
7882
half alpha = 1;
7983
#endif
8084

85+
#if UNITY_VERSION >= 202220
86+
#if defined(LOD_FADE_CROSSFADE) && USE_UNITY_CROSSFADE
87+
LODFadeCrossFade(unpacked.positionCS);
88+
#endif
89+
#endif
90+
8191
InputData inputData;
8292
InitializeInputData(unpacked, surfaceDescription, inputData);
8393
// TODO: Mip debug modes would require this, open question how to do this on ShaderGraph.

0 commit comments

Comments
 (0)