diff options
author | clayjohn <claynjohn@gmail.com> | 2022-07-31 16:20:24 -0700 |
---|---|---|
committer | clayjohn <claynjohn@gmail.com> | 2022-08-31 12:14:46 -0700 |
commit | 385ee5c70b110fc4e6a47c847428bfe3da89e18e (patch) | |
tree | 79a98b11b042372e99ed209f033dd721f5a74e14 /servers/rendering/renderer_rd/shaders/environment | |
parent | 736632ee7ed00a3474448cfd227f696f82905ac7 (diff) |
Implement Physical Light Units as an optional setting.
This allows light sources to be specified in physical light units in addition to the regular energy multiplier. In order to avoid loss of precision at high values, brightness values are premultiplied by an exposure normalization value.
In support of Physical Light Units this PR also renames CameraEffects to CameraAttributes.
Diffstat (limited to 'servers/rendering/renderer_rd/shaders/environment')
7 files changed, 34 insertions, 19 deletions
diff --git a/servers/rendering/renderer_rd/shaders/environment/gi.glsl b/servers/rendering/renderer_rd/shaders/environment/gi.glsl index 6ea8cb1377..ab927df678 100644 --- a/servers/rendering/renderer_rd/shaders/environment/gi.glsl +++ b/servers/rendering/renderer_rd/shaders/environment/gi.glsl @@ -32,6 +32,8 @@ struct ProbeCascadeData { float to_probe; ivec3 probe_world_offset; float to_cell; // 1/bounds * grid_size + vec3 pad; + float exposure_normalization; }; layout(rgba16f, set = 0, binding = 9) uniform restrict writeonly image2D ambient_buffer; @@ -83,6 +85,9 @@ struct VoxelGIData { float normal_bias; // 4 - 88 bool blend_ambient; // 4 - 92 uint mipmaps; // 4 - 96 + + vec3 pad; // 12 - 108 + float exposure_normalization; // 4 - 112 }; layout(set = 0, binding = 16, std140) uniform VoxelGIs { @@ -241,7 +246,7 @@ void sdfvoxel_gi_process(uint cascade, vec3 cascade_pos, vec3 cam_pos, vec3 cam_ pos_uvw.x += float(offset.z) * sdfgi.lightprobe_uv_offset.z; diffuse = textureLod(sampler2DArray(lightprobe_texture, linear_sampler), pos_uvw, 0.0).rgb; - diffuse_accum += vec4(diffuse * weight, weight); + diffuse_accum += vec4(diffuse * weight * sdfgi.cascades[cascade].exposure_normalization, weight); { vec3 specular = vec3(0.0); @@ -255,7 +260,7 @@ void sdfvoxel_gi_process(uint cascade, vec3 cascade_pos, vec3 cam_pos, vec3 cam_ specular = mix(specular, textureLod(sampler2DArray(lightprobe_texture, linear_sampler), pos_uvw, 0.0).rgb, (roughness - 0.2) * 1.25); } - specular_accum += specular * weight; + specular_accum += specular * weight * sdfgi.cascades[cascade].exposure_normalization; } } @@ -574,7 +579,7 @@ void voxel_gi_compute(uint index, vec3 position, vec3 normal, vec3 ref_vec, mat3 } } - light.rgb *= voxel_gi_instances.data[index].dynamic_range; + light.rgb *= voxel_gi_instances.data[index].dynamic_range * voxel_gi_instances.data[index].exposure_normalization; if (!voxel_gi_instances.data[index].blend_ambient) { light.a = 1.0; } @@ -583,7 +588,7 @@ void voxel_gi_compute(uint index, vec3 position, vec3 normal, vec3 ref_vec, mat3 //radiance vec4 irr_light = voxel_cone_trace(voxel_gi_textures[index], cell_size, position, ref_vec, tan(roughness * 0.5 * M_PI * 0.99), max_distance, voxel_gi_instances.data[index].bias); - irr_light.rgb *= voxel_gi_instances.data[index].dynamic_range; + irr_light.rgb *= voxel_gi_instances.data[index].dynamic_range * voxel_gi_instances.data[index].exposure_normalization; if (!voxel_gi_instances.data[index].blend_ambient) { irr_light.a = 1.0; } diff --git a/servers/rendering/renderer_rd/shaders/environment/sdfgi_debug.glsl b/servers/rendering/renderer_rd/shaders/environment/sdfgi_debug.glsl index 9640d30e78..177dab16c7 100644 --- a/servers/rendering/renderer_rd/shaders/environment/sdfgi_debug.glsl +++ b/servers/rendering/renderer_rd/shaders/environment/sdfgi_debug.glsl @@ -21,6 +21,7 @@ struct CascadeData { float to_cell; // 1/bounds * grid_size ivec3 probe_world_offset; uint pad; + vec4 pad2; }; layout(set = 0, binding = 9, std140) uniform Cascades { diff --git a/servers/rendering/renderer_rd/shaders/environment/sdfgi_debug_probes.glsl b/servers/rendering/renderer_rd/shaders/environment/sdfgi_debug_probes.glsl index 75b1ad2130..a0ef169f03 100644 --- a/servers/rendering/renderer_rd/shaders/environment/sdfgi_debug_probes.glsl +++ b/servers/rendering/renderer_rd/shaders/environment/sdfgi_debug_probes.glsl @@ -73,6 +73,7 @@ struct CascadeData { float to_cell; // 1/bounds * grid_size ivec3 probe_world_offset; uint pad; + vec4 pad2; }; layout(set = 0, binding = 1, std140) uniform Cascades { diff --git a/servers/rendering/renderer_rd/shaders/environment/sdfgi_direct_light.glsl b/servers/rendering/renderer_rd/shaders/environment/sdfgi_direct_light.glsl index b95fad650e..9f7449b8aa 100644 --- a/servers/rendering/renderer_rd/shaders/environment/sdfgi_direct_light.glsl +++ b/servers/rendering/renderer_rd/shaders/environment/sdfgi_direct_light.glsl @@ -45,6 +45,7 @@ struct CascadeData { float to_cell; // 1/bounds * grid_size ivec3 probe_world_offset; uint pad; + vec4 pad2; }; layout(set = 0, binding = 8, std140) uniform Cascades { diff --git a/servers/rendering/renderer_rd/shaders/environment/sdfgi_integrate.glsl b/servers/rendering/renderer_rd/shaders/environment/sdfgi_integrate.glsl index 9c03297f5c..4bdb0dcc72 100644 --- a/servers/rendering/renderer_rd/shaders/environment/sdfgi_integrate.glsl +++ b/servers/rendering/renderer_rd/shaders/environment/sdfgi_integrate.glsl @@ -20,6 +20,7 @@ struct CascadeData { float to_cell; // 1/bounds * grid_size ivec3 probe_world_offset; uint pad; + vec4 pad2; }; layout(set = 0, binding = 7, std140) uniform Cascades { diff --git a/servers/rendering/renderer_rd/shaders/environment/sky.glsl b/servers/rendering/renderer_rd/shaders/environment/sky.glsl index e825020a4e..7a0b2af3ce 100644 --- a/servers/rendering/renderer_rd/shaders/environment/sky.glsl +++ b/servers/rendering/renderer_rd/shaders/environment/sky.glsl @@ -15,10 +15,10 @@ layout(location = 0) out vec2 uv_interp; layout(push_constant, std430) uniform Params { mat3 orientation; vec4 projections[MAX_VIEWS]; - vec4 position_multiplier; + vec3 position; float time; + vec3 pad; float luminance_multiplier; - float pad[2]; } params; @@ -55,10 +55,10 @@ layout(location = 0) in vec2 uv_interp; layout(push_constant, std430) uniform Params { mat3 orientation; vec4 projections[MAX_VIEWS]; - vec4 position_multiplier; + vec3 position; float time; + vec3 pad; float luminance_multiplier; - float pad[2]; } params; @@ -200,17 +200,17 @@ void main() { #ifdef USE_CUBEMAP_PASS #ifdef USES_HALF_RES_COLOR - half_res_color = texture(samplerCube(half_res, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), cube_normal) * params.luminance_multiplier; + half_res_color = texture(samplerCube(half_res, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), cube_normal) / params.luminance_multiplier; #endif #ifdef USES_QUARTER_RES_COLOR - quarter_res_color = texture(samplerCube(quarter_res, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), cube_normal) * params.luminance_multiplier; + quarter_res_color = texture(samplerCube(quarter_res, material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]), cube_normal) / params.luminance_multiplier; #endif #else #ifdef USES_HALF_RES_COLOR - half_res_color = textureLod(sampler2D(half_res, material_samplers[SAMPLER_LINEAR_CLAMP]), uv, 0.0) * params.luminance_multiplier; + half_res_color = textureLod(sampler2D(half_res, material_samplers[SAMPLER_LINEAR_CLAMP]), uv, 0.0) / params.luminance_multiplier; #endif #ifdef USES_QUARTER_RES_COLOR - quarter_res_color = textureLod(sampler2D(quarter_res, material_samplers[SAMPLER_LINEAR_CLAMP]), uv, 0.0) * params.luminance_multiplier; + quarter_res_color = textureLod(sampler2D(quarter_res, material_samplers[SAMPLER_LINEAR_CLAMP]), uv, 0.0) / params.luminance_multiplier; #endif #endif @@ -220,7 +220,7 @@ void main() { } - frag_color.rgb = color * params.position_multiplier.w; + frag_color.rgb = color; frag_color.a = alpha; #if !defined(DISABLE_FOG) && !defined(USE_CUBEMAP_PASS) @@ -242,12 +242,13 @@ void main() { #endif // DISABLE_FOG - // Blending is disabled for Sky, so alpha doesn't blend - // alpha is used for subsurface scattering so make sure it doesn't get applied to Sky + // Blending is disabled for Sky, so alpha doesn't blend. + // Alpha is used for subsurface scattering so make sure it doesn't get applied to Sky. if (!AT_CUBEMAP_PASS && !AT_HALF_RES_PASS && !AT_QUARTER_RES_PASS) { frag_color.a = 0.0; } - // For mobile renderer we're dividing by 2.0 as we're using a UNORM buffer - frag_color.rgb = frag_color.rgb / params.luminance_multiplier; + // For mobile renderer we're multiplying by 0.5 as we're using a UNORM buffer. + // For both mobile and clustered, we also bake in the exposure value for the environment and camera. + frag_color.rgb = frag_color.rgb * params.luminance_multiplier; } diff --git a/servers/rendering/renderer_rd/shaders/environment/volumetric_fog_process.glsl b/servers/rendering/renderer_rd/shaders/environment/volumetric_fog_process.glsl index 07d5223472..eed9038502 100644 --- a/servers/rendering/renderer_rd/shaders/environment/volumetric_fog_process.glsl +++ b/servers/rendering/renderer_rd/shaders/environment/volumetric_fog_process.glsl @@ -84,6 +84,9 @@ struct VoxelGIData { float normal_bias; // 4 - 88 bool blend_ambient; // 4 - 92 uint mipmaps; // 4 - 96 + + vec3 pad; // 12 - 108 + float exposure_normalization; // 4 - 112 }; layout(set = 0, binding = 11, std140) uniform VoxelGIs { @@ -105,6 +108,8 @@ struct SDFVoxelGICascadeData { float to_probe; ivec3 probe_world_offset; float to_cell; // 1/bounds * grid_size + vec3 pad; + float exposure_normalization; }; layout(set = 1, binding = 0, std140) uniform SDFGI { @@ -624,7 +629,7 @@ void main() { light += a * slight; } - light.rgb *= voxel_gi_instances.data[i].dynamic_range * params.gi_inject; + light.rgb *= voxel_gi_instances.data[i].dynamic_range * params.gi_inject * voxel_gi_instances.data[i].exposure_normalization; total_light += light.rgb; } @@ -691,7 +696,7 @@ void main() { vec3 ambient = texelFetch(sampler2DArray(sdfgi_ambient_texture, linear_sampler), uvw, 0).rgb; - ambient_accum.rgb += ambient * weight; + ambient_accum.rgb += ambient * weight * sdfgi.cascades[i].exposure_normalization; ambient_accum.a += weight; } |