Specifying the target layer of a 3D rendertarget in vertex shader? [HLSL]

亡梦爱人 提交于 2019-12-07 14:47:52

问题


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.

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?


回答1:


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

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.

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.

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.



来源:https://stackoverflow.com/questions/18992917/specifying-the-target-layer-of-a-3d-rendertarget-in-vertex-shader-hlsl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!