在顶点着色器中指定3D rendertarget的目标层? [HLSL] [英] Specifying the target layer of a 3D rendertarget in vertex shader? [HLSL]

查看:151
本文介绍了在顶点着色器中指定3D rendertarget的目标层? [HLSL]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在HLSL/Directx11中工作时,我看到有两种绑定3D渲染目标的方法:要么绑定整个目标,要么在指定图层时绑定它.

When working in HLSL/Directx11 I see there are two methods for binding a 3D rendertarget: either you bind the entire target or you bind it while specifying a layer.

如果绑定整个目标,应如何在HLSL代码中指定要应用输出颜色的图层?

If you bind the entire target how does one specify the layer in HLSL code to which the output color is applied?

我怀疑这需要几何着色器...对吗?

I have a suspicion this requires a geometry shader ... is that correct?

还有其他方法可以在顶点着色器或其他地方完成此操作吗?

Is there any other approach which would allow this to be done in the vertex shader or elsewhere?

推荐答案

如果绑定整个体积纹理(或TextureArray),则确实需要使用Geometry Shader来写入特定的切片.

If you bind your whole volume texture (or TextureArray), you indeed need to use Geometry Shader to write to a specific slice.

您的GS输出结构将如下所示:

your GS output structure will look like this:

struct GSOutput
{
    float4 pos : SV_Position;
    uint slice : SV_RenderTargetArrayIndex;
    //Add anything else you need for your triangle
};

请不要对该片进行插值,因此,如果需要发射多个片,则需要为每个片推一个基元.

Please not that slice is not interpolated, so if you need to emit to several slices you need to push one primitive per slice.

在第二种情况下,您不想使用几何着色器".

Second case where you do not want to use Geometry Shader.

使用与上一个参数相同的参数创建一个rendertargetview描述,但是对于每个切片,更改这些参数(这是针对Texture2DArray,但如果使用Texture3D,则几乎相同):

Create a rendertargetview description with the same parameters as the previous one, but for each slice, change those parameters (This is for a Texture2DArray, but it's mostly the same if you use Texture3D) :

D3D11_RENDER_TARGET_VIEW_DESC rtvd;

rtvd.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
rtvd.Texture2DArray.ArraySize = 1;
rtvd.Texture2DArray.FirstArraySlice = yourslice;

现在您仅具有切片的渲染目标,因此您可以直接在管道中绑定单个切片.

Now you have a render target for the slice only, so you can directly bind a single slice in the pipeline.

请注意,这仅在您事先(在CPU中)知道绘图调用将呈现到哪个切片的情况下才有效.同样,您只能为该绘制调用渲染为单个切片.

Please note that this only works if you know in advance (in CPU) to which slice your draw call will render. Also you can render to a single slice only for this draw call.

这篇关于在顶点着色器中指定3D rendertarget的目标层? [HLSL]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆