From 14389925fe2d3a29c01202c19b951f70f3a67daa Mon Sep 17 00:00:00 2001 From: Deve <deveee@gmail.com> Date: Sun, 23 Dec 2018 23:16:18 +0100 Subject: [PATCH] Minor optimization in pointlight scatter. Compute some values before loop. --- data/shaders/pointlightscatter.frag | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/data/shaders/pointlightscatter.frag b/data/shaders/pointlightscatter.frag index a50f68fdc..631067ad6 100644 --- a/data/shaders/pointlightscatter.frag +++ b/data/shaders/pointlightscatter.frag @@ -31,15 +31,15 @@ void main() float stepsize = length(farthestpoint - closestpoint) / 16.; vec3 fog = vec3(0.); vec3 xpos = farthestpoint; + vec3 fog_factor = light_col * density * stepsize * energy * 20.; + vec3 xpos_step = eyedir * stepsize; for (int i = 0; i < 16; i++) { float d = distance(light_pos, xpos); float l = (16. - float(i)) * stepsize; - float att = energy * 20. / (1. + d * d); - att *= max((radius - d) / radius, 0.); - fog += density * light_col * att * exp(- density * d) * exp(- density * l) * stepsize; - xpos += stepsize * eyedir; + fog += fog_factor / (1. + d * d) * max((radius - d) / radius, 0.) * exp(- density * d) * exp(- density * l); + xpos += xpos_step; } Fog = vec4(fogcol * fog, 0.);