Jump to content

  • Log In with Google      Sign In   
  • Create Account


Writing to multiple RenderTarget2D's from HLSL pixel shader


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Boreal Games   Members   -  Reputation: 778

Like
0Likes
Like

Posted 20 April 2012 - 12:58 PM

I need to write to two render targets: one for colour and another for depth+normal (for post-processing). I have a problem, though. Both targets seem to be getting the value output by COLOR0, while the second should logically be getting the value from COLOR1. What did I do wrong?

RT Initialization:
renderTarget = new RenderTarget2D(device, gameResolution.Width, gameResolution.Height, false, graphics.PreferredBackBufferFormat, DepthFormat.Depth24);
extraTarget = new RenderTarget2D(device, gameResolution.Width, gameResolution.Height, false, SurfaceFormat.Color, DepthFormat.None);


Using RTs:
Device.SetRenderTargets(new RenderTargetBinding(renderTarget), new RenderTargetBinding(extraTarget));


Relevant HLSL:
struct Pixel
{
	float4 Color : COLOR0;
	float4 Extra : COLOR1;
};

Pixel PS(Middle input)
{
	Pixel output;

	// perform other shader code

	output.Color = float4(totalDiffuse * matDiffuseColor * color.rgb + totalSpecular * matSpecularColor, color.a);
	output.Extra = float4(input.Position.z / input.Position.w, clippedNormal);

	return output;
}


Sponsor:

#2 jischneider   Members   -  Reputation: 252

Like
0Likes
Like

Posted 20 April 2012 - 02:24 PM

First of all, you will have precision problems with this scheme. You should store depth using a single surface format and normals in a floating point render target.

Why don't you try: Device.SetRenderTargets(renderTarget, extraTarget);

If this work, then you have a problem with RenderTargetBinding (that is used to avoid garbage). Try to pass the RenderTargetBinding like you should, in a array.

Project page: < XNA FINAL Engine >


#3 Boreal Games   Members   -  Reputation: 778

Like
0Likes
Like

Posted 20 April 2012 - 03:54 PM

I managed to get the separate writing working properly. Using the same shader code, however, it seems my Extra RT is not getting depth-tested. I gave it a depth buffer, but the buffer accumulates, causing the "color" output that should be occluded to draw like it's additive.

#4 jischneider   Members   -  Reputation: 252

Like
0Likes
Like

Posted 20 April 2012 - 04:32 PM

Do you try what I suggested?

Project page: < XNA FINAL Engine >





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS