@@ -123,8 +123,6 @@ private void BuildShadowSettings()
123123 }
124124 }
125125
126- #region HelperMethods
127-
128126 private void SetupLightShaderVariables ( VisibleLight [ ] lights , ScriptableRenderContext context )
129127 {
130128 if ( lights . Length <= 0 )
@@ -196,9 +194,13 @@ private bool RenderShadows(CullResults cullResults, ScriptableRenderContext cont
196194 int lightIndex = - 1 ;
197195 for ( int i = 0 ; i < lightCount ; ++ i )
198196 {
199- if ( lights [ i ] . light . shadows != LightShadows . None && lights [ i ] . lightType == LightType . Directional )
197+ LightType type = lights [ i ] . lightType ;
198+ if ( lights [ i ] . light . shadows != LightShadows . None && ( type == LightType . Directional || type == LightType . Spot ) )
200199 {
201200 lightIndex = i ;
201+ if ( lights [ i ] . lightType == LightType . Spot )
202+ cascadeCount = 1 ;
203+
202204 shadowResolution = GetMaxTileResolutionInAtlas ( m_ShadowSettings . shadowAtlasWidth ,
203205 m_ShadowSettings . shadowAtlasHeight , cascadeCount ) ;
204206 break ;
@@ -224,24 +226,45 @@ private bool RenderShadows(CullResults cullResults, ScriptableRenderContext cont
224226
225227 float shadowNearPlane = m_Asset . ShadowNearOffset ;
226228 Vector3 splitRatio = m_ShadowSettings . directionalLightCascades ;
227- Vector3 lightDir = lights [ lightIndex ] . light . transform . forward ;
228- for ( int cascadeIdx = 0 ; cascadeIdx < cascadeCount ; ++ cascadeIdx )
229- {
230- Matrix4x4 view , proj ;
231- var settings = new DrawShadowsSettings ( cullResults , lightIndex ) ;
232- bool needRendering = cullResults . ComputeDirectionalShadowMatricesAndCullingPrimitives ( lightIndex ,
233- cascadeIdx , cascadeCount , splitRatio , shadowResolution , shadowNearPlane , out view , out proj ,
234- out settings . splitData ) ;
229+ Vector3 lightDir = Vector3 . Normalize ( lights [ lightIndex ] . light . transform . forward ) ;
235230
236- m_DirectionalShadowSplitDistances [ cascadeIdx ] = settings . splitData . cullingSphere ;
237- m_DirectionalShadowSplitDistances [ cascadeIdx ] . w *= settings . splitData . cullingSphere . w ;
231+ Matrix4x4 view , proj ;
232+ var settings = new DrawShadowsSettings ( cullResults , lightIndex ) ;
233+ bool needRendering = false ;
234+
235+ if ( lights [ lightIndex ] . lightType == LightType . Spot )
236+ {
237+ needRendering = cullResults . ComputeSpotShadowMatricesAndCullingPrimitives ( lightIndex , out view , out proj ,
238+ out settings . splitData ) ;
238239
239240 if ( needRendering )
240241 {
241- SetupShadowSliceTransform ( cascadeIdx , shadowResolution , proj , view ) ;
242- RenderShadowSlice ( ref context , lightDir , cascadeIdx , proj , view , settings ) ;
242+ SetupShadowSliceTransform ( 0 , shadowResolution , proj , view ) ;
243+ RenderShadowSlice ( ref context , lightDir , 0 , proj , view , settings ) ;
244+ }
245+ }
246+ else if ( lights [ lightIndex ] . lightType == LightType . Directional )
247+ {
248+ for ( int cascadeIdx = 0 ; cascadeIdx < cascadeCount ; ++ cascadeIdx )
249+ {
250+ needRendering = cullResults . ComputeDirectionalShadowMatricesAndCullingPrimitives ( lightIndex ,
251+ cascadeIdx , cascadeCount , splitRatio , shadowResolution , shadowNearPlane , out view , out proj ,
252+ out settings . splitData ) ;
253+
254+ m_DirectionalShadowSplitDistances [ cascadeIdx ] = settings . splitData . cullingSphere ;
255+ m_DirectionalShadowSplitDistances [ cascadeIdx ] . w *= settings . splitData . cullingSphere . w ;
256+
257+ if ( needRendering )
258+ {
259+ SetupShadowSliceTransform ( cascadeIdx , shadowResolution , proj , view ) ;
260+ RenderShadowSlice ( ref context , lightDir , cascadeIdx , proj , view , settings ) ;
261+ }
243262 }
244263 }
264+ else
265+ {
266+ Debug . LogWarning ( "Only spot and directional shadow casters are supported in lowend mobile pipeline" ) ;
267+ }
245268
246269 return true ;
247270 }
@@ -343,15 +366,15 @@ void SetupShadowShaderVariables(ScriptableRenderContext context, int cascadeCoun
343366
344367 void SetShaderKeywords ( CommandBuffer cmd )
345368 {
346- if ( m_Asset . SupportsVertexLight )
347- cmd . EnableShaderKeyword ( "_VERTEX_LIGHTS" ) ;
348- else
349- cmd . DisableShaderKeyword ( "_VERTEX_LIGHTS" ) ;
369+ if ( m_Asset . SupportsVertexLight )
370+ cmd . EnableShaderKeyword ( "_VERTEX_LIGHTS" ) ;
371+ else
372+ cmd . DisableShaderKeyword ( "_VERTEX_LIGHTS" ) ;
350373
351374 if ( m_Asset . CascadeCount == 1 )
352- cmd . DisableShaderKeyword ( "_SHADOW_CASCADES" ) ;
375+ cmd . DisableShaderKeyword ( "_SHADOW_CASCADES" ) ;
353376 else
354- cmd . EnableShaderKeyword ( "_SHADOW_CASCADES" ) ;
377+ cmd . EnableShaderKeyword ( "_SHADOW_CASCADES" ) ;
355378
356379 switch ( m_Asset . CurrShadowType )
357380 {
@@ -371,7 +394,5 @@ void SetShaderKeywords(CommandBuffer cmd)
371394 break ;
372395 }
373396 }
374-
375- #endregion
376397 }
377398}
0 commit comments