从顶点着色器更新信息

发布于 2024-11-04 04:48:46 字数 423 浏览 4 评论 0原文

在 WebGL 应用程序的顶点着色器程序中,我执行以下操作:

使用随时间变化的函数 f(t) 计算 gl_Position P。

我的问题是:

是否可以存储在顶点着色器中计算的更新后的 P(t),以便我可以在下一个时间步骤中使用它?这对于执行一些边界测试很有用。

我已经阅读了一些关于如何使用纹理来存储和更新顶点位置的信息,但这在 WebGL 中是否可行,因为在 OpenGL ES 1.0 中甚至不支持来自顶点程序的纹理访问?

举一个更具体的例子,假设我们试图根据方程 R(t) = (k*t, 0, 0) 移动一个点。这些位置在顶点着色器中更新,从而使点移动。现在,如果我想让点在位于 R = (C, 0, 0) 的墙上反弹。为此,我们需要 t - dt 处的点的位置。 (前一个时间步)。

任何想法表示赞赏。

问候

In the vertex shader program of a WebGL application, I am doing the following:

Calculate gl_Position P using a function f(t) that varies in time.

My question is:

Is it possible to store the updated P(t) computed in the vertex shader so I can use it in the next time step? This will be useful for performing some boundary tests.

I have read some information on how textures can be used to store and updated vextex positions, but is this feasible in WebGL, since even texture access from a vertex program is unsupported in OpenGL ES 1.0?

For a more concrete example, let us say that we are trying to move a point according to the equation R(t) = (k*t, 0, 0). These positions are updated in the vertex shader, which makes the point move. Now if I want to make the point bounce at the wall located at R = (C, 0, 0). To do that, we need the position of the point at t - dt. (previous time step).

Any ideas appreciated.

Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

后来的我们 2024-11-11 04:48:46

除了前面的答案之外,您还可以绕过 PBO 获取顶点纹理,但我不知道它们是否在 WebGL 或 GLES 中受支持,因为我只有桌面 GL 经验。您将顶点位置写入帧缓冲区。但是,您可以将它们复制到顶点缓冲区(通过 PBO 效果最好),并将它们用作通常的顶点属性,而不是使用它们作为顶点纹理。这是进行变换反馈的旧方法,我认为不支持这种方法。

In addition to the previous answers, you can circumvent vertex texture fetch by PBOs, but I do not know, if they are supported in WebGL or GLES, as I have only desktop GL experience. You write the vertex positions into the framebuffer. But then, instead of using these as vertex texture, you copy them into a vertex buffer (which works best via PBOs) and use them as a usual vertex attribute. That's the old way of doing transform feedback, which I suppose is not supported.

你列表最软的妹 2024-11-11 04:48:46

无法在顶点着色器中存储任何内容。您只能将值从它传递到片段着色器并将它们写入帧缓冲区像素。正如您所说,顶点纹理获取并未得到普遍支持(例如,ANGLE 几天前才开始支持它),所以即使这样也有点行不通。

您可以做两件事:要么在 JS 中进行所有位置数学运算,然后将 p1 和 p0 作为制服传递。或者跟踪之前的时间值并在着色器中对 t1 和 t0 进行两次位置数学计算(除非您受顶点着色器限制,否则不会对性能产生太大影响)。

There's no way to store anything in the vertex shader. You can only pass values from it to the fragment shader and write those to the framebuffer pixels. And as you said, vertex texture fetch isn't universally supported (for instance, ANGLE started supporting it only a few days ago), so even that is a bit unworkable.

You can do two things: either do all the position math in JS and pass in the p1 and p0 as uniforms. Or keep track of the previous time value and do the position math twice in the shader, both for t1 and t0 (shouldn't have much of a performance impact unless you're vertex shader -bound).

探春 2024-11-11 04:48:46

你的 dt 是常量吗?如果是这样,您可以通过评估 R(t-dt) 来检索您的点的先前位置

。如果它不是常量,那么您可以使用 uniform 在每个渲染周期中传递它。

Is your dt a constant? if so you could retrieve the previous position for your point by evaluating

R(t-dt). If it is not a constant then you could use a uniform to pass it along on every rendering cycle.

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