• 13
• 18
• 19
• 27
• 10

# Per Pixel Spotlight vs Projective Texturing For spotlight

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

## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
Quote:
 Original post by spekUsing 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

##### Share on other sites
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