Jump to content
  • Advertisement
Sign in to follow this  
Hardguy

Light, Attenuation

This topic is 4884 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So what is the best way for calculating light attentuation using the least textures units and gpu instructions? I have read some about it and this is what I have come up with so far: as a forumla A = d^2 / R^2 is used, A being attenuation, d distance to light and R radius of light (where A is 0). This can be formulated as: A = l.x^2 / R^2 + l.y^2 / R^2 + l.z^2 / R^2 l being light pos set to normal/tanget space. And if you set R' to 1 and l' to l/R you get A = l'.x^2 + l'.y^2 + l'.z^2 In the fragment shader you can now use the function: A = 1- ( (max(l'.x^2,1) + max(l'.y^2,1) + max(l'.z^2,1)) or use a 3d texture or a 2d and a 1d and end up with: A = tex2d(l'.x, l'.y) - tex1d(l'z) or A = tex3d(l'.x, l'.y, l'z) Using the 3d texture it can be done using only one texture unit and very few instructions. However a 3d texture is quite mem consuming and might have to have to low resolution. Using a 2D and 1D texture the resolution can be inscreased but one more texture unit are used. Are there any other better ways of doing this? I am trying to make this fit at least Gf3 and hopefully Gf2.

Share this post


Link to post
Share on other sites
Advertisement
I'm using this method (HLSL like code):

half getAttenuation(half3 lightVec)
{
return saturate(1 - dot(lightVec, lightVec) * g_OneOverSqrLightRadius);
}

where:

lightVec is vector from fragment to light.
g_OneOverSqrLightRadius is precalculated (1 / (light radius) ^ 2).

Share this post


Link to post
Share on other sites
GF2 doesn't have pixel shaders. However it did have register combiners (I think it was called something like that...) which could be accessed as an OpenGL extension and do per-pixel lighting (or radial fogging). I really know very little about pixel shaders but I'd be surprised if they weren't quite efficient at doing 1/R^2 calculations. Sadly nVidia seem to have taken down most of their examples and info for older cards (obviously they don't want anybody to be able to play anything new on a GF2).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!