Make lights_per_object configurable

This commit is contained in:
Unknown 2020-11-16 22:11:22 -05:00 committed by NHodgesVFX
parent d0a5ef9c7a
commit 5965fbd9fa
3 changed files with 12 additions and 6 deletions

View File

@ -1073,6 +1073,9 @@
<member name="rendering/limits/rendering/max_renderable_reflections" type="int" setter="" getter="" default="1024">
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.
</member>
<member name="rendering/limits/rendering/max_lights_per_object" type="int" setter="" getter="" default="32">
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.
</member>
<member name="rendering/limits/time/time_rollover_secs" type="float" setter="" getter="" default="3600">
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).
</member>

View File

@ -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");

View File

@ -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);