Sign in to follow this  
MilfredCubicleX

Light volumes in a deferred shader

Recommended Posts

Hey, this is a relatively simple question but i can't seem to figure it out. I'm trying to do light volumes for my deferred shader, but I can't figure out how to take the position of the light volume spheres and turn it into texture coordinates to get the gbuffer data. My shader looks like this:
struct VS_OUTPUT {
	float4 pPos : POSITION;
	float2 pPos2 : TEXCOORD0;
};

VS_OUTPUT VS( float4 vPos : POSITION )
{
	VS_OUTPUT Out;
	float4 tPos = mul( vPos, matWorldViewProj );
	float2 screensize = float2( 640.0, 480.0 );
	Out.pPos = tPos;
	Out.pPos2 = tPos.xy / screensize.xy;
	return Out;
}

float4 PS( VS_OUTPUT In ) : COLOR 
{
	float2 texcoord = In.pPos2.xy;
	float4 diffuse = tex2D( diffuseSampler, texcoord );
	float4 normal = tex2D( normalSampler, texcoord ) * 2.0 - 1.0;
	float4 pos = tex2D( posSampler, texcoord );
	float4 depth = tex2D( depthSampler, texcoord );
	.. do lighting stuff
}

I thought this would give me appropriate coordinates but instead i see the screen textures like 9 times, and it changes when I change the viewing direction.. helpppp please.

Share this post


Link to post
Share on other sites

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