@@ -114,18 +114,14 @@ Shader "ScriptableRenderPipeline/LowEndMobile/NonPBR"
114114
115115#if defined (_VERTEX_LIGHTS)
116116 half4 diffuseAndSpecular = half4 (1.0 , 1.0 , 1.0 , 1.0 );
117- for (int lightIndex = globalLightCount .x; lightIndex < globalLightCount .y; ++lightIndex)
117+ for (int lightIndex = globalLightData .x; lightIndex < globalLightData .y; ++lightIndex)
118118 {
119119 LightInput lightInput;
120120 INITIALIZE_LIGHT (lightInput, lightIndex);
121121 o.fogCoord.yzw += EvaluateOneLight (lightInput, diffuseAndSpecular.rgb, diffuseAndSpecular, normal, o.posWS, o.viewDir.xyz);
122122 }
123123#endif
124124
125- #ifndef _SHADOW_CASCADES
126- o.shadowCoord = mul (_WorldToShadow[0 ], float4 (o.posWS, 1.0 ));
127- #endif
128-
129125#ifdef _LIGHT_PROBES_ON
130126 o.fogCoord.yzw += max (half3 (0 , 0 , 0 ), ShadeSH9 (half4 (normal, 1 )));
131127#endif
@@ -152,23 +148,24 @@ Shader "ScriptableRenderPipeline/LowEndMobile/NonPBR"
152148 half4 specularGloss;
153149 SpecularGloss (i.uv01.xy, diffuse, alpha, specularGloss);
154150
155- #ifdef _SHADOWS
156- half shadowAttenuation = ComputeShadowAttenuation (i);
157- #else
158- half shadowAttenuation = 1.0f ;
159- #endif
160151 half3 viewDir = i.viewDir.xyz;
161152
162153 // TODO: Restrict pixel lights by 4. This way we can keep moderate constrain for most LD project
163154 // and can benefit from better data layout/avoid branching by doing vec math.
164155 half3 color = half3 (0 , 0 , 0 );
165- for (int lightIndex = 0 ; lightIndex < globalLightCount .x; ++lightIndex)
156+ for (int lightIndex = 0 ; lightIndex < globalLightData .x; ++lightIndex)
166157 {
167- LightInput additionalLight;
168- INITIALIZE_LIGHT (additionalLight, lightIndex);
169- color += EvaluateOneLight (additionalLight, diffuse, specularGloss, normal, i.posWS, viewDir);
158+ LightInput lightData;
159+ half NdotL;
160+ INITIALIZE_LIGHT (lightData, lightIndex);
161+ color += EvaluateOneLight (lightData, diffuse, specularGloss, normal, i.posWS, viewDir, NdotL);
162+ #ifdef _SHADOWS
170163 if (lightIndex == 0 )
171- color *= shadowAttenuation;
164+ {
165+ float bias = max (globalLightData.z, (1.0 - NdotL) * globalLightData.w);
166+ color *= ComputeShadowAttenuation (i, i.normal * bias);
167+ }
168+ #endif
172169 }
173170
174171 half3 emissionColor;
@@ -210,39 +207,11 @@ Shader "ScriptableRenderPipeline/LowEndMobile/NonPBR"
210207 #pragma vertex vert
211208 #pragma fragment frag
212209
213- float4 _WorldLightDirAndBias;
214-
215210 #include "UnityCG.cginc"
216211
217- struct VertexInput
218- {
219- float4 pos : POSITION ;
220- float3 normal : NORMAL ;
221- };
222-
223- // Similar to UnityClipSpaceShadowCasterPos but using LDPipeline lightdir and bias and applying near plane clamp
224- float4 ClipSpaceShadowCasterPos (float4 vertex, float3 normal)
212+ float4 vert (float4 pos : POSITION ) : SV_POSITION
225213 {
226- float4 wPos = mul (unity_ObjectToWorld , vertex);
227-
228- if (_WorldLightDirAndBias.w > 0.0 )
229- {
230- float3 wNormal = UnityObjectToWorldNormal (normal);
231-
232- // apply normal offset bias (inset position along the normal)
233- // bias needs to be scaled by sine between normal and light direction
234- // (http://the-witness.net/news/2013/09/shadow-mapping-summary-part-1/)
235- //
236- // _WorldLightDirAndBias.w shadow bias defined in LRRenderPipeline asset
237-
238- float shadowCos = dot (wNormal, _WorldLightDirAndBias.xyz);
239- float shadowSine = sqrt (1 - shadowCos*shadowCos);
240- float normalBias = _WorldLightDirAndBias.w * shadowSine;
241-
242- wPos.xyz -= wNormal * normalBias;
243- }
244-
245- float4 clipPos = mul (UNITY_MATRIX_VP , wPos);
214+ float4 clipPos = UnityObjectToClipPos (pos);
246215#if defined (UNITY_REVERSED_Z )
247216 clipPos.z = min (clipPos.z, UNITY_NEAR_CLIP_VALUE );
248217#else
@@ -251,40 +220,35 @@ Shader "ScriptableRenderPipeline/LowEndMobile/NonPBR"
251220 return clipPos;
252221 }
253222
254- float4 vert (VertexInput i) : SV_POSITION
255- {
256- return ClipSpaceShadowCasterPos (i.pos, i.normal);
257- }
258-
259223 half4 frag () : SV_TARGET
260224 {
261225 return 0 ;
262226 }
263227 ENDCG
264228 }
265229
266- // This pass it not used during regular rendering, only for lightmap baking.
267- Pass
268- {
269- Name "LD_META"
270- Tags { "LightMode" = "Meta" }
230+ // This pass it not used during regular rendering, only for lightmap baking.
231+ Pass
232+ {
233+ Name "LD_META"
234+ Tags { "LightMode" = "Meta" }
271235
272- Cull Off
236+ Cull Off
273237
274- CGPROGRAM
275- #pragma vertex vert_meta
276- #pragma fragment frag_meta
238+ CGPROGRAM
239+ #pragma vertex vert_meta
240+ #pragma fragment frag_meta
277241
278- #pragma shader_feature _EMISSION
279- #pragma shader_feature _METALLICGLOSSMAP
280- #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
281- #pragma shader_feature ___ _DETAIL_MULX2
282- #pragma shader_feature EDITOR_VISUALIZATION
242+ #pragma shader_feature _EMISSION
243+ #pragma shader_feature _METALLICGLOSSMAP
244+ #pragma shader_feature _ _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
245+ #pragma shader_feature ___ _DETAIL_MULX2
246+ #pragma shader_feature EDITOR_VISUALIZATION
283247
284- #include "UnityStandardMeta.cginc"
285- ENDCG
286- }
248+ #include "UnityStandardMeta.cginc"
249+ ENDCG
287250 }
288- Fallback "Standard (Specular setup)"
289- CustomEditor "LowendMobilePipelineMaterialEditor"
251+ }
252+ Fallback "Standard (Specular setup)"
253+ CustomEditor "LowendMobilePipelineMaterialEditor"
290254}
0 commit comments