Jump to content
  • Advertisement
Sign in to follow this  
duskndreamz

Per Pixel Spotlight vs Projective Texturing For spotlight

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
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


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!