Created
May 31, 2020 01:19
-
-
Save menduz/871be0282227c4c9ee2bab3d2568190a to your computer and use it in GitHub Desktop.
Cheap attenuation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float dist = length(lightVector); | |
float lightR = (lightPosRadius.w / uViewSize.y); | |
if(dist < lightR){ | |
float attenuation = dist/(1.0 - (dist/lightR) * (dist/lightR)); | |
attenuation = attenuation / lightR + 1.0; | |
attenuation = 1.0 / (attenuation * attenuation); | |
if (attenuation > 0.0) { | |
// normalize vectors | |
float normalPower = max(0.0, dot(normal, -normalize(lightVector.xyz))); | |
lightColor += diffuse * 2.0 * lc * normalPower * attenuation; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment