Skip to content

Instantly share code, notes, and snippets.

@menduz
Created May 31, 2020 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save menduz/871be0282227c4c9ee2bab3d2568190a to your computer and use it in GitHub Desktop.
Save menduz/871be0282227c4c9ee2bab3d2568190a to your computer and use it in GitHub Desktop.
Cheap attenuation
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