Skip to content

Commit

Permalink
Merge pull request #81067 from bitsawer/fix_voxelgi_exposure
Browse files Browse the repository at this point in the history
Fix VoxelGI CameraAttributes exposure normalization handling
  • Loading branch information
akien-mga committed Aug 29, 2023
2 parents 9be010c + c73e1f0 commit b272d7e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
24 changes: 17 additions & 7 deletions scene/3d/voxel_gi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ VoxelGIData::~VoxelGIData() {
void VoxelGI::set_probe_data(const Ref<VoxelGIData> &p_data) {
if (p_data.is_valid()) {
RS::get_singleton()->instance_set_base(get_instance(), p_data->get_rid());
RS::get_singleton()->voxel_gi_set_baked_exposure_normalization(p_data->get_rid(), _get_camera_exposure_normalization());
} else {
RS::get_singleton()->instance_set_base(get_instance(), RID());
}
Expand Down Expand Up @@ -303,6 +304,10 @@ Vector3 VoxelGI::get_size() const {

void VoxelGI::set_camera_attributes(const Ref<CameraAttributes> &p_camera_attributes) {
camera_attributes = p_camera_attributes;

if (probe_data.is_valid()) {
RS::get_singleton()->voxel_gi_set_baked_exposure_normalization(probe_data->get_rid(), _get_camera_exposure_normalization());
}
}

Ref<CameraAttributes> VoxelGI::get_camera_attributes() const {
Expand Down Expand Up @@ -398,13 +403,7 @@ void VoxelGI::bake(Node *p_from_node, bool p_create_visual_debug) {
p_from_node = p_from_node ? p_from_node : get_parent();
ERR_FAIL_NULL(p_from_node);

float exposure_normalization = 1.0;
if (camera_attributes.is_valid()) {
exposure_normalization = camera_attributes->get_exposure_multiplier();
if (GLOBAL_GET("rendering/lights_and_shadows/use_physical_light_units")) {
exposure_normalization = camera_attributes->calculate_exposure_normalization();
}
}
float exposure_normalization = _get_camera_exposure_normalization();

Voxelizer baker;

Expand Down Expand Up @@ -485,6 +484,17 @@ void VoxelGI::_debug_bake() {
bake(nullptr, true);
}

float VoxelGI::_get_camera_exposure_normalization() {
float exposure_normalization = 1.0;
if (camera_attributes.is_valid()) {
exposure_normalization = camera_attributes->get_exposure_multiplier();
if (GLOBAL_GET("rendering/lights_and_shadows/use_physical_light_units")) {
exposure_normalization = camera_attributes->calculate_exposure_normalization();
}
}
return exposure_normalization;
}

AABB VoxelGI::get_aabb() const {
return AABB(-size / 2, size);
}
Expand Down
2 changes: 2 additions & 0 deletions scene/3d/voxel_gi.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ class VoxelGI : public VisualInstance3D {
void _find_meshes(Node *p_at_node, List<PlotMesh> &plot_meshes);
void _debug_bake();

float _get_camera_exposure_normalization();

protected:
static void _bind_methods();
#ifndef DISABLE_DEPRECATED
Expand Down

0 comments on commit b272d7e

Please sign in to comment.