Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top