   HLSL Attenuation Problem
  Hi everyone, In an effect that I created recently I use normal maps and per pixel lighting. There are a few problems with it though. I am testing the effect in my program with a simple plane that looks like a stone floor and is made of two triangles.The worst of these problems is that of attenuation with the lights. For attenuation I get the distance from the point light to the specific vertex and test it against the light's range. The problem is that when the light is right over the center of the plane it is farther from the 4 vertexes than it is from the center of the plane and my shader makes everything uniformly shaded when there should be a bright spot over the center of the plane. Is there a way to do per-pixel attenuation in hlsl so that this does not happen? Thanks a lot!   
  You can either tesselate the surface to add more calculation points on the surface, or use per-pixel lighting to your shader. By using per-pixel lighting, you'll be moving the lighting calculation into the PS, and avoiding this issue completely.   ;  Yes per-pixel attenuation is possible. Pass into the pixel shader this vector: Att=float3(vertposworld-lightpos)*range;in the pixel shader simply do something like this:float atten=mul(In.Att, In.Att);   ;Quote:Original post by Matt AufderheidePass into the pixel shader this vector: Att=float3(vertposworld-lightpos)*range;That's the exact type of code that'll generate the artifacts that the OP doesn't want [wink]What you need to do is pass the vertposworld and lightpos values to the pixel shader untouched and then perform the distance(vertposworld,lightpos)/range calculation per-pixel.hthJack;  Thanks guys, thats very helpful.@sirobI have done this but it sort of defeats the benefit of per pixel lighting in that you have to render more primitives.@jollyjeffersThanks alot, this works well. I probably should have tried that though :)   