Sign in to follow this  

Per Pixel Spotlight vs Projective Texturing For spotlight

This topic is 2544 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
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

This topic is 2544 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this