3

Currently I need a couple of textures' worth of per-pixel data from my rendering pass (normals, depth and colour).

Instead of running three passes with shaders that are essentially the same (WorldViewPos multiplication, etc.) but each outputting a different type of data to a texture in a render target (e.g. one pass for colour, one pass for depth, one pass for normals); I'd like to either use a Texture3D object or ideally a Texture2D array as my pixel shader's render target. That way I could reduce these three render passes to just one and output all the data in one go.

Unfortunately the only examples I've found have been for geometry shaders. Is there a way to specify which texture in a texture array to send data to inside a pixel shader?

Nick Udell
  • 2,306
  • 5
  • 41
  • 81

1 Answers1

3

What you are looking for is "Multiple Render Targets".

You can set more than one render target using GraphicsDevice.SetRenderTargets (MSDN, see also).

You can output to multiple render targets in a HLSL pixel shader by outputting to COLOR0 (the semantic) for the first target, COLOR1 for the second, and so on.

Finally, you must be using the HiDef profile, which allows up to 4 render targets to be set at once.


EDIT: I just realised I gave an XNA answer - but actually you didn't tag the question with an API at all. The HLSL should be the same for DirectX, SlimDX, etc. To set render targets in DirectX I think you want IDirect3DDevice9::SetRenderTarget (MSDN).

Andrew Russell
  • 26,137
  • 7
  • 54
  • 104
  • Thanks for that, it's just what I needed, but I've been having problems with the implementation. I started a new question for it as I've had to paste a fair amount of data in order to elabourate. It can be found here: http://stackoverflow.com/questions/6891194/multiple-render-targets-not-saving-data – Nick Udell Aug 01 '11 at 12:40