You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-05 12:10:55 +00:00
Merge pull request #107384 from Kaleb-Reid/compat-directional-cull-mask
Implement DirectionalLight3D cull masks in Compatibility
This commit is contained in:
@@ -1715,6 +1715,8 @@ void RasterizerSceneGLES3::_setup_lights(const RenderDataGLES3 *p_render_data, b
|
|||||||
|
|
||||||
light_data.specular = light_storage->light_get_param(base, RS::LIGHT_PARAM_SPECULAR);
|
light_data.specular = light_storage->light_get_param(base, RS::LIGHT_PARAM_SPECULAR);
|
||||||
|
|
||||||
|
light_data.mask = light_storage->light_get_cull_mask(base);
|
||||||
|
|
||||||
light_data.shadow_opacity = (p_using_shadows && light_storage->light_has_shadow(base))
|
light_data.shadow_opacity = (p_using_shadows && light_storage->light_has_shadow(base))
|
||||||
? light_storage->light_get_param(base, RS::LIGHT_PARAM_SHADOW_OPACITY)
|
? light_storage->light_get_param(base, RS::LIGHT_PARAM_SHADOW_OPACITY)
|
||||||
: 0.0;
|
: 0.0;
|
||||||
@@ -3421,6 +3423,10 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
|
|||||||
// Render directional lights.
|
// Render directional lights.
|
||||||
|
|
||||||
uint32_t shadow_id = MAX_DIRECTIONAL_LIGHTS - 1 - (pass - int32_t(inst->light_passes.size()));
|
uint32_t shadow_id = MAX_DIRECTIONAL_LIGHTS - 1 - (pass - int32_t(inst->light_passes.size()));
|
||||||
|
if (!(scene_state.directional_lights[shadow_id].mask & inst->layer_mask)) {
|
||||||
|
// Disable additive lighting when masks are not overlapping.
|
||||||
|
spec_constants &= ~SceneShaderGLES3::USE_ADDITIVE_LIGHTING;
|
||||||
|
}
|
||||||
if (pass == 0 && inst->lightmap_instance.is_valid() && scene_state.directional_lights[shadow_id].bake_mode == RenderingServer::LIGHT_BAKE_STATIC) {
|
if (pass == 0 && inst->lightmap_instance.is_valid() && scene_state.directional_lights[shadow_id].bake_mode == RenderingServer::LIGHT_BAKE_STATIC) {
|
||||||
// Disable additive lighting with a static light and a lightmap.
|
// Disable additive lighting with a static light and a lightmap.
|
||||||
spec_constants &= ~SceneShaderGLES3::USE_ADDITIVE_LIGHTING;
|
spec_constants &= ~SceneShaderGLES3::USE_ADDITIVE_LIGHTING;
|
||||||
@@ -3667,6 +3673,8 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
|
|||||||
|
|
||||||
if (p_pass_mode == PASS_MODE_MATERIAL) {
|
if (p_pass_mode == PASS_MODE_MATERIAL) {
|
||||||
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::UV_OFFSET, p_params->uv_offset, shader->version, instance_variant, spec_constants);
|
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::UV_OFFSET, p_params->uv_offset, shader->version, instance_variant, spec_constants);
|
||||||
|
} else if (p_pass_mode == PASS_MODE_COLOR || p_pass_mode == PASS_MODE_COLOR_TRANSPARENT) {
|
||||||
|
material_storage->shaders.scene_shader.version_set_uniform(SceneShaderGLES3::LAYER_MASK, inst->layer_mask, shader->version, instance_variant, spec_constants);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Can be index count or vertex count
|
// Can be index count or vertex count
|
||||||
|
|||||||
@@ -203,10 +203,11 @@ private:
|
|||||||
float color[3];
|
float color[3];
|
||||||
float size;
|
float size;
|
||||||
|
|
||||||
uint32_t enabled; // For use by SkyShaders
|
uint32_t enabled : 1; // For use by SkyShaders
|
||||||
uint32_t bake_mode;
|
uint32_t bake_mode : 2;
|
||||||
float shadow_opacity;
|
float shadow_opacity;
|
||||||
float specular;
|
float specular;
|
||||||
|
uint32_t mask;
|
||||||
};
|
};
|
||||||
static_assert(sizeof(DirectionalLightData) % 16 == 0, "DirectionalLightData size must be a multiple of 16 bytes");
|
static_assert(sizeof(DirectionalLightData) % 16 == 0, "DirectionalLightData size must be a multiple of 16 bytes");
|
||||||
|
|
||||||
|
|||||||
@@ -291,19 +291,19 @@ struct DirectionalLightData {
|
|||||||
mediump float energy;
|
mediump float energy;
|
||||||
mediump vec3 color;
|
mediump vec3 color;
|
||||||
mediump float size;
|
mediump float size;
|
||||||
lowp uint unused;
|
lowp uint enabled_bake_mode;
|
||||||
lowp uint bake_mode;
|
|
||||||
mediump float shadow_opacity;
|
mediump float shadow_opacity;
|
||||||
mediump float specular;
|
mediump float specular;
|
||||||
|
highp uint mask;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout(std140) uniform DirectionalLights { // ubo:7
|
layout(std140) uniform DirectionalLights { // ubo:7
|
||||||
DirectionalLightData directional_lights[MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS];
|
DirectionalLightData directional_lights[MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS];
|
||||||
};
|
};
|
||||||
|
|
||||||
#define LIGHT_BAKE_DISABLED 0u
|
#define DIRECTIONAL_LIGHT_ENABLED uint(1 << 0)
|
||||||
#define LIGHT_BAKE_STATIC 1u
|
#define DIRECTIONAL_LIGHT_BAKE_STATIC uint(1 << 1)
|
||||||
#define LIGHT_BAKE_DYNAMIC 2u
|
#define DIRECTIONAL_LIGHT_BAKE_DYNAMIC uint(1 << 2)
|
||||||
#endif // !DISABLE_LIGHT_DIRECTIONAL
|
#endif // !DISABLE_LIGHT_DIRECTIONAL
|
||||||
|
|
||||||
// Omni and spot light data.
|
// Omni and spot light data.
|
||||||
@@ -466,6 +466,7 @@ uniform highp vec3 compressed_aabb_position;
|
|||||||
uniform highp vec3 compressed_aabb_size;
|
uniform highp vec3 compressed_aabb_size;
|
||||||
uniform highp vec4 uv_scale;
|
uniform highp vec4 uv_scale;
|
||||||
uniform highp uint instance_offset;
|
uniform highp uint instance_offset;
|
||||||
|
uniform highp uint layer_mask;
|
||||||
|
|
||||||
#if defined(RENDER_MOTION_VECTORS)
|
#if defined(RENDER_MOTION_VECTORS)
|
||||||
uniform highp mat4 prev_world_transform;
|
uniform highp mat4 prev_world_transform;
|
||||||
@@ -815,8 +816,11 @@ void vertex_shader(vec4 vertex_angle_attrib_input,
|
|||||||
#ifdef BASE_PASS
|
#ifdef BASE_PASS
|
||||||
#ifndef DISABLE_LIGHT_DIRECTIONAL
|
#ifndef DISABLE_LIGHT_DIRECTIONAL
|
||||||
for (uint i = uint(0); i < scene_data_input.directional_light_count; i++) {
|
for (uint i = uint(0); i < scene_data_input.directional_light_count; i++) {
|
||||||
|
if (!bool(directional_lights[i].mask & layer_mask)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
#if defined(USE_LIGHTMAP) && !defined(DISABLE_LIGHTMAP)
|
#if defined(USE_LIGHTMAP) && !defined(DISABLE_LIGHTMAP)
|
||||||
if (directional_lights[i].bake_mode == LIGHT_BAKE_STATIC) {
|
if (bool(directional_lights[i].enabled_bake_mode & DIRECTIONAL_LIGHT_BAKE_STATIC)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -847,9 +851,11 @@ void vertex_shader(vec4 vertex_angle_attrib_input,
|
|||||||
additive_specular_light_interp = vec3(0.0);
|
additive_specular_light_interp = vec3(0.0);
|
||||||
#if !defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT)
|
#if !defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT)
|
||||||
|
|
||||||
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,
|
if (bool(directional_lights[directional_shadow_index].mask & layer_mask)) {
|
||||||
additive_diffuse_light_interp.rgb,
|
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,
|
||||||
additive_specular_light_interp.rgb);
|
additive_diffuse_light_interp.rgb,
|
||||||
|
additive_specular_light_interp.rgb);
|
||||||
|
}
|
||||||
#endif // !defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT)
|
#endif // !defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT)
|
||||||
|
|
||||||
#ifdef ADDITIVE_OMNI
|
#ifdef ADDITIVE_OMNI
|
||||||
@@ -1188,11 +1194,12 @@ multiview_data_block;
|
|||||||
|
|
||||||
uniform highp mat4 world_transform;
|
uniform highp mat4 world_transform;
|
||||||
uniform highp uint instance_offset;
|
uniform highp uint instance_offset;
|
||||||
|
uniform highp uint layer_mask;
|
||||||
uniform highp uint model_flags;
|
uniform highp uint model_flags;
|
||||||
|
|
||||||
#define LIGHT_BAKE_DISABLED 0u
|
#define DIRECTIONAL_LIGHT_ENABLED uint(1 << 0)
|
||||||
#define LIGHT_BAKE_STATIC 1u
|
#define DIRECTIONAL_LIGHT_BAKE_STATIC uint(1 << 1)
|
||||||
#define LIGHT_BAKE_DYNAMIC 2u
|
#define DIRECTIONAL_LIGHT_BAKE_DYNAMIC uint(1 << 2)
|
||||||
|
|
||||||
#ifndef MODE_RENDER_DEPTH
|
#ifndef MODE_RENDER_DEPTH
|
||||||
#ifdef USE_VERTEX_LIGHTING
|
#ifdef USE_VERTEX_LIGHTING
|
||||||
@@ -1213,10 +1220,10 @@ struct DirectionalLightData {
|
|||||||
mediump float energy;
|
mediump float energy;
|
||||||
mediump vec3 color;
|
mediump vec3 color;
|
||||||
mediump float size;
|
mediump float size;
|
||||||
lowp uint unused;
|
lowp uint enabled_bake_mode;
|
||||||
lowp uint bake_mode;
|
|
||||||
mediump float shadow_opacity;
|
mediump float shadow_opacity;
|
||||||
mediump float specular;
|
mediump float specular;
|
||||||
|
highp uint mask;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout(std140) uniform DirectionalLights { // ubo:7
|
layout(std140) uniform DirectionalLights { // ubo:7
|
||||||
@@ -2373,8 +2380,11 @@ void main() {
|
|||||||
|
|
||||||
#ifndef DISABLE_LIGHT_DIRECTIONAL
|
#ifndef DISABLE_LIGHT_DIRECTIONAL
|
||||||
for (uint i = uint(0); i < scene_data_block.data.directional_light_count; i++) {
|
for (uint i = uint(0); i < scene_data_block.data.directional_light_count; i++) {
|
||||||
|
if (!bool(directional_lights[i].mask & layer_mask)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
#if defined(USE_LIGHTMAP) && !defined(DISABLE_LIGHTMAP)
|
#if defined(USE_LIGHTMAP) && !defined(DISABLE_LIGHTMAP)
|
||||||
if (directional_lights[i].bake_mode == LIGHT_BAKE_STATIC) {
|
if (bool(directional_lights[i].enabled_bake_mode & DIRECTIONAL_LIGHT_BAKE_STATIC)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -2692,26 +2702,30 @@ void main() {
|
|||||||
#endif // SHADOWS_DISABLED
|
#endif // SHADOWS_DISABLED
|
||||||
|
|
||||||
#ifndef USE_VERTEX_LIGHTING
|
#ifndef USE_VERTEX_LIGHTING
|
||||||
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,
|
if (bool(directional_lights[directional_shadow_index].mask & layer_mask)) {
|
||||||
|
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,
|
||||||
#ifdef LIGHT_BACKLIGHT_USED
|
#ifdef LIGHT_BACKLIGHT_USED
|
||||||
backlight,
|
backlight,
|
||||||
#endif
|
#endif
|
||||||
#ifdef LIGHT_RIM_USED
|
#ifdef LIGHT_RIM_USED
|
||||||
rim, rim_tint,
|
rim, rim_tint,
|
||||||
#endif
|
#endif
|
||||||
#ifdef LIGHT_CLEARCOAT_USED
|
#ifdef LIGHT_CLEARCOAT_USED
|
||||||
clearcoat, clearcoat_roughness, geo_normal,
|
clearcoat, clearcoat_roughness, geo_normal,
|
||||||
#endif // LIGHT_CLEARCOAT_USED
|
#endif // LIGHT_CLEARCOAT_USED
|
||||||
#ifdef LIGHT_ANISOTROPY_USED
|
#ifdef LIGHT_ANISOTROPY_USED
|
||||||
binormal,
|
binormal,
|
||||||
tangent, anisotropy,
|
tangent, anisotropy,
|
||||||
#endif
|
#endif
|
||||||
diffuse_light,
|
diffuse_light,
|
||||||
specular_light);
|
specular_light);
|
||||||
#else
|
} else {
|
||||||
// Just apply shadows to vertex lighting.
|
#endif // !USE_VERTEX_LIGHTING
|
||||||
diffuse_light *= directional_shadow;
|
// Just apply shadows to vertex lighting.
|
||||||
specular_light *= directional_shadow;
|
diffuse_light *= directional_shadow;
|
||||||
|
specular_light *= directional_shadow;
|
||||||
|
#ifndef USE_VERTEX_LIGHTING
|
||||||
|
}
|
||||||
#endif // !USE_VERTEX_LIGHTING
|
#endif // !USE_VERTEX_LIGHTING
|
||||||
#endif // !defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT)
|
#endif // !defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT)
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,10 @@ layout(std140) uniform GlobalShaderUniformData { //ubo:1
|
|||||||
struct DirectionalLightData {
|
struct DirectionalLightData {
|
||||||
vec4 direction_energy;
|
vec4 direction_energy;
|
||||||
vec4 color_size;
|
vec4 color_size;
|
||||||
bool enabled;
|
uint enabled_bake_mode;
|
||||||
|
float shadow_opacity;
|
||||||
|
float specular;
|
||||||
|
uint mask;
|
||||||
};
|
};
|
||||||
|
|
||||||
layout(std140) uniform DirectionalLights { //ubo:4
|
layout(std140) uniform DirectionalLights { //ubo:4
|
||||||
@@ -67,6 +70,8 @@ layout(std140) uniform DirectionalLights { //ubo:4
|
|||||||
}
|
}
|
||||||
directional_lights;
|
directional_lights;
|
||||||
|
|
||||||
|
#define DIRECTIONAL_LIGHT_ENABLED uint(1 << 0)
|
||||||
|
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
|
|
||||||
#ifdef MATERIAL_UNIFORMS_USED
|
#ifdef MATERIAL_UNIFORMS_USED
|
||||||
|
|||||||
@@ -1513,22 +1513,22 @@ MaterialStorage::MaterialStorage() {
|
|||||||
actions.renames["QUARTER_RES_COLOR"] = "quarter_res_color";
|
actions.renames["QUARTER_RES_COLOR"] = "quarter_res_color";
|
||||||
actions.renames["RADIANCE"] = "radiance";
|
actions.renames["RADIANCE"] = "radiance";
|
||||||
actions.renames["FOG"] = "custom_fog";
|
actions.renames["FOG"] = "custom_fog";
|
||||||
actions.renames["LIGHT0_ENABLED"] = "directional_lights.data[0].enabled";
|
actions.renames["LIGHT0_ENABLED"] = "bool(directional_lights.data[0].enabled_bake_mode & DIRECTIONAL_LIGHT_ENABLED)";
|
||||||
actions.renames["LIGHT0_DIRECTION"] = "directional_lights.data[0].direction_energy.xyz";
|
actions.renames["LIGHT0_DIRECTION"] = "directional_lights.data[0].direction_energy.xyz";
|
||||||
actions.renames["LIGHT0_ENERGY"] = "directional_lights.data[0].direction_energy.w";
|
actions.renames["LIGHT0_ENERGY"] = "directional_lights.data[0].direction_energy.w";
|
||||||
actions.renames["LIGHT0_COLOR"] = "directional_lights.data[0].color_size.xyz";
|
actions.renames["LIGHT0_COLOR"] = "directional_lights.data[0].color_size.xyz";
|
||||||
actions.renames["LIGHT0_SIZE"] = "directional_lights.data[0].color_size.w";
|
actions.renames["LIGHT0_SIZE"] = "directional_lights.data[0].color_size.w";
|
||||||
actions.renames["LIGHT1_ENABLED"] = "directional_lights.data[1].enabled";
|
actions.renames["LIGHT1_ENABLED"] = "bool(directional_lights.data[1].enabled_bake_mode & DIRECTIONAL_LIGHT_ENABLED)";
|
||||||
actions.renames["LIGHT1_DIRECTION"] = "directional_lights.data[1].direction_energy.xyz";
|
actions.renames["LIGHT1_DIRECTION"] = "directional_lights.data[1].direction_energy.xyz";
|
||||||
actions.renames["LIGHT1_ENERGY"] = "directional_lights.data[1].direction_energy.w";
|
actions.renames["LIGHT1_ENERGY"] = "directional_lights.data[1].direction_energy.w";
|
||||||
actions.renames["LIGHT1_COLOR"] = "directional_lights.data[1].color_size.xyz";
|
actions.renames["LIGHT1_COLOR"] = "directional_lights.data[1].color_size.xyz";
|
||||||
actions.renames["LIGHT1_SIZE"] = "directional_lights.data[1].color_size.w";
|
actions.renames["LIGHT1_SIZE"] = "directional_lights.data[1].color_size.w";
|
||||||
actions.renames["LIGHT2_ENABLED"] = "directional_lights.data[2].enabled";
|
actions.renames["LIGHT2_ENABLED"] = "bool(directional_lights.data[2].enabled_bake_mode & DIRECTIONAL_LIGHT_ENABLED)";
|
||||||
actions.renames["LIGHT2_DIRECTION"] = "directional_lights.data[2].direction_energy.xyz";
|
actions.renames["LIGHT2_DIRECTION"] = "directional_lights.data[2].direction_energy.xyz";
|
||||||
actions.renames["LIGHT2_ENERGY"] = "directional_lights.data[2].direction_energy.w";
|
actions.renames["LIGHT2_ENERGY"] = "directional_lights.data[2].direction_energy.w";
|
||||||
actions.renames["LIGHT2_COLOR"] = "directional_lights.data[2].color_size.xyz";
|
actions.renames["LIGHT2_COLOR"] = "directional_lights.data[2].color_size.xyz";
|
||||||
actions.renames["LIGHT2_SIZE"] = "directional_lights.data[2].color_size.w";
|
actions.renames["LIGHT2_SIZE"] = "directional_lights.data[2].color_size.w";
|
||||||
actions.renames["LIGHT3_ENABLED"] = "directional_lights.data[3].enabled";
|
actions.renames["LIGHT3_ENABLED"] = "bool(directional_lights.data[3].enabled_bake_mode & DIRECTIONAL_LIGHT_ENABLED)";
|
||||||
actions.renames["LIGHT3_DIRECTION"] = "directional_lights.data[3].direction_energy.xyz";
|
actions.renames["LIGHT3_DIRECTION"] = "directional_lights.data[3].direction_energy.xyz";
|
||||||
actions.renames["LIGHT3_ENERGY"] = "directional_lights.data[3].direction_energy.w";
|
actions.renames["LIGHT3_ENERGY"] = "directional_lights.data[3].direction_energy.w";
|
||||||
actions.renames["LIGHT3_COLOR"] = "directional_lights.data[3].color_size.xyz";
|
actions.renames["LIGHT3_COLOR"] = "directional_lights.data[3].color_size.xyz";
|
||||||
|
|||||||
Reference in New Issue
Block a user