Jump to content
  • Advertisement
Sign in to follow this  
XVincentX

Starting in deferred shading

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

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??

Share this post


Link to post
Share on other sites
Advertisement
hello xvincentx

could this be of any help to you?

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

cheers

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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...

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!