Starting in deferred shading

Started by
3 comments, last by XVincentX 14 years, 11 months ago
I decided to make a try with deferred shading. For now i would like to make a simple directional light. So made Gbuffers: Position, Basecolor from texture, Normal, Depth (depth it's simply a copy resource from depthbuffer in D3D10). With this shader

PS_OUT ps_main(PS_INPUT In)
{
	PS_OUT output = (PS_OUT)0;
	
	float4 BaseColor = Texture.Sample(SamplText,In.Tex);
	output.Position = In.WorldPos;
	output.Normal = 0.5f * (float4(In.Nor,1.0f) + 1.0f); 
	output.Diffuse = BaseColor;
	
	return output;
}
But i noticed that, in order to make trasformation from screen space to world space and all this kind of conversion, there are some operations to do that i do not know. Infact, directional light is not the same making it in forward rendering.

float4 ps_draw(in float4 Pos:SV_POSITION, in float2 Tex:TEXCOORD)	:	SV_TARGET
{
	float4 TexC = BaseColor.Sample(SamplText,Tex);
	float3 Norm = 2.0f * Normal.Sample(SamplText,Tex).xyz - 1.0f;
	
	return TexC * max(0.0f,dot(Norm,normalize(LightDirection)));
}

void vs_draw (in float4 Pos:POSITION, in float2 Tex:TEXCOORD,out float4 WP:SV_POSITION,out float2 Tx:TEXCOORD)
{
	WP = float4(Pos.xyz,1);
	Tx = Tex - halfpixel;
}

How should i insert data in buffers and retrive it in the same way??
Advertisement
hello xvincentx

could this be of any help to you?

http://mynameismjp.wordpress.com/2009/03/10/reconstructing-position-from-depth/

cheers
No, i have position in a separate GBuffer.
I was talking about normals.
You shouldn't have to do any special transformations in your light shader as long as your normals were stored in world space. Did you convert them to world space in your G-Buffer shader?
What do you mean world space? Simply mul them for WorldMatrix?
Yes, i did.

Nothing about -1 1 range...0 1 range trasformations...this stuff...

This topic is closed to new replies.

Advertisement