diff options
author | reduz <reduzio@gmail.com> | 2021-01-05 12:33:54 -0300 |
---|---|---|
committer | reduz <reduzio@gmail.com> | 2021-01-05 14:44:05 -0300 |
commit | 446618cf94fac48168e6fc8ead545ab3f349da0a (patch) | |
tree | 25ee8685b15145a9d20c1047c4d9fccc28e26bd0 /modules/lightmapper_rd | |
parent | 6e23ab4fa20f766ef9e1ec64be88675db6c708af (diff) |
Change the light attenuation formulas.
-Much better looking, physically based.
-Almost negligible extra cost.
Diffstat (limited to 'modules/lightmapper_rd')
-rw-r--r-- | modules/lightmapper_rd/lm_compute.glsl | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/modules/lightmapper_rd/lm_compute.glsl b/modules/lightmapper_rd/lm_compute.glsl index 56976bd623..8a9adbc5cc 100644 --- a/modules/lightmapper_rd/lm_compute.glsl +++ b/modules/lightmapper_rd/lm_compute.glsl @@ -249,6 +249,15 @@ float quick_hash(vec2 pos) { return fract(sin(dot(pos * 19.19, vec2(49.5791, 97.413))) * 49831.189237); } +float get_omni_attenuation(float distance, float inv_range, float decay) { + float nd = distance * inv_range; + nd *= nd; + nd *= nd; // nd^4 + nd = max(1.0 - nd, 0.0); + nd *= nd; // nd^2 + return nd * pow(max(distance, 0.0001), -decay); +} + void main() { #ifdef MODE_LIGHT_PROBES int probe_index = int(gl_GlobalInvocationID.x); @@ -300,7 +309,7 @@ void main() { d /= lights.data[i].range; - attenuation = pow(max(1.0 - d, 0.0), lights.data[i].attenuation); + attenuation = get_omni_attenuation(d, 1.0 / lights.data[i].range, lights.data[i].attenuation); if (lights.data[i].type == LIGHT_TYPE_SPOT) { vec3 rel = normalize(position - light_pos); |