开发者

Shader side of Vertex composition HLSL

Say you ask directX to send in vertex data from multiple vertex buffers like so:

immediateContext->IASetVertexBuffers( 0, 3, bufferArray, &vertexStride, 0 );
immediateContext->IASetIndexBuffer( indexBuffer, DXGI_FORMAT_R32_UINT, 0 )开发者_开发问答;
immediateContext->DrawIndexed( numIndices, 0 , 0 );

Now HLSL side should I be doing something like this:

struct FatVertex
{
    float4 dataFromVertexBuffer1: SemanticName1
    float4 dataFromVertexBuffer2: SemanticName2
    float4 dataFromVertexBuffer3: SemanticName3
};

PixelShaderInput VertexShader( FatVertex input )
{
    // Transform things, fill PixelShaderInput struct etc.
}

Or something like this:

struct BufferData1
{
    float4 dataFromVertexBuffer1: SemanticName1
};

struct BufferData2
{
    float4 dataFromVertexBuffer2: SemanticName2
};

struct BufferData3
{
    float4 dataFromVertexBuffer3: SemanticName3
};

PixelShaderInput VertexShader( BufferData1 input1, BufferData2 input2, BufferData3 input3 )
{
    // Transform things, fill PixelShaderInput struct etc.
}

Or are both perfectly valid (as I am assuming that the semantic name tells Direct3D where to put things).

This is all Direct3D11.


Both ways are legal, HLSL does indeed use the semantic index. This allows for a lot of flexibility and is really quite wonderful for someone used to GLSL.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜