Jump to content
  • Advertisement
Sign in to follow this  

[DirectX9][C++] PSSM Depth Test with 4 MRT

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

How can i propertly output depth "values" to 4 rt's? Everithing works fine with multipass. nVidia 9800gt (supports 4 mrts) DX SDK November 2008 (I think that all relevant code is below) Current depth shader:
float4x4 World;
float4x4 View0;
float4x4 View1;
float4x4 View2;
float4x4 View3;
float4x4 Projection0;
float4x4 Projection1;
float4x4 Projection2;
float4x4 Projection3;

texture DiffuseTexture;
sampler DiffuseSampler : register(s0) = sampler_state
    Texture     = (DiffuseTexture);
    MinFilter   = Point;
    MagFilter   = Point;
    MipFilter   = None;

struct A2V
    float3 Position0  : POSITION0;
    float2 TexCoord0  : TEXCOORD0;

struct V2P
    float4 Position0  : POSITION0;
	float4 Position1  : POSITION1;
	float4 Position2  : POSITION2;
	float4 Position3  : POSITION3;
    float2 TexCoord0  : TEXCOORD0;
    float4 Depth      : TEXCOORD1;

struct P2A
	float4 Color0 : COLOR0;
	float4 Color1 : COLOR1;
	float4 Color2 : COLOR2;
	float4 Color3 : COLOR3;

void VertexMain(in A2V IN, out V2P OUT)
    float4x4 worldView0     = mul(World, View0);
    float4x4 worldViewProj0 = mul(worldView0, Projection0);
	float4x4 worldView1     = mul(World, View1);
    float4x4 worldViewProj1 = mul(worldView1, Projection1);
	float4x4 worldView2     = mul(World, View2);
    float4x4 worldViewProj2 = mul(worldView2, Projection2);
	float4x4 worldView3     = mul(World, View3);
    float4x4 worldViewProj3 = mul(worldView3, Projection3);

	float4 wpos0            = float4(IN.Position0.xyz, 1.0f);

	OUT.Position0 = mul(wpos0, worldViewProj0);
	OUT.Position1 = mul(wpos0, worldViewProj1);
	OUT.Position2 = mul(wpos0, worldViewProj2);
	OUT.Position3 = mul(wpos0, worldViewProj3);

    OUT.TexCoord0          = IN.TexCoord0;

	OUT.Depth.x              = (OUT.Position0.z / OUT.Position0.w);
	OUT.Depth.y              = (OUT.Position1.z / OUT.Position1.w);
	OUT.Depth.z              = (OUT.Position2.z / OUT.Position2.w);
	OUT.Depth.w              = (OUT.Position3.z / OUT.Position3.w);

void PixelMain(in V2P IN, out P2A OUT)
	if(tex2D(DiffuseSampler, IN.TexCoord0).a < 1.0f)

	OUT.Color0   = float4(IN.Depth.x, 1.0f, 1.0f, 1.0f);
	OUT.Color1   = float4(IN.Depth.y, 1.0f, 1.0f, 1.0f);
	OUT.Color2   = float4(IN.Depth.z, 1.0f, 1.0f, 1.0f);
	OUT.Color3   = float4(IN.Depth.w, 1.0f, 1.0f, 1.0f);

technique DepthTest
    pass p0
        VertexShader     = compile vs_3_0 VertexMain();
        PixelShader      = compile ps_3_0 PixelMain();
C++ code fragments:
dev->SetRenderTarget(0, rt0);
	dev->SetRenderTarget(1, rt1);
	dev->SetRenderTarget(2, rt2);
	dev->SetRenderTarget(3, rt3);
	D3DRECT rcs[4];
	rcs[0].x1 = 0;
	rcs[0].x2 = ShadowMapSize;
	rcs[0].y1 = 0;
	rcs[0].y2 = ShadowMapSize;
	rcs[1].x1 = 0;
	rcs[1].x2 = ShadowMapSize;
	rcs[1].y1 = 0;
	rcs[1].y2 = ShadowMapSize;
	rcs[2].x1 = 0;
	rcs[2].x2 = ShadowMapSize;
	rcs[2].y1 = 0;
	rcs[2].y2 = ShadowMapSize;
	rcs[3].x1 = 0;
	rcs[3].x2 = ShadowMapSize;
	rcs[3].y1 = 0;
	rcs[3].y2 = ShadowMapSize;
	HRESULT hr = dev->Clear(4, rcs, fg, 0x00FFFFFF, 1.0f, 0L);
All 4 rts has same format and size (R32F, 1024x1024) The output is only correct for first rt. Others are somewhat similar to it but should have different depths values? (Sorry for not posting images i have dialup connection so its pretty slow)

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!