@@ -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
6679half4 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}
0 commit comments