开发者

Texture2D Array as Render Target in HLSL Pixel Shader

开发者 https://www.devze.com 2023-03-25 09:23 出处:网络
Currently I need a couple of textures\' worth of per-pixel data from my rendering pass (normals, depth and colour).

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, on开发者_运维技巧e 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?


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消