XNA - 顶点流?
有人会向我提供/指出在 HLSL 和 XNA 中使用多个顶点流的解释或教程吗?我对 GPU 如何存储/访问它们、自定义着色器中流的优点或用途等感兴趣。
我已经看到了一些关于将多个顶点流用于实例化几何体的示例,但我有一个我很难理解底层机制。
更新
如果我有一个接受两个参数的顶点着色器(借自本教程)
InstancingVSoutput InstancingVS(InstancingVSinput input, float4x4 instanceTransform : TEXCOORD0, float4 color : TEXCOORD4)
{
InstancingVSoutput output;
float4 pos = input.Position;
pos = mul(pos, transpose(instanceTransform));
pos = mul(pos, WVP);
output.Position = pos;
output.Color = color;
return output;
}
从示例中看来,我是从 instanceTransform
和 input
中提取此内容的,它们是从单独的流中提取的。但是,在本例中,input
流是一个包含六个顶点的列表,而 instanceTransform
来自包含大量元素的流,其中包含平移矩阵。这应该用于实例化几何体。
我对这个着色器执行了多少次感到困惑 - 它是 VertexBuffer0.VertexCount*VertexBuffer1.VertexCount 吗?这类事情的问题在于,一旦有人弄清楚了,他们就不会费心向社区贡献一份写得很好的文档来详细说明他们的发现。
啊。
Would someone provide/point me to an explanation of or tutorial on using multiple vertex streams in HLSL and XNA? I'm interested in how they're stored/accessed by the GPU, advantages of or uses for streams in custom shaders, etc.
I've seen a few examples on using multiple vertex streams for instanced geometry, but I'm having a hard time wrapping my head around the underlying mechanism.
Update
If I have a vertex shader which accepts two parameters (borrowed from this tutorial)
InstancingVSoutput InstancingVS(InstancingVSinput input, float4x4 instanceTransform : TEXCOORD0, float4 color : TEXCOORD4)
{
InstancingVSoutput output;
float4 pos = input.Position;
pos = mul(pos, transpose(instanceTransform));
pos = mul(pos, WVP);
output.Position = pos;
output.Color = color;
return output;
}
It seems from the example that I pulled this from that instanceTransform
and input
are pulled from separate streams. However, in this case, the input
stream is a list of six vertices, and the instanceTransform
comes from a stream of a much larger number of elements, consisting of translation matrices. This is supposed to be used for instanced geometry.
I'm confused about how many times this shader gets executed - is it VertexBuffer0.VertexCount*VertexBuffer1.VertexCount? The problem with this kind of thing is that, once someone's figured it out, they don't bother contributing a well-written document back to the community detailing their discovery.
Argh.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于还没有其他人插话,我会尝试一下 :-) 这是 apphub 论坛上关于 Vertex Streams 的一个很棒的帖子:
http://forums.create.msdn.com/forums/p/46229 /276901.aspx
来自答案之一:
希望有帮助;-)
Since no one else has chimed in yet, I'll give it a go :-) this is a great thread on the apphub forums about Vertex Streams:
http://forums.create.msdn.com/forums/p/46229/276901.aspx
from one of the answers:
Hope it helps ;-)