XNA - 顶点流?

发布于 2024-10-13 12:22:39 字数 986 浏览 3 评论 0原文

有人会向我提供/指出在 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;
}

从示例中看来,我是从 instanceTransforminput 中提取此内容的,它们是从单独的流中提取的。但是,在本例中,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情感失落者 2024-10-20 12:22:39

由于还没有其他人插话,我会尝试一下 :-) 这是 apphub 论坛上关于 Vertex Streams 的一个很棒的帖子:
http://forums.create.msdn.com/forums/p/46229 /276901.aspx

来自答案之一:

要点是:不同的流
可以有不同的数据布局,并且
你的 VertexDeclaration 决定了什么
数据是从什么流中提取的。
所以,举例来说,你可以有一个
存储所有位置的缓冲区
和一个存储所有你的缓冲区
颜色,你可以将它们设置为
不同的流;或者你
可以将它们整合成一条流,
但这并不总是很方便。

希望有帮助;-)

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:

The gist is this: different streams
can have different data layouts, and
your VertexDeclaration determines what
data gets pulled from what stream.
So, for instance, you could have one
buffer that stores all your positions
and one buffer which stores all your
colors, and you could set those to
different streams; alternatively you
could munge them into a single stream,
but this isn't always convenient.

Hope it helps ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文