• Advertisement
Sign in to follow this  

Light volumes in a deferred shader

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

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
Advertisement
Nevermind, I found the answer:

float2 ScreenPos;
ScreenPos[0] = PSIn.Position2D.x/PSIn.Position2D.w/2.0f +0.5f;
ScreenPos[1] = -PSIn.Position2D.y/PSIn.Position2D.w/2.0f +0.5f;



I was just having trouble figuring out what to google

Share this post


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

  • Advertisement