Providing a complete 3D rendering goal in one go

Using DirectX 11, I created a three-dimensional volume texture that can be tied to a rendering target:

D3D11_TEXTURE3D_DESC texDesc3d;
// ...
texDesc3d.Usage     = D3D11_USAGE_DEFAULT;
texDesc3d.BindFlags = D3D11_BIND_RENDER_TARGET;

// Create volume texture and views
m_dxDevice->CreateTexture3D(&texDesc3d, nullptr, &m_tex3d);
m_dxDevice->CreateRenderTargetView(m_tex3d, nullptr, &m_tex3dRTView);

Now, I would like to update the entire rendering target and populate its procedural data generated in the pixel shader, like updating the target 2D rendering with a "full-screen pass". All I need to generate the data is the coordinates of the UVW pixel in question.

For 2D, you can build a simple vertex shader that displays a full screen triangle:

struct VS_OUTPUT
{
    float4 position : SV_Position;
    float2 uv: TexCoord;
};

// input: three empty vertices
VS_OUTPUT main( uint vertexID : SV_VertexID )
{
    VS_OUTPUT result;
    result.uv = float2((vertexID << 1) & 2, vertexID & 2);
    result.position = float4(result.uv * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);
    return result;
}

It's hard for me to envelop how to adopt this principle for 3D. Is this possible in DirectX 11, or do I need to display individual fragments of the volume texture, as described here ?

+4
1

, . N , Geometry Shader.

struct VS_OUTPUT
{
    float4 position : SV_Position;
    float2 uv: TexCoord;
    uint index: SLICEINDEX;
};

VS_OUTPUT main( uint vertexID : SV_VertexID, uint ii : SV_InstanceID )
{
    VS_OUTPUT result;
    result.uv = float2((vertexID << 1) & 2, vertexID & 2);
    result.position = float4(result.uv * float2(2.0f, -2.0f) + float2(-1.0f, 1.0f), 0.0f, 1.0f);
    result.slice = ii;
    return result;
}

DrawInstanced 3 N , N -

GS :

struct psInput
{
    float4 pos : SV_POSITION;
    float2 uv: TEXCOORD0;
uint index : SV_RenderTargetArrayIndex; //This will write your vertex to a specific slice, which you can read in pixel shader too
};

[maxvertexcount(3)] 
void GS( triangle VS_OUTPUT input[3], inout TriangleStream<psInput> gsout )
{       
psInput output;
for (uint i = 0; i < 3; i++)
{
    output.pos = input[i].pos;
    output.uv = input[i].uv;
    output.index= i;
    gsout.Append(output);
}
gsout.RestartStrip();
}

:

float4 PS(psInput input) : SV_Target
{
//Do something with uvs, and use slice input as Z
}

( ), numthreads arbirtary

[numthreads(8,8,8)]
void CS(uint3 tid : SV_DispatchThreadID)
{
     //Standard overflow safeguards

     //Generate data using tid coordinates
} 

/8, /8, /8

+1

All Articles