Skip to content

Commit e6d0b32

Browse files
committed
Merge pull request #106673 from retrotails/master
Fix light range in VoxelGI
2 parents 37559a1 + ba06234 commit e6d0b32

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

servers/rendering/renderer_rd/environment/gi.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2943,6 +2943,10 @@ void GI::VoxelGIInstance::update(bool p_update_light_instances, const Vector<RID
29432943
}
29442944
}
29452945

2946+
// probe size relative to 1 unit in world space
2947+
Vector3 ps = gi->voxel_gi_get_octree_size(probe) / gi->voxel_gi_get_bounds(probe).size;
2948+
float cell_size = (1.0 / MAX(MAX(ps.x, ps.y), ps.z));
2949+
29462950
if (has_dynamic_object_data || p_update_light_instances || p_dynamic_objects.size()) {
29472951
// PROCESS MIPMAPS
29482952
if (mipmaps.size()) {
@@ -2961,6 +2965,7 @@ void GI::VoxelGIInstance::update(bool p_update_light_instances, const Vector<RID
29612965
push_constant.dynamic_range = gi->voxel_gi_get_dynamic_range(probe);
29622966
push_constant.light_count = light_count;
29632967
push_constant.aniso_strength = 0;
2968+
push_constant.cell_size = cell_size;
29642969

29652970
/* print_line("probe update to version " + itos(last_probe_version));
29662971
print_line("propagation " + rtos(push_constant.propagation));
@@ -3161,9 +3166,9 @@ void GI::VoxelGIInstance::update(bool p_update_light_instances, const Vector<RID
31613166
push_constant.prev_rect_size[1] = 0;
31623167
push_constant.on_mipmap = false;
31633168
push_constant.propagation = gi->voxel_gi_get_propagation(probe);
3169+
push_constant.cell_size = cell_size;
31643170
push_constant.pad[0] = 0;
31653171
push_constant.pad[1] = 0;
3166-
push_constant.pad[2] = 0;
31673172

31683173
//process lighting
31693174
RD::ComputeListID compute_list = RD::get_singleton()->compute_list_begin();

servers/rendering/renderer_rd/environment/gi.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class GI : public RendererGI {
188188
uint32_t cell_offset;
189189
uint32_t cell_count;
190190
float aniso_strength;
191-
uint32_t pad;
191+
float cell_size;
192192
};
193193

194194
struct VoxelGIDynamicPushConstant {
@@ -209,7 +209,8 @@ class GI : public RendererGI {
209209
float dynamic_range;
210210
uint32_t on_mipmap;
211211
float propagation;
212-
float pad[3];
212+
float cell_size;
213+
float pad[2];
213214
};
214215

215216
VoxelGILight *voxel_gi_lights = nullptr;

servers/rendering/renderer_rd/shaders/environment/voxel_gi.glsl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ layout(push_constant, std430) uniform Params {
8686
uint cell_offset;
8787
uint cell_count;
8888
float aniso_strength;
89-
uint pad;
89+
float cell_size;
9090
}
9191
params;
9292

@@ -126,7 +126,8 @@ layout(push_constant, std430) uniform Params {
126126
float dynamic_range;
127127
bool on_mipmap;
128128
float propagation;
129-
float pad[3];
129+
float cell_size;
130+
float pad[2];
130131
}
131132
params;
132133

@@ -209,7 +210,10 @@ bool compute_light_vector(uint light, vec3 pos, out float attenuation, out vec3
209210
return false;
210211
}
211212

212-
attenuation = get_omni_attenuation(distance, 1.0 / lights.data[light].radius, lights.data[light].attenuation);
213+
attenuation = get_omni_attenuation(
214+
distance * params.cell_size,
215+
1.0 / (lights.data[light].radius * params.cell_size),
216+
lights.data[light].attenuation);
213217

214218
if (lights.data[light].type == LIGHT_TYPE_SPOT) {
215219
vec3 rel = normalize(pos - light_pos);

0 commit comments

Comments
 (0)