@@ -456,24 +456,35 @@ void main() {
456
456
diffuse_light_interp = vec4 (0.0 );
457
457
specular_light_interp = vec4 (0.0 );
458
458
459
+ uint omni_light_count = sc_omni_lights(8 );
459
460
uvec2 omni_light_indices = instances.data[draw_call.instance_index].omni_lights;
460
- for (uint i = 0 ; i < sc_omni_lights() ; i++ ) {
461
+ for (uint i = 0 ; i < omni_light_count ; i++ ) {
461
462
uint light_index = (i > 3 ) ? ((omni_light_indices.y >> ((i - 4 ) * 8 )) & 0xFF) : ((omni_light_indices.x >> (i * 8 )) & 0xFF);
463
+ if (i > 0 && light_index == 0xFF) {
464
+ break ;
465
+ }
466
+
462
467
light_process_omni_vertex(light_index, vertex, view, normal_interp, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb);
463
468
}
464
469
470
+ uint spot_light_count = sc_spot_lights(8 );
465
471
uvec2 spot_light_indices = instances.data[draw_call.instance_index].spot_lights;
466
- for (uint i = 0 ; i < sc_spot_lights() ; i++ ) {
472
+ for (uint i = 0 ; i < spot_light_count ; i++ ) {
467
473
uint light_index = (i > 3 ) ? ((spot_light_indices.y >> ((i - 4 ) * 8 )) & 0xFF) : ((spot_light_indices.x >> (i * 8 )) & 0xFF);
474
+ if (i > 0 && light_index == 0xFF) {
475
+ break ;
476
+ }
477
+
468
478
light_process_spot_vertex(light_index, vertex, view, normal_interp, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb);
469
479
}
470
480
471
- if (sc_directional_lights() > 0 ) {
481
+ uint directional_lights_count = sc_directional_lights(scene_data.directional_light_count);
482
+ if (directional_lights_count > 0 ) {
472
483
// We process the first directional light separately as it may have shadows.
473
484
vec3 directional_diffuse = vec3 (0.0 );
474
485
vec3 directional_specular = vec3 (0.0 );
475
486
476
- for (uint i = 0 ; i < sc_directional_lights() ; i++ ) {
487
+ for (uint i = 0 ; i < directional_lights_count ; i++ ) {
477
488
if (! bool (directional_lights.data[i].mask & instances.data[draw_call.instance_index].layer_mask)) {
478
489
continue ; // Not masked, skip.
479
490
}
@@ -729,6 +740,8 @@ layout(set = MATERIAL_UNIFORM_SET, binding = 0, std140) uniform MaterialUniforms
729
740
730
741
#GLOBALS
731
742
743
+ #define scene_data scene_data_block.data
744
+
732
745
/* clang-format on */
733
746
734
747
#ifdef MODE_RENDER_DEPTH
@@ -799,7 +812,8 @@ vec4 fog_process(vec3 vertex) {
799
812
float sun_total = 0.0 ;
800
813
vec3 view = normalize (vertex);
801
814
802
- for (uint i = 0 ; i < sc_directional_lights(); i++ ) {
815
+ uint directional_lights_count = sc_directional_lights(scene_data.directional_light_count);
816
+ for (uint i = 0 ; i < directional_lights_count; i++ ) {
803
817
vec3 light_color = directional_lights.data[i].color * directional_lights.data[i].energy;
804
818
float light_amount = pow (max (dot (view, directional_lights.data[i].direction), 0.0 ), 8.0 );
805
819
fog_color += light_color * light_amount * scene_data_block.data.fog_sun_scatter;
@@ -831,8 +845,6 @@ vec4 fog_process(vec3 vertex) {
831
845
832
846
#endif // !MODE_RENDER DEPTH
833
847
834
- #define scene_data scene_data_block.data
835
-
836
848
void main() {
837
849
#ifdef UBERSHADER
838
850
bool front_facing = gl_FrontFacing ;
@@ -1129,9 +1141,13 @@ void main() {
1129
1141
vec3 vertex_ddx = dFdx (vertex);
1130
1142
vec3 vertex_ddy = dFdy (vertex);
1131
1143
1144
+ uint decal_count = sc_decals(8 );
1132
1145
uvec2 decal_indices = instances.data[draw_call.instance_index].decals;
1133
- for (uint i = 0 ; i < sc_decals() ; i++ ) {
1146
+ for (uint i = 0 ; i < decal_count ; i++ ) {
1134
1147
uint decal_index = (i > 3 ) ? ((decal_indices.y >> ((i - 4 ) * 8 )) & 0xFF) : ((decal_indices.x >> (i * 8 )) & 0xFF);
1148
+ if (decal_index == 0xFF) {
1149
+ break ;
1150
+ }
1135
1151
1136
1152
vec3 uv_local = (decals.data[decal_index].xform * vec4 (vertex, 1.0 )).xyz;
1137
1153
if (any (lessThan (uv_local, vec3 (0.0 , - 1.0 , 0.0 ))) || any (greaterThan (uv_local, vec3 (1.0 )))) {
@@ -1405,7 +1421,8 @@ void main() {
1405
1421
1406
1422
// skipping ssao, do we remove ssao totally?
1407
1423
1408
- if (sc_reflection_probes() > 0 ) {
1424
+ uint reflection_probe_count = sc_reflection_probes(8 );
1425
+ if (reflection_probe_count > 0 ) {
1409
1426
vec4 reflection_accum = vec4 (0.0 , 0.0 , 0.0 , 0.0 );
1410
1427
vec4 ambient_accum = vec4 (0.0 , 0.0 , 0.0 , 0.0 );
1411
1428
@@ -1423,8 +1440,11 @@ void main() {
1423
1440
ref_vec = mix (ref_vec, bent_normal, roughness * roughness * roughness * roughness);
1424
1441
1425
1442
uvec2 reflection_indices = instances.data[draw_call.instance_index].reflection_probes;
1426
- for (uint i = 0 ; i < sc_reflection_probes() ; i++ ) {
1443
+ for (uint i = 0 ; i < reflection_probe_count ; i++ ) {
1427
1444
uint reflection_index = (i > 3 ) ? ((reflection_indices.y >> ((i - 4 ) * 8 )) & 0xFF) : ((reflection_indices.x >> (i * 8 )) & 0xFF);
1445
+ if (reflection_index == 0xFF) {
1446
+ break ;
1447
+ }
1428
1448
1429
1449
if (reflection_accum.a >= 1.0 && ambient_accum.a >= 1.0 ) {
1430
1450
break ;
@@ -1519,7 +1539,8 @@ void main() {
1519
1539
direct_specular_light += specular_light_interp.rgb * f0;
1520
1540
#endif
1521
1541
1522
- if (sc_directional_lights() > 0 ) {
1542
+ uint directional_lights_count = sc_directional_lights(scene_data.directional_light_count);
1543
+ if (directional_lights_count > 0 ) {
1523
1544
#ifndef SHADOWS_DISABLED
1524
1545
// Do shadow and lighting in two passes to reduce register pressure
1525
1546
uint shadow0 = 0 ;
@@ -1554,7 +1575,7 @@ void main() {
1554
1575
// Only process the first light's shadow for vertex lighting.
1555
1576
for (uint i = 0 ; i < 1 ; i++ ) {
1556
1577
#else
1557
- for (uint i = 0 ; i < sc_directional_lights() ; i++ ) {
1578
+ for (uint i = 0 ; i < directional_lights_count ; i++ ) {
1558
1579
#endif
1559
1580
if (! bool (directional_lights.data[i].mask & instances.data[draw_call.instance_index].layer_mask)) {
1560
1581
continue ; // not masked
@@ -1696,7 +1717,8 @@ void main() {
1696
1717
#endif // SHADOWS_DISABLED
1697
1718
1698
1719
#ifndef USE_VERTEX_LIGHTING
1699
- for (uint i = 0 ; i < sc_directional_lights(); i++ ) {
1720
+ uint directional_lights_count = sc_directional_lights(scene_data.directional_light_count);
1721
+ for (uint i = 0 ; i < directional_lights_count; i++ ) {
1700
1722
if (! bool (directional_lights.data[i].mask & instances.data[draw_call.instance_index].layer_mask)) {
1701
1723
continue ; // not masked
1702
1724
}
@@ -1767,9 +1789,14 @@ void main() {
1767
1789
} // directional light
1768
1790
1769
1791
#ifndef USE_VERTEX_LIGHTING
1792
+ uint omni_light_count = sc_omni_lights(8 );
1770
1793
uvec2 omni_indices = instances.data[draw_call.instance_index].omni_lights;
1771
- for (uint i = 0 ; i < sc_omni_lights() ; i++ ) {
1794
+ for (uint i = 0 ; i < omni_light_count ; i++ ) {
1772
1795
uint light_index = (i > 3 ) ? ((omni_indices.y >> ((i - 4 ) * 8 )) & 0xFF) : ((omni_indices.x >> (i * 8 )) & 0xFF);
1796
+ if (i > 0 && light_index == 0xFF) {
1797
+ break ;
1798
+ }
1799
+
1773
1800
light_process_omni(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, scene_data.taa_frame_count, albedo, alpha, screen_uv, vec3 (1.0 ),
1774
1801
#ifdef LIGHT_BACKLIGHT_USED
1775
1802
backlight,
@@ -1795,9 +1822,14 @@ void main() {
1795
1822
diffuse_light, direct_specular_light);
1796
1823
}
1797
1824
1825
+ uint spot_light_count = sc_spot_lights(8 );
1798
1826
uvec2 spot_indices = instances.data[draw_call.instance_index].spot_lights;
1799
- for (uint i = 0 ; i < sc_spot_lights() ; i++ ) {
1827
+ for (uint i = 0 ; i < spot_light_count ; i++ ) {
1800
1828
uint light_index = (i > 3 ) ? ((spot_indices.y >> ((i - 4 ) * 8 )) & 0xFF) : ((spot_indices.x >> (i * 8 )) & 0xFF);
1829
+ if (i > 0 && light_index == 0xFF) {
1830
+ break ;
1831
+ }
1832
+
1801
1833
light_process_spot(light_index, vertex, view, normal, vertex_ddx, vertex_ddy, f0, orms, scene_data.taa_frame_count, albedo, alpha, screen_uv, vec3 (1.0 ),
1802
1834
#ifdef LIGHT_BACKLIGHT_USED
1803
1835
backlight,
0 commit comments