Skip to content

Instantly share code, notes, and snippets.

@bagobor
Created March 7, 2013 14:19
Show Gist options
  • Save bagobor/5108345 to your computer and use it in GitHub Desktop.
Save bagobor/5108345 to your computer and use it in GitHub Desktop.
3ds max lights decay
inline float Decay(float att,float dist, float r0) {
float s;
if (decayType==DECAY_NONE || dist==0.0f) return att;
if ((s=r0/dist)>=1.0f) return att;
return (decayType==DECAY_INVSQ)? s*s*att: s*att;
}
float BaseObjLight::ApplyDistanceAtten( float dist )
{
float atten = 1.0f;
if(ls.useNearAtten) {
if(dist<ls.nearAttenStart) // Beyond range
return 0;
if(dist<ls.nearAttenEnd) {
// in attenuated range
float u = (dist - ls.nearAttenStart)/(ls.nearAttenEnd-ls.nearAttenStart);
atten = u*u*(3-2*u); /* smooth cubic curve */
}
}
if (ls.useAtten) {
if(dist>ls.attenEnd) /* Beyond range */
return 0;
if(dist>ls.attenStart) {
/* Outside full-intensity range */
float u = (ls.attenEnd-dist)/(ls.attenEnd-ls.attenStart);
atten *= u*u*(3-2*u); /* smooth cubic curve */
}
}
// atten = Decay(atten,dist,ls.nearAttenEnd); // old way, changed by dan
atten = Decay(atten,dist, decayRadius);
return atten;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment