@@ -291,19 +291,19 @@ struct DirectionalLightData {
291291 mediump float energy;
292292 mediump vec3 color;
293293 mediump float size;
294- lowp uint unused;
295- lowp uint bake_mode;
294+ lowp uint enabled_bake_mode;
296295 mediump float shadow_opacity;
297296 mediump float specular;
297+ highp uint mask;
298298};
299299
300300layout (std140) uniform DirectionalLights { // ubo:7
301301 DirectionalLightData directional_lights[MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS];
302302};
303303
304- #define LIGHT_BAKE_DISABLED 0u
305- #define LIGHT_BAKE_STATIC 1u
306- #define LIGHT_BAKE_DYNAMIC 2u
304+ #define DIRECTIONAL_LIGHT_ENABLED uint ( 1 << 0 )
305+ #define DIRECTIONAL_LIGHT_BAKE_STATIC uint ( 1 << 1 )
306+ #define DIRECTIONAL_LIGHT_BAKE_DYNAMIC uint ( 1 << 2 )
307307#endif // !DISABLE_LIGHT_DIRECTIONAL
308308
309309// Omni and spot light data.
@@ -466,6 +466,7 @@ uniform highp vec3 compressed_aabb_position;
466466uniform highp vec3 compressed_aabb_size;
467467uniform highp vec4 uv_scale;
468468uniform highp uint instance_offset;
469+ uniform highp uint layer_mask;
469470
470471#if defined(RENDER_MOTION_VECTORS)
471472uniform highp mat4 prev_world_transform;
@@ -815,8 +816,11 @@ void vertex_shader(vec4 vertex_angle_attrib_input,
815816#ifdef BASE_PASS
816817#ifndef DISABLE_LIGHT_DIRECTIONAL
817818 for (uint i = uint (0 ); i < scene_data_input.directional_light_count; i++ ) {
819+ if (! bool (directional_lights[i].mask & layer_mask)) {
820+ continue ;
821+ }
818822#if defined(USE_LIGHTMAP) && ! defined(DISABLE_LIGHTMAP)
819- if (directional_lights[i].bake_mode == LIGHT_BAKE_STATIC ) {
823+ if (bool ( directional_lights[i].enabled_bake_mode & DIRECTIONAL_LIGHT_BAKE_STATIC) ) {
820824 continue ;
821825 }
822826#endif
@@ -847,9 +851,11 @@ void vertex_shader(vec4 vertex_angle_attrib_input,
847851 additive_specular_light_interp = vec3 (0.0 );
848852#if ! defined(ADDITIVE_OMNI) && ! defined(ADDITIVE_SPOT)
849853
850- 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,
851- additive_diffuse_light_interp.rgb,
852- additive_specular_light_interp.rgb);
854+ if (bool (directional_lights[directional_shadow_index].mask & layer_mask)) {
855+ 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,
856+ additive_diffuse_light_interp.rgb,
857+ additive_specular_light_interp.rgb);
858+ }
853859#endif // !defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT)
854860
855861#ifdef ADDITIVE_OMNI
@@ -1188,11 +1194,12 @@ multiview_data_block;
11881194
11891195uniform highp mat4 world_transform;
11901196uniform highp uint instance_offset;
1197+ uniform highp uint layer_mask;
11911198uniform highp uint model_flags;
11921199
1193- #define LIGHT_BAKE_DISABLED 0u
1194- #define LIGHT_BAKE_STATIC 1u
1195- #define LIGHT_BAKE_DYNAMIC 2u
1200+ #define DIRECTIONAL_LIGHT_ENABLED uint ( 1 << 0 )
1201+ #define DIRECTIONAL_LIGHT_BAKE_STATIC uint ( 1 << 1 )
1202+ #define DIRECTIONAL_LIGHT_BAKE_DYNAMIC uint ( 1 << 2 )
11961203
11971204#ifndef MODE_RENDER_DEPTH
11981205#ifdef USE_VERTEX_LIGHTING
@@ -1213,10 +1220,10 @@ struct DirectionalLightData {
12131220 mediump float energy;
12141221 mediump vec3 color;
12151222 mediump float size;
1216- lowp uint unused;
1217- lowp uint bake_mode;
1223+ lowp uint enabled_bake_mode;
12181224 mediump float shadow_opacity;
12191225 mediump float specular;
1226+ highp uint mask;
12201227};
12211228
12221229layout (std140) uniform DirectionalLights { // ubo:7
@@ -2373,8 +2380,11 @@ void main() {
23732380
23742381#ifndef DISABLE_LIGHT_DIRECTIONAL
23752382 for (uint i = uint (0 ); i < scene_data_block.data.directional_light_count; i++ ) {
2383+ if (! bool (directional_lights[i].mask & layer_mask)) {
2384+ continue ;
2385+ }
23762386#if defined(USE_LIGHTMAP) && ! defined(DISABLE_LIGHTMAP)
2377- if (directional_lights[i].bake_mode == LIGHT_BAKE_STATIC ) {
2387+ if (bool ( directional_lights[i].enabled_bake_mode & DIRECTIONAL_LIGHT_BAKE_STATIC) ) {
23782388 continue ;
23792389 }
23802390#endif
@@ -2692,26 +2702,30 @@ void main() {
26922702#endif // SHADOWS_DISABLED
26932703
26942704#ifndef USE_VERTEX_LIGHTING
2695- 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,
2705+ if (bool (directional_lights[directional_shadow_index].mask & layer_mask)) {
2706+ 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,
26962707#ifdef LIGHT_BACKLIGHT_USED
2697- backlight,
2708+ backlight,
26982709#endif
26992710#ifdef LIGHT_RIM_USED
2700- rim, rim_tint,
2711+ rim, rim_tint,
27012712#endif
27022713#ifdef LIGHT_CLEARCOAT_USED
2703- clearcoat, clearcoat_roughness, geo_normal,
2714+ clearcoat, clearcoat_roughness, geo_normal,
27042715#endif // LIGHT_CLEARCOAT_USED
27052716#ifdef LIGHT_ANISOTROPY_USED
2706- binormal,
2707- tangent, anisotropy,
2717+ binormal,
2718+ tangent, anisotropy,
27082719#endif
2709- diffuse_light,
2710- specular_light);
2711- #else
2712- // Just apply shadows to vertex lighting.
2713- diffuse_light *= directional_shadow;
2714- specular_light *= directional_shadow;
2720+ diffuse_light,
2721+ specular_light);
2722+ } else {
2723+ #endif // !USE_VERTEX_LIGHTING
2724+ // Just apply shadows to vertex lighting.
2725+ diffuse_light *= directional_shadow;
2726+ specular_light *= directional_shadow;
2727+ #ifndef USE_VERTEX_LIGHTING
2728+ }
27152729#endif // !USE_VERTEX_LIGHTING
27162730#endif // !defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT)
27172731
0 commit comments