在 HLSL 像素着色器中将 Texture2D 数组作为渲染目标
目前,我需要来自渲染通道的一些纹理的每像素数据(法线、深度和颜色)。
不是使用本质上相同的着色器(WorldViewPos 乘法等)运行三个通道,但每个通道都将不同类型的数据输出到渲染目标中的纹理(例如,一个通道用于颜色,一个通道用于深度,一个通道用于法线);我想使用Texture3D 对象或理想情况下使用Texture2D 数组作为像素着色器的渲染目标。这样我就可以将这三个渲染通道减少为一个,并一次性输出所有数据。
不幸的是,我发现的唯一例子是几何着色器。有没有办法指定纹理数组中的哪个纹理将数据发送到像素着色器内部?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找的是“多个渲染目标”。
您可以使用 GraphicsDevice.SetRenderTargets 设置多个渲染目标 (MSDN, 参见也)。
您可以通过输出到
COLOR0
来输出到 HLSL 像素着色器中的多个渲染目标(语义) 用于第一个目标,COLOR1
用于第二个目标,依此类推。最后,您必须使用 HiDef< /a> 配置文件,最多允许一次设置 4 个渲染目标。
编辑:我刚刚意识到我给出了 XNA 答案 - 但实际上您根本没有用 API 标记问题。 HLSL 对于 DirectX、SlimDX 等应该是相同的。要在 DirectX 中设置渲染目标,我想你想要
IDirect3DDevice9::SetRenderTarget
( MSDN)。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).