Cleanup: EEVEE-Next: Move light clamping out of volume_light

This commit is contained in:
Clément Foucault
2024-04-11 11:43:07 +02:00
parent 969af3e8be
commit b4bc96cc41
3 changed files with 7 additions and 17 deletions

View File

@@ -53,6 +53,7 @@ void VolumeModule::init()
data_.shadow_steps = (shadow_enabled) ? scene_eval->eevee.volumetric_shadow_samples : 0;
data_.light_clamp = scene_eval->eevee.volumetric_light_clamp;
data_.light_clamp = (data_.light_clamp > 0.0) ? data_.light_clamp : 1e20;
use_reprojection_ = (scene_eval->eevee.flag & SCE_EEVEE_TAA_REPROJECTION) != 0;
}

View File

@@ -185,20 +185,6 @@ vec3 volume_light(LightData light, const bool is_directional, LightVector lv)
float power = 1.0;
if (!is_directional) {
float volume_radius_squared = light_local_data_get(light).radius_squared;
float light_clamp = uniform_buf.volumes.light_clamp;
if (light_clamp != 0.0) {
/* 0.0 light clamp means it's disabled. */
float max_power = reduce_max(light.color) * light.power[LIGHT_VOLUME];
if (max_power > 0.0) {
/* The limit of the power attenuation function when the distance to the light goes to 0 is
* `2 / r^2` where r is the light radius. We need to find the right radius that emits at
* most the volume light upper bound. Inverting the function we get: */
float min_radius_squared = 1.0 / (0.5 * light_clamp / max_power);
/* Square it here to avoid a multiplication inside the shader. */
volume_radius_squared = max(volume_radius_squared, min_radius_squared);
}
}
/**
* Using "Point Light Attenuation Without Singularity" from Cem Yuksel
* http://www.cemyuksel.com/research/pointlightattenuation/pointlightattenuation.pdf

View File

@@ -14,6 +14,7 @@
#pragma BLENDER_REQUIRE(eevee_lightprobe_eval_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_volume_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_colorspace_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_volume_lib.glsl)
#pragma BLENDER_REQUIRE(eevee_sampling_lib.glsl)
@@ -25,6 +26,7 @@ vec3 volume_scatter_light_eval(
{
LightData light = light_buf[l_idx];
/* TODO(fclem): Own light list for volume without lights that have 0 volume influence. */
if (light.power[LIGHT_VOLUME] == 0.0) {
return vec3(0);
}
@@ -41,14 +43,15 @@ vec3 volume_scatter_light_eval(
visibility *= shadow_sample(is_directional, shadow_atlas_tx, shadow_tilemaps_tx, light, P)
.light_visibilty;
}
visibility *= volume_phase_function(-V, lv.L, s_anisotropy);
if (visibility < LIGHT_ATTENUATION_THRESHOLD) {
return vec3(0);
}
vec3 Li = volume_light(light, is_directional, lv) *
vec3 Li = volume_light(light, is_directional, lv) * visibility *
volume_shadow(light, is_directional, P, lv, extinction_tx);
return Li * visibility * volume_phase_function(-V, lv.L, s_anisotropy);
return colorspace_brightness_clamp_max(Li, uniform_buf.volumes.light_clamp);
}
#endif