PDA

View Full Version : perspective correction for projected spotlights



heppe
10-05-2004, 07:56 AM
We are using a texture to get per-pixel attenuation for a spot-light effect. We are doing our own TexCoord calculation based on vertex locations relative to the "spotlight". The calculations are a lot like a basic camera projection.

The problem we are seeing is that the lit area suffers from some perspective projection problems that we don't know how to solve. Is there any way to give OGL explicit w values to work with for its perspective correction calculations?

dorbie
10-05-2004, 10:15 AM
Yes you can give specific w values using vertex4* but this would involve doing additional projection work on the CPU to get this right, your problem is you want independent w values for different textures, fortunately OpenGL supports this, the texture coordinates have a 4th term, you will have to use texcoord4* calls if specifying explicitly but you can then send in s,t,r,q where q is the perspective correction 'w' for your spotlight projection.

You may be better off letting OpenGL compute this, since it can easily do the division using a perspective projection matrix from which q is generated automatically.

The next step would be either to use texgen or use a vertex program to multicast the coordinates that go in to the matirix from the vertex values.

The objective of all of this would be to hardware accelerate the perspective projection and reduce bandwidth used to the graphics system.

heppe
10-05-2004, 11:56 AM
unless I'm missing something, I think we already have the w (or "q"), since we needed to compute it to project the points in the first place.

You are right that we really should be using texgen and texture matrices. We need to get it right on the CPU first, though.