@@ -112,56 +112,47 @@ inline void ForwardLighting(inout Surface surface, inout Lighting lighting)
112112 }
113113
114114 [branch]
115- if (any ( xForwardLightMask) )
115+ if (xForwardLightMask != 0 )
116116 {
117117 // Loop through light buckets for the draw call:
118- const uint first_item = 0 ;
119- const uint last_item = first_item + lights ().item_count () - 1 ;
120- const uint first_bucket = first_item / 32 ;
121- const uint last_bucket = min (last_item / 32 , 1 ); // only 2 buckets max (uint2) for forward pass!
118+ uint bucket_bits = xForwardLightMask;
119+
122120 [loop]
123- for ( uint bucket = first_bucket; bucket <= last_bucket; ++bucket )
121+ while (bucket_bits != 0 )
124122 {
125- uint bucket_bits = xForwardLightMask[bucket];
126-
127- [loop]
128- while (bucket_bits != 0 )
129- {
130- // Retrieve global entity index from local bucket, then remove bit from local bucket:
131- const uint bucket_bit_index = firstbitlow (bucket_bits);
132- const uint entity_index = bucket * 32 + bucket_bit_index;
133- bucket_bits ^= 1u << bucket_bit_index;
123+ // Retrieve global entity index from local bucket, then remove bit from local bucket:
124+ const uint entity_index = firstbitlow (bucket_bits);
125+ bucket_bits ^= 1u << entity_index;
134126
135- ShaderEntity light = load_entity (lights ().first_item () + entity_index);
127+ ShaderEntity light = load_entity (lights ().first_item () + entity_index);
136128
137129#ifndef INCLUDE_STATIC_LIGHTS
138- if (light.IsStaticLight ())
139- continue ; // static lights will be skipped here (they are used at lightmap baking)
130+ if (light.IsStaticLight ())
131+ continue ; // static lights will be skipped here (they are used at lightmap baking)
140132#endif // INCLUDE_STATIC_LIGHTS
141133
142- switch (light.GetType ())
143- {
144- case ENTITY_TYPE_DIRECTIONALLIGHT:
145- {
146- light_directional (light, surface, lighting);
147- }
148- break ;
149- case ENTITY_TYPE_POINTLIGHT:
150- {
151- light_point (light, surface, lighting);
152- }
153- break ;
154- case ENTITY_TYPE_SPOTLIGHT:
155- {
156- light_spot (light, surface, lighting);
157- }
158- break ;
159- case ENTITY_TYPE_RECTLIGHT:
160- {
161- light_rect (light, surface, lighting);
162- }
163- break ;
164- }
134+ switch (light.GetType ())
135+ {
136+ case ENTITY_TYPE_DIRECTIONALLIGHT:
137+ {
138+ light_directional (light, surface, lighting);
139+ }
140+ break ;
141+ case ENTITY_TYPE_POINTLIGHT:
142+ {
143+ light_point (light, surface, lighting);
144+ }
145+ break ;
146+ case ENTITY_TYPE_SPOTLIGHT:
147+ {
148+ light_spot (light, surface, lighting);
149+ }
150+ break ;
151+ case ENTITY_TYPE_RECTLIGHT:
152+ {
153+ light_rect (light, surface, lighting);
154+ }
155+ break ;
165156 }
166157 }
167158 }
@@ -298,7 +289,7 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
298289 {
299290 // Loop through envmap buckets in the tile:
300291 ShaderEntityIterator iterator = probes ();
301- for (uint bucket = iterator.first_bucket (); bucket <= iterator.last_bucket (); ++bucket)
292+ for (uint bucket = iterator.first_bucket (); bucket <= iterator.last_bucket (); ++bucket)
302293 {
303294 uint bucket_bits = load_entitytile (flatTileIndex + bucket);
304295 bucket_bits = iterator.mask_entity (bucket, bucket_bits);
@@ -403,7 +394,7 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
403394 {
404395 // Directional lights are not culled, so simply iterate through each one:
405396 ShaderEntityIterator iterator = directional_lights ();
406- for (uint entity_index = iterator.first_item (); entity_index < iterator.end_item (); ++entity_index)
397+ for (uint entity_index = iterator.first_item (); entity_index < iterator.end_item (); ++entity_index)
407398 {
408399 ShaderEntity light = load_entity (entity_index);
409400
@@ -434,7 +425,7 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
434425 {
435426 // Loop through light buckets in the tile:
436427 ShaderEntityIterator iterator = spotlights ();
437- for (uint bucket = iterator.first_bucket (); bucket <= iterator.last_bucket (); ++bucket)
428+ for (uint bucket = iterator.first_bucket (); bucket <= iterator.last_bucket (); ++bucket)
438429 {
439430 uint bucket_bits = load_entitytile (flatTileIndex + bucket);
440431 bucket_bits = iterator.mask_entity (bucket, bucket_bits);
@@ -476,7 +467,7 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
476467 {
477468 // Loop through light buckets in the tile:
478469 ShaderEntityIterator iterator = pointlights ();
479- for (uint bucket = iterator.first_bucket (); bucket <= iterator.last_bucket (); ++bucket)
470+ for (uint bucket = iterator.first_bucket (); bucket <= iterator.last_bucket (); ++bucket)
480471 {
481472 uint bucket_bits = load_entitytile (flatTileIndex + bucket);
482473 bucket_bits = iterator.mask_entity (bucket, bucket_bits);
@@ -518,7 +509,7 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
518509 {
519510 // Loop through light buckets in the tile:
520511 ShaderEntityIterator iterator = rectlights ();
521- for (uint bucket = iterator.first_bucket (); bucket <= iterator.last_bucket (); ++bucket)
512+ for (uint bucket = iterator.first_bucket (); bucket <= iterator.last_bucket (); ++bucket)
522513 {
523514 uint bucket_bits = load_entitytile (flatTileIndex + bucket);
524515 bucket_bits = iterator.mask_entity (bucket, bucket_bits);
@@ -564,9 +555,9 @@ inline void TiledLighting(inout Surface surface, inout Lighting lighting, uint f
564555 half capsuleshadow = 1 ;
565556 half capsulereflection = 1 ;
566557
567- // Loop through light buckets in the tile:
558+ // Loop through entity buckets in the tile:
568559 ShaderEntityIterator iterator = forces ();
569- for (uint bucket = iterator.first_bucket (); ( bucket <= iterator.last_bucket ()) && (capsuleshadow > 0 || capsulereflection > 0 ); ++bucket)
560+ for (uint bucket = iterator.first_bucket (); bucket <= iterator.last_bucket (); ++bucket)
570561 {
571562 uint bucket_bits = load_entitytile (flatTileIndex + bucket);
572563 bucket_bits = iterator.mask_entity (bucket, bucket_bits);
@@ -641,7 +632,7 @@ inline void TiledDecals(inout Surface surface, uint flatTileIndex, inout half4 s
641632
642633 // Loop through decal buckets in the tile:
643634 ShaderEntityIterator iterator = decals ();
644- for (uint bucket = iterator.first_bucket (); bucket <= iterator.last_bucket (); ++bucket)
635+ for (uint bucket = iterator.first_bucket (); bucket <= iterator.last_bucket (); ++bucket)
645636 {
646637 uint bucket_bits = load_entitytile (flatTileIndex + bucket);
647638 bucket_bits = iterator.mask_entity (bucket, bucket_bits);
0 commit comments