Sign in to follow this  

Per Pixel Spotlight vs Projective Texturing For spotlight

This topic is 2546 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
Racedriver GRID uses only one projective textured spot light (with a wide angle of phi) for each car.

Look at these pics:




Using traditional spotlight equations is performance-friendly, but cannot give you any realism. If you add projective texturing support, this will be eat performance a bit because of texture sampling.

Suggestion:
Use projective textured spotlights for cars.
Use traditional spot light equations for streetlights.

hth.
-R

Share this post


Link to post
Share on other sites
Quote:
Original post by programci_84
Racedriver GRID uses only one projective textured spot light (with a wide angle of phi) for each car.

Using traditional spotlight equations is performance-friendly, but cannot give you any realism. If you add projective texturing support, this will be eat performance a bit because of texture sampling.

Suggestion:
Use projective textured spotlights for cars.
Use traditional spot light equations for streetlights.

hth.
-R


But how do we use the same texture for multiple projective texture based spotlights ??

I am using this as my reference shader for Projective Texturing
 
//=============================================================================
// ProjTex.fx by Frank Luna (C) 2004 All Rights Reserved.
//
// Projective texturing.
//=============================================================================

struct Mtrl
{
float4 ambient;
float4 diffuse;
float4 spec;
float specPower;
};

struct SpotLight
{
float4 ambient;
float4 diffuse;
float4 spec;
float3 posW;
float3 dirW;
float spotPower;
};

uniform extern float4x4 gWorld;
uniform extern float4x4 gWorldInvTrans;
uniform extern float4x4 gLightWVP;
uniform extern float4x4 gWVP;
uniform extern Mtrl gMtrl;
uniform extern SpotLight gLight;
uniform extern float3 gEyePosW;
uniform extern texture gTex;


sampler TexS = sampler_state
{
Texture = <gTex>;
MinFilter = Anisotropic;
MaxAnisotropy = 8;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
};

struct OutputVS
{
float4 posH : POSITION0;
float3 posW : TEXCOORD0;
float3 normalW : TEXCOORD1;
float3 toEyeW : TEXCOORD2;
float4 projTex : TEXCOORD3;
};

OutputVS ProjTexVS(float3 posL : POSITION0, float3 normalL : NORMAL0)
{
// Zero out our output.
OutputVS outVS = (OutputVS)0;

// Transform normal to world space.
outVS.normalW = mul(float4(normalL, 0.0f), gWorldInvTrans).xyz;

// Transform vertex position to world space.
outVS.posW = mul(float4(posL, 1.0f), gWorld).xyz;

// Compute the unit vector from the vertex to the eye.
outVS.toEyeW = gEyePosW - outVS.posW;

// Transform to homogeneous clip space.
outVS.posH = mul(float4(posL, 1.0f), gWVP);

// Render from light source to generate projective texture coordinates.
outVS.projTex = mul(float4(posL, 1.0f), gLightWVP);

// Done--return the output.
return outVS;
}

float4 ProjTexPS(float3 posW : TEXCOORD0,
float3 normalW : TEXCOORD1,
float3 toEyeW : TEXCOORD2,
float4 projTex : TEXCOORD3) : COLOR
{
// Interpolated normals can become unnormal--so normalize.
normalW = normalize(normalW);
toEyeW = normalize(toEyeW);

// Light vector is from pixel to spotlight position.
float3 lightVecW = normalize(gLight.posW - posW);

// Compute the reflection vector.
float3 r = reflect(-lightVecW, normalW);

// Determine how much (if any) specular light makes it into the eye.
float t = pow(max(dot(r, toEyeW), 0.0f), gMtrl.specPower);

// Determine the diffuse light intensity that strikes the vertex.
float s = max(dot(lightVecW, normalW), 0.0f);

// Compute the ambient, diffuse and specular terms separately.
float3 spec = t*(gMtrl.spec*gLight.spec).rgb;
float3 diffuse = s*(gMtrl.diffuse*gLight.diffuse.rgb);
float3 ambient = gMtrl.ambient*gLight.ambient;

// Compute spotlight coefficient.
float spot = pow(max( dot(-lightVecW, gLight.dirW), 0.0f), gLight.spotPower);

// Project the texture coords and scale/offset to [0, 1].
projTex.xy /= projTex.w;
projTex.x = 0.5f*projTex.x + 0.5f;
projTex.y = -0.5f*projTex.y + 0.5f;

// Sample tex w/ projective texture coords.
float4 texColor = tex2D(TexS, projTex.xy);

// Only project/light in spotlight cone.
float3 litColor = spot*(ambient+diffuse*texColor.rgb + spec);

// Output the color and the alpha.
return float4(litColor, gMtrl.diffuse.a*texColor.a);
}

technique ProjTexTech
{
pass P0
{
// Specify the vertex and pixel shader associated with this pass.
vertexShader = compile vs_3_0 ProjTexVS();
pixelShader = compile ps_3_0 ProjTexPS();
}
}

Share this post


Link to post
Share on other sites
A quick way to get this working might suit well enough.

Take your existing spotlight and just ammened the end bit. When you have your dot product that would've been used as brightness, instead use that dot as a U coordinate to read a 1D texture that has varying falloffs in it across the texture. That's the fastest way to do this by far.

The next method involves reading from a 2D texture with "headlights" drawn into it. Ie two circles of mainly bright with appropriate blurred falloff further out, like an bulrred infinity symbol. This is a bit trickier as you need to use a cross product to find the plane between your spot and its direction and then use the xy component of that cross as UV coords. (Send up the X/Y vector for your spot as well as Z)

The above isn't projective texturing as I grew up with the term, it's textured lighting I guess. But it will work very well.

You can use a 1 component "luminance" texture to keep the bandwidth down a bit.

Share this post


Link to post
Share on other sites

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