Sign in to follow this  

3D Texture Render Target?

Recommended Posts

Would it be possible for you to give a quick explanation (and ideally code sample) on how to do achieve this scenario?

I am assuming it looks something like making a D3D11_TEXTURE3D_DESC and then creating a D3D11_RENDER_TARGET_VIEW_DESC for that texture but I am not clear on what it would be code-wise in the shader to set which u,v,w would be written by the pixel shader.

Big thanks!

Share this post

Link to post
Share on other sites
it is actually not that difficult. First you have to create the texture (i hope its pretty selfexplanatory)

ID3D10Device* pDevice = Renderer::getInstance()->getDevice();

ID3D10Texture3D* colorMap = 0;

texDesc.Width = _width;
texDesc.Height = _height;
texDesc.Depth = _depth;
texDesc.MipLevels = 0;
texDesc.Format = _colorFormat;
texDesc.Usage = D3D10_USAGE_DEFAULT;
texDesc.CPUAccessFlags = 0;

HR(pDevice->CreateTexture3D(&texDesc, 0, &colorMap));

HR(pDevice->CreateRenderTargetView(colorMap, 0, &m_colorMapRTV));
HR(pDevice->CreateShaderResourceView(colorMap, 0, &m_colorMapSRV));

buildViewport(_width, _height);

when writing to the texture you have to choose the layer via a geometry shader - for example in c++ code you have something like that

for (unsigned int layer = 0; layer < RES_DEPTH; ++layer)
shader->setInt("g_layer", layer);


then the geometry shader chooses the specific layer

float4 posH : SV_POSITION;
float2 texC : TEXCOORD;
uint layer : SV_RenderTargetArrayIndex;

void GS_SetLayer(triangle VS_OUT input[3],
inout TriangleStream<GS_OUT_LAYER> triOutputStream)
GS_OUT_LAYER output;

for(int i=0; i < 3; ++i)
output.posH = input[i].posH;
output.texC = input[i].texC;
output.layer = g_layer;



Important is the system-value semantic SV_RenderTargetArrayIndex which chooses the slice/layer in depth to which the pixel shader writes.

hope this helps!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this