From 5965fbd9fa7c1634b375c03efa1aba6ba5dce34d Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 16 Nov 2020 22:11:22 -0500 Subject: [PATCH] Make lights_per_object configurable --- doc/classes/ProjectSettings.xml | 3 +++ drivers/gles3/rasterizer_scene_gles3.cpp | 11 ++++++----- drivers/gles3/rasterizer_scene_gles3.h | 4 +++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/doc/classes/ProjectSettings.xml b/doc/classes/ProjectSettings.xml index af935b1d61b..9467e4c6251 100644 --- a/doc/classes/ProjectSettings.xml +++ b/doc/classes/ProjectSettings.xml @@ -1073,6 +1073,9 @@ Max number of reflection probes renderable in a frame. If more than this number are used, they will be ignored. On some systems (particularly web) setting this number as low as possible can increase the speed of shader compilation. + + Max number of lights renderable per object. This is further limited by hardware support. Most devices only support 409 lights, while many devices (especially mobile) only support 102. Setting this low will slightly reduce memory usage and may decrease shader compile times. + Shaders have a time variable that constantly increases. At some point, it needs to be rolled back to zero to avoid precision errors on shader animations. This setting specifies when (in seconds). diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp index cc11237ddf5..4a37e1fc3fa 100644 --- a/drivers/gles3/rasterizer_scene_gles3.cpp +++ b/drivers/gles3/rasterizer_scene_gles3.cpp @@ -1834,15 +1834,14 @@ void RasterizerSceneGLES3::_render_geometry(RenderList::Element *e) { void RasterizerSceneGLES3::_setup_light(RenderList::Element *e, const Transform &p_view_transform) { - int omni_indices[16]; + int maxobj = state.max_forward_lights_per_object; + int *omni_indices = (int *)alloca(maxobj * sizeof(int)); int omni_count = 0; - int spot_indices[16]; + int *spot_indices = (int *)alloca(maxobj * sizeof(int)); int spot_count = 0; int reflection_indices[16]; int reflection_count = 0; - int maxobj = MIN(16, state.max_forward_lights_per_object); - int lc = e->instance->light_instances.size(); if (lc) { @@ -5054,6 +5053,8 @@ void RasterizerSceneGLES3::initialize() { ProjectSettings::get_singleton()->set_custom_property_info("rendering/limits/rendering/max_renderable_lights", PropertyInfo(Variant::INT, "rendering/limits/rendering/max_renderable_lights", PROPERTY_HINT_RANGE, "16,4096,1")); render_list.max_reflections = GLOBAL_DEF("rendering/limits/rendering/max_renderable_reflections", (int)RenderList::DEFAULT_MAX_REFLECTIONS); ProjectSettings::get_singleton()->set_custom_property_info("rendering/limits/rendering/max_renderable_reflections", PropertyInfo(Variant::INT, "rendering/limits/rendering/max_renderable_reflections", PROPERTY_HINT_RANGE, "8,1024,1")); + render_list.max_lights_per_object = GLOBAL_DEF_RST("rendering/limits/rendering/max_lights_per_object", (int)RenderList::DEFAULT_MAX_LIGHTS_PER_OBJECT); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/limits/rendering/max_lights_per_object", PropertyInfo(Variant::INT, "rendering/limits/rendering/max_lights_per_object", PROPERTY_HINT_RANGE, "8,1024,1")); { //quad buffers @@ -5168,7 +5169,7 @@ void RasterizerSceneGLES3::initialize() { glBufferData(GL_UNIFORM_BUFFER, sizeof(LightDataUBO), NULL, GL_DYNAMIC_DRAW); glBindBuffer(GL_UNIFORM_BUFFER, 0); - state.max_forward_lights_per_object = 8; + state.max_forward_lights_per_object = MIN(state.max_ubo_lights, render_list.max_lights_per_object); state.scene_shader.add_custom_define("#define MAX_LIGHT_DATA_STRUCTS " + itos(state.max_ubo_lights) + "\n"); state.scene_shader.add_custom_define("#define MAX_FORWARD_LIGHTS " + itos(state.max_forward_lights_per_object) + "\n"); diff --git a/drivers/gles3/rasterizer_scene_gles3.h b/drivers/gles3/rasterizer_scene_gles3.h index 9c48a98bfbb..32e7b4e3035 100644 --- a/drivers/gles3/rasterizer_scene_gles3.h +++ b/drivers/gles3/rasterizer_scene_gles3.h @@ -672,6 +672,7 @@ public: MAX_DIRECTIONAL_LIGHTS = 16, DEFAULT_MAX_LIGHTS = 4096, DEFAULT_MAX_REFLECTIONS = 1024, + DEFAULT_MAX_LIGHTS_PER_OBJECT = 32, SORT_KEY_PRIORITY_SHIFT = 56, SORT_KEY_PRIORITY_MASK = 0xFF, @@ -704,6 +705,7 @@ public: int max_elements; int max_lights; int max_reflections; + int max_lights_per_object; struct Element { @@ -836,7 +838,7 @@ public: _FORCE_INLINE_ bool _setup_material(RasterizerStorageGLES3::Material *p_material, bool p_depth_pass, bool p_alpha_pass); _FORCE_INLINE_ void _setup_geometry(RenderList::Element *e, const Transform &p_view_transform); _FORCE_INLINE_ void _render_geometry(RenderList::Element *e); - _FORCE_INLINE_ void _setup_light(RenderList::Element *e, const Transform &p_view_transform); + void _setup_light(RenderList::Element *e, const Transform &p_view_transform); void _render_list(RenderList::Element **p_elements, int p_element_count, const Transform &p_view_transform, const CameraMatrix &p_projection, RasterizerStorageGLES3::Sky *p_sky, bool p_reverse_cull, bool p_alpha_pass, bool p_shadow, bool p_directional_add, bool p_directional_shadows);