顶点合成 HLSL 的着色器端
假设您要求 directX 从多个顶点缓冲区发送顶点数据,如下所示:
immediateContext->IASetVertexBuffers( 0, 3, bufferArray, &vertexStride, 0 );
immediateContext->IASetIndexBuffer( indexBuffer, DXGI_FORMAT_R32_UINT, 0 );
immediateContext->DrawIndexed( numIndices, 0 , 0 );
现在 HLSL 端我应该做这样的事情:
struct FatVertex
{
float4 dataFromVertexBuffer1: SemanticName1
float4 dataFromVertexBuffer2: SemanticName2
float4 dataFromVertexBuffer3: SemanticName3
};
PixelShaderInput VertexShader( FatVertex input )
{
// Transform things, fill PixelShaderInput struct etc.
}
或者这样的事情:
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.
}
或者都是完全有效的(因为我假设语义名称告诉 Direct3D 在哪里放东西)。
这都是 Direct3D11。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两种方式都是合法的,HLSL确实使用了语义索引。这提供了很大的灵活性,对于习惯 GLSL 的人来说确实非常好。
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.