@@ -290,19 +290,19 @@ struct DirectionalLightData {
290290 mediump float energy;
291291 mediump vec3 color;
292292 mediump float size;
293- lowp uint unused;
294- lowp uint bake_mode;
293+ lowp uint enabled_bake_mode;
295294 mediump float shadow_opacity;
296295 mediump float specular;
296+ highp uint mask;
297297};
298298
299299layout (std140) uniform DirectionalLights { // ubo:7
300300 DirectionalLightData directional_lights[MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS];
301301};
302302
303- #define LIGHT_BAKE_DISABLED 0u
304- #define LIGHT_BAKE_STATIC 1u
305- #define LIGHT_BAKE_DYNAMIC 2u
303+ #define DIRECTIONAL_LIGHT_ENABLED uint ( 1 << 0 )
304+ #define DIRECTIONAL_LIGHT_BAKE_STATIC uint ( 1 << 1 )
305+ #define DIRECTIONAL_LIGHT_BAKE_DYNAMIC uint ( 1 << 2 )
306306#endif // !DISABLE_LIGHT_DIRECTIONAL
307307
308308// Omni and spot light data.
@@ -465,6 +465,7 @@ uniform highp vec3 compressed_aabb_position;
465465uniform highp vec3 compressed_aabb_size;
466466uniform highp vec4 uv_scale;
467467uniform highp uint instance_offset;
468+ uniform highp uint layer_mask;
468469
469470#if defined(RENDER_MOTION_VECTORS)
470471uniform highp mat4 prev_world_transform;
@@ -814,8 +815,11 @@ void vertex_shader(vec4 vertex_angle_attrib_input,
814815#ifdef BASE_PASS
815816#ifndef DISABLE_LIGHT_DIRECTIONAL
816817 for (uint i = uint (0 ); i < scene_data_input.directional_light_count; i++ ) {
818+ if (! bool (directional_lights[i].mask & layer_mask)) {
819+ continue ;
820+ }
817821#if defined(USE_LIGHTMAP) && ! defined(DISABLE_LIGHTMAP)
818- if (directional_lights[i].bake_mode == LIGHT_BAKE_STATIC ) {
822+ if (bool ( directional_lights[i].enabled_bake_mode & DIRECTIONAL_LIGHT_BAKE_STATIC) ) {
819823 continue ;
820824 }
821825#endif
@@ -846,9 +850,11 @@ void vertex_shader(vec4 vertex_angle_attrib_input,
846850 additive_specular_light_interp = vec3 (0.0 );
847851#if ! defined(ADDITIVE_OMNI) && ! defined(ADDITIVE_SPOT)
848852
849- light_compute(normal_interp, normalize (directional_lights[directional_shadow_index].direction), normalize (view), directional_lights[directional_shadow_index].color * directional_lights[directional_shadow_index].energy, true, roughness,
850- additive_diffuse_light_interp.rgb,
851- additive_specular_light_interp.rgb);
853+ if (bool (directional_lights[directional_shadow_index].mask & layer_mask)) {
854+ light_compute(normal_interp, normalize (directional_lights[directional_shadow_index].direction), normalize (view), directional_lights[directional_shadow_index].color * directional_lights[directional_shadow_index].energy, true, roughness,
855+ additive_diffuse_light_interp.rgb,
856+ additive_specular_light_interp.rgb);
857+ }
852858#endif // !defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT)
853859
854860#ifdef ADDITIVE_OMNI
@@ -1187,11 +1193,12 @@ multiview_data_block;
11871193
11881194uniform highp mat4 world_transform;
11891195uniform highp uint instance_offset;
1196+ uniform highp uint layer_mask;
11901197uniform highp uint model_flags;
11911198
1192- #define LIGHT_BAKE_DISABLED 0u
1193- #define LIGHT_BAKE_STATIC 1u
1194- #define LIGHT_BAKE_DYNAMIC 2u
1199+ #define DIRECTIONAL_LIGHT_ENABLED uint ( 1 << 0 )
1200+ #define DIRECTIONAL_LIGHT_BAKE_STATIC uint ( 1 << 1 )
1201+ #define DIRECTIONAL_LIGHT_BAKE_DYNAMIC uint ( 1 << 2 )
11951202
11961203#ifndef MODE_RENDER_DEPTH
11971204#ifdef USE_VERTEX_LIGHTING
@@ -1212,10 +1219,10 @@ struct DirectionalLightData {
12121219 mediump float energy;
12131220 mediump vec3 color;
12141221 mediump float size;
1215- lowp uint unused;
1216- lowp uint bake_mode;
1222+ lowp uint enabled_bake_mode;
12171223 mediump float shadow_opacity;
12181224 mediump float specular;
1225+ highp uint mask;
12191226};
12201227
12211228layout (std140) uniform DirectionalLights { // ubo:7
@@ -2369,8 +2376,11 @@ void main() {
23692376
23702377#ifndef DISABLE_LIGHT_DIRECTIONAL
23712378 for (uint i = uint (0 ); i < scene_data_block.data.directional_light_count; i++ ) {
2379+ if (! bool (directional_lights[i].mask & layer_mask)) {
2380+ continue ;
2381+ }
23722382#if defined(USE_LIGHTMAP) && ! defined(DISABLE_LIGHTMAP)
2373- if (directional_lights[i].bake_mode == LIGHT_BAKE_STATIC ) {
2383+ if (bool ( directional_lights[i].enabled_bake_mode & DIRECTIONAL_LIGHT_BAKE_STATIC) ) {
23742384 continue ;
23752385 }
23762386#endif
@@ -2688,26 +2698,30 @@ void main() {
26882698#endif // SHADOWS_DISABLED
26892699
26902700#ifndef USE_VERTEX_LIGHTING
2691- light_compute(normal, normalize (directional_lights[directional_shadow_index].direction), normalize (view), directional_lights[directional_shadow_index].size, directional_lights[directional_shadow_index].color * directional_lights[directional_shadow_index].energy, true, directional_shadow, f0, roughness, metallic, directional_lights[directional_shadow_index].specular, albedo, alpha, screen_uv,
2701+ if (bool (directional_lights[directional_shadow_index].mask & layer_mask)) {
2702+ light_compute(normal, normalize (directional_lights[directional_shadow_index].direction), normalize (view), directional_lights[directional_shadow_index].size, directional_lights[directional_shadow_index].color * directional_lights[directional_shadow_index].energy, true, directional_shadow, f0, roughness, metallic, directional_lights[directional_shadow_index].specular, albedo, alpha, screen_uv,
26922703#ifdef LIGHT_BACKLIGHT_USED
2693- backlight,
2704+ backlight,
26942705#endif
26952706#ifdef LIGHT_RIM_USED
2696- rim, rim_tint,
2707+ rim, rim_tint,
26972708#endif
26982709#ifdef LIGHT_CLEARCOAT_USED
2699- clearcoat, clearcoat_roughness, geo_normal,
2710+ clearcoat, clearcoat_roughness, geo_normal,
27002711#endif // LIGHT_CLEARCOAT_USED
27012712#ifdef LIGHT_ANISOTROPY_USED
2702- binormal,
2703- tangent, anisotropy,
2713+ binormal,
2714+ tangent, anisotropy,
27042715#endif
2705- diffuse_light,
2706- specular_light);
2707- #else
2708- // Just apply shadows to vertex lighting.
2709- diffuse_light *= directional_shadow;
2710- specular_light *= directional_shadow;
2716+ diffuse_light,
2717+ specular_light);
2718+ } else {
2719+ #endif // !USE_VERTEX_LIGHTING
2720+ // Just apply shadows to vertex lighting.
2721+ diffuse_light *= directional_shadow;
2722+ specular_light *= directional_shadow;
2723+ #ifndef USE_VERTEX_LIGHTING
2724+ }
27112725#endif // !USE_VERTEX_LIGHTING
27122726#endif // !defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT)
27132727
0 commit comments