diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index 17bdcbcad34..cd4c7dd82fb 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -1302,15 +1302,12 @@ void RasterizerSceneGLES3::_fill_render_list(RenderListType p_render_list, const int32_t shadow_id = light_storage->light_instance_get_shadow_id(light_instance); if (light_storage->light_has_shadow(light) && shadow_id >= 0) { - // Skip static lights when a lightmap is used. - if (!inst->lightmap_instance.is_valid() || light_storage->light_get_bake_mode(light) != RenderingServer::LIGHT_BAKE_STATIC) { - GeometryInstanceGLES3::LightPass pass; - pass.light_id = light_storage->light_instance_get_gl_id(light_instance); - pass.shadow_id = shadow_id; - pass.light_instance_rid = light_instance; - pass.is_omni = true; - inst->light_passes.push_back(pass); - } + GeometryInstanceGLES3::LightPass pass; + pass.light_id = light_storage->light_instance_get_gl_id(light_instance); + pass.shadow_id = shadow_id; + pass.light_instance_rid = light_instance; + pass.is_omni = true; + inst->light_passes.push_back(pass); } else { // Lights without shadow can all go in base pass. inst->omni_light_gl_cache.push_back((uint32_t)light_storage->light_instance_get_gl_id(light_instance)); @@ -1328,14 +1325,11 @@ void RasterizerSceneGLES3::_fill_render_list(RenderListType p_render_list, const int32_t shadow_id = light_storage->light_instance_get_shadow_id(light_instance); if (light_storage->light_has_shadow(light) && shadow_id >= 0) { - // Skip static lights when a lightmap is used. - if (!inst->lightmap_instance.is_valid() || light_storage->light_get_bake_mode(light) != RenderingServer::LIGHT_BAKE_STATIC) { - GeometryInstanceGLES3::LightPass pass; - pass.light_id = light_storage->light_instance_get_gl_id(light_instance); - pass.shadow_id = shadow_id; - pass.light_instance_rid = light_instance; - inst->light_passes.push_back(pass); - } + GeometryInstanceGLES3::LightPass pass; + pass.light_id = light_storage->light_instance_get_gl_id(light_instance); + pass.shadow_id = shadow_id; + pass.light_instance_rid = light_instance; + inst->light_passes.push_back(pass); } else { // Lights without shadow can all go in base pass. inst->spot_light_gl_cache.push_back((uint32_t)light_storage->light_instance_get_gl_id(light_instance)); diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl index 2022c8ee436..fd195fe7c43 100644 --- a/drivers/gles3/shaders/scene.glsl +++ b/drivers/gles3/shaders/scene.glsl @@ -275,6 +275,10 @@ struct DirectionalLightData { layout(std140) uniform DirectionalLights { // ubo:7 DirectionalLightData directional_lights[MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS]; }; + +#define LIGHT_BAKE_DISABLED 0u +#define LIGHT_BAKE_STATIC 1u +#define LIGHT_BAKE_DYNAMIC 2u #endif // !DISABLE_LIGHT_DIRECTIONAL // Omni and spot light data. @@ -723,6 +727,11 @@ void main() { #ifdef BASE_PASS #ifndef DISABLE_LIGHT_DIRECTIONAL for (uint i = uint(0); i < scene_data.directional_light_count; i++) { +#if defined(USE_LIGHTMAP) && !defined(DISABLE_LIGHTMAP) + if (directional_lights[i].bake_mode == LIGHT_BAKE_STATIC) { + continue; + } +#endif light_compute(normal_interp, normalize(directional_lights[i].direction), normalize(view), directional_lights[i].color * directional_lights[i].energy, true, roughness, diffuse_light_interp.rgb, specular_light_interp.rgb); @@ -2138,11 +2147,7 @@ void main() { if (i >= omni_light_count) { break; } -#if defined(USE_LIGHTMAP) && !defined(DISABLE_LIGHTMAP) - if (omni_lights[omni_light_indices[i]].bake_mode == LIGHT_BAKE_STATIC) { - continue; - } -#endif + light_process_omni(omni_light_indices[i], vertex, view, normal, f0, roughness, metallic, 1.0, albedo, alpha, screen_uv, #ifdef LIGHT_BACKLIGHT_USED backlight, @@ -2166,11 +2171,7 @@ void main() { if (i >= spot_light_count) { break; } -#if defined(USE_LIGHTMAP) && !defined(DISABLE_LIGHTMAP) - if (spot_lights[spot_light_indices[i]].bake_mode == LIGHT_BAKE_STATIC) { - continue; - } -#endif + light_process_spot(spot_light_indices[i], vertex, view, normal, f0, roughness, metallic, 1.0, albedo, alpha, screen_uv, #ifdef LIGHT_BACKLIGHT_USED backlight, diff --git a/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl b/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl index 52b3d5d1e38..5b4d746b528 100644 --- a/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl +++ b/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl @@ -2211,6 +2211,10 @@ void fragment_shader(in SceneData scene_data) { continue; //not masked } + if (directional_lights.data[i].bake_mode == LIGHT_BAKE_STATIC && bool(instances.data[instance_index].flags & INSTANCE_FLAGS_USE_LIGHTMAP)) { + continue; // Statically baked light and object uses lightmap, skip + } + #ifdef LIGHT_TRANSMITTANCE_USED float transmittance_z = transmittance_depth; #ifndef SHADOWS_DISABLED diff --git a/servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl b/servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl index 144b994a52c..dbca038d3a7 100644 --- a/servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl +++ b/servers/rendering/renderer_rd/shaders/forward_mobile/scene_forward_mobile.glsl @@ -1445,6 +1445,10 @@ void main() { continue; //not masked } + if (directional_lights.data[i].bake_mode == LIGHT_BAKE_STATIC && bool(instances.data[draw_call.instance_index].flags & INSTANCE_FLAGS_USE_LIGHTMAP)) { + continue; // Statically baked light and object uses lightmap, skip. + } + float shadow = 1.0; if (directional_lights.data[i].shadow_opacity > 0.001) { @@ -1560,6 +1564,10 @@ void main() { continue; //not masked } + if (directional_lights.data[i].bake_mode == LIGHT_BAKE_STATIC && bool(instances.data[draw_call.instance_index].flags & INSTANCE_FLAGS_USE_LIGHTMAP)) { + continue; // Statically baked light and object uses lightmap, skip. + } + // We're not doing light transmittence float shadow = 1.0; diff --git a/servers/rendering/renderer_rd/storage_rd/light_storage.cpp b/servers/rendering/renderer_rd/storage_rd/light_storage.cpp index 1d309a80063..a812c894b92 100644 --- a/servers/rendering/renderer_rd/storage_rd/light_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/light_storage.cpp @@ -676,12 +676,13 @@ void LightStorage::update_light_buffers(RenderDataRD *p_render_data, const Paged angular_diameter = 0.0; } + light_data.bake_mode = light->bake_mode; + if (light_data.shadow_opacity > 0.001) { RS::LightDirectionalShadowMode smode = light->directional_shadow_mode; light_data.soft_shadow_scale = light->param[RS::LIGHT_PARAM_SHADOW_BLUR]; light_data.softshadow_angle = angular_diameter; - light_data.bake_mode = light->bake_mode; if (angular_diameter <= 0.0) { light_data.soft_shadow_scale *= RendererSceneRenderRD::get_singleton()->directional_shadow_quality_radius_get(); // Only use quality radius for PCF diff --git a/servers/rendering/renderer_scene_cull.cpp b/servers/rendering/renderer_scene_cull.cpp index af17a355358..1fcbcb98533 100644 --- a/servers/rendering/renderer_scene_cull.cpp +++ b/servers/rendering/renderer_scene_cull.cpp @@ -3044,6 +3044,10 @@ void RendererSceneCull::_scene_cull(CullData &cull_data, InstanceCullResult &cul continue; } + if ((RSG::light_storage->light_get_bake_mode(E->base) == RS::LIGHT_BAKE_STATIC) && idata.instance->lightmap) { + continue; + } + instance_pair_buffer[idx++] = light->instance; if (idx == MAX_INSTANCE_PAIRS) { break;