Per Pixel Spotlight vs Projective Texturing For spotlight

Started by
2 comments, last by spek 13 years, 3 months ago
Hi,

I am trying to figure out the tradeoff between perpixel spotlights vs Projective Texturing based spotlight for my racing game.

I need multiple lights( arnd 5-6) at any time, for the car headlights as well as for the streetlights.

Can anyone please suggest which one is better in terms of performance, which one gives better quality results.

Thanks
Advertisement
Using projective textures for spotlights is pretty common, and shouldn't be a problem at all (unless you are targetting a limited platform maybe).
projTexCoords = mul( textureMatrix, float4( pixelWorldPos.xyz,1 ) );beamTexture = tex2Dproj( tex, projTexCoords );result = dot( pixelNormal, lightVector ) * beamTexture.rgb;

The good thing with this is, in case you want to add shadowMaps, you'll need these projective texture coordinates anyway. And it also allows to apply more complex(colored) "beam textures". Imagine light shinines through a fence for example.

Not sure if the simple code above is faster or equal to solving it mathematically. Don't think it differs much anyway.
Quote:Original post by spek
Using projective textures for spotlights is pretty common, and shouldn't be a problem at all (unless you are targetting a limited platform maybe).
projTexCoords = mul( textureMatrix, float4( pixelWorldPos.xyz,1 ) );beamTexture = tex2Dproj( tex, projTexCoords );result = dot( pixelNormal, lightVector ) * beamTexture.rgb;

The good thing with this is, in case you want to add shadowMaps, you'll need these projective texture coordinates anyway. And it also allows to apply more complex(colored) "beam textures". Imagine light shinines through a fence for example.

Not sure if the simple code above is faster or equal to solving it mathematically. Don't think it differs much anyway.


can you direct me to some good projective texturing samples, haven't been able to find many for directx 9
I'm not familar with DirectX, but I'm pretty sure you can find an example in the nVidia SDK 9.5 or 10
http://developer.nvidia.com/object/sdk-9.html
http://developer.nvidia.com/object/sdk_home

The shader above is pretty much it anyway. All that is left is setting up a texture matrix first. Here some OpenGL code I use:
      procedure SetTextureMatrix(  const pos : TVector3f;                                   const dir : TVector3f;                                   const FoV : integer;                                   const up  : TVector3f                                   );      begin                { Bias already applied }                glMatrixMode(GL_TEXTURE);                    { Reset }                    glLoadIdentity;                    { Bias }                    glTranslatef( 0.5, 0.5, 0.5);                    glScalef(     0.5, 0.5, 0.5);                    { Camera perspective }                    gluPerspective( FoV, 1, 0.01, 1000);                                   { Light matrices }                    gluLookat( pos[0], pos[1], pos[2],                               pos[0] - dir[0],   // target pos                               pos[1] - dir[1],                               pos[2] - dir[2],                               up[0], up[1], up[2] );                glMatrixMode(GL_MODELVIEW);                      end; // SetTextureMatrix

This topic is closed to new replies.

Advertisement