Jump to content

  • Log In with Google      Sign In   
  • Create Account

Lotes

Member Since 08 Nov 2012
Offline Last Active Nov 14 2012 06:53 AM

Topics I've Started

Render depth to texture

08 November 2012 - 07:30 AM

Hi, I work with XNA and I want to render the depth information of my scene into a texture. But all I get is my scene (some cubes) completly colored in white. So the depth information I determined is greater or equal 1.0 I guess. How is it done right? I googled a lot, but I can't find my mistake :'-(... Do I have to make any settings in XNA before rendering?

Here are the HLSL shaders I use:

float4x4 xView;
float4x4 xProjection;
float4x4 xWorld;

struct VertexToPixel
{
	float4 Position	: POSITION;  
	float4 Color  : COLOR0;
};

struct PixelToFrame
{
	float4 Color : COLOR0;
};

VertexToPixel PositionsVS( float4 inPos : POSITION)
{
	float4x4 preViewProjection = mul (xView, xProjection);
	float4x4 preWorldViewProjection = mul (xWorld, preViewProjection);
	VertexToPixel Output = (VertexToPixel)0;
	Output.Position = mul(inPos, preWorldViewProjection);
	Output.Color.a = 1;
	Output.Color.rgb = Output.Position.z/Output.Position.w;
	return Output;
}

PixelToFrame PositionsPS(VertexToPixel PSIn)
{
	PixelToFrame Output = (PixelToFrame)0;
	Output.Color = PSIn.Color;
	return Output;
}

technique Positions
{
	pass Pass0
	{  
	  VertexShader = compile vs_3_0 PositionsVS();
	  PixelShader  = compile ps_3_0 PositionsPS();
	}
}

PARTNERS