# Vertex shader light from lamp

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

## Recommended Posts

In our game scenes we have various spot lights implemented with vertex and pixel shaders to make lamp light effects. Now, since pixel shaders are expensive to send through the pipeline, I was thinking of getting the same light effect using just vertex shaders – however to make this look good, the scene areas with lamp lights has to consist of more triangles (a job for the artist, not me:)) So my question is: What do you guys do for the dynamic light from lamps etc, just vertex shaders ? I’m mostly thinking of lamps placed in indoor ceilings. As usually my concern is speed, especially since we have huge a ball-room scene with many lamps, which may me shoot down (turned off) independently during gameplay ..

##### Share on other sites
If you use per-vertex lighting, the results will not be as good as per-pixel lighting, and the polycount would have to increase.

If we're talking about diffuse light only, you can use the dot3 extension and multitexturing to achieve that(on OpenGL, but if you're using DirectX I assume there is an equivalent function).

Anyway, I had an idea a while ago of how to fake it with just using a 3D texture. I haven't implemented it yet, but I think some games use something like this.

Note that this is only for diffuse lighting.
Basically, think about the lighting equation for diffuse lighting:

Col=(norm(L) dot N)*Attenuation

Col=(norm(L) dot N)*(1-length(L)^2) (just an approximation,but it has good results)

Now, if we translate the light vector to tangent space using vertex shaders, the equation becomes:

Col=(norm(Lt) dot (0,0,1)) * (1-length(Lt)^2)

The only variable here is Lt. So you can encode the whole thing in a 3D texture(say 32x32x32), and use as 3D texture coordinates the light vector in tangent space. You would have to scale the vector to achieve bigger/smaller light ranges. You don't need pixel shaders, just texturing will do the trick.

And even if you don't want to mess with tangent spaces, just indexing a 3D attenuation map with the light vector would produce some fair results. Not as good, because it would only take into consideration the attenuation, but pleasing.

As I said, I haven't done it yet, so I'm not 100% sure, but it seems right to me. If anyone thinks I'm wrong, please correct me.

[Edited by - mikeman on October 14, 2004 1:42:15 AM]

• 21
• 14
• 9
• 17
• 13