将 int 数组传递给片段着色器

发布于 2024-10-05 13:25:06 字数 285 浏览 1 评论 0原文

我正在尝试在 OpenGL ES 中绘制迭代函数。整数数组根据迭代函数命中给定像素的频率进行更新。我想将此密度数组传递给片段着色器,并使用它在覆盖整个屏幕的简单四边形上绘制结果。

我的问题是:我可以将此数组作为 uniform 直接传递给着色器,并使用 gl_FragCoord 查找给定位置的密度来生成像素

,还是

应该使用使用 GL_LUMINANCE 创建具有一个通道的纹理的数组并将其传递给着色器?

I'm attempting to plot an iterative function in OpenGL ES. An array of ints is being updated with how often a given pixel is hit by the iterative function. I'd like to pass this density array to a fragment shader and use it to plot the result on a simple quad covering the whole screen.

My question is: can I pass this array directly to the shader as a uniform and generate pixels by using gl_FragCoord to look up the density for the given position

or

should I rather use the array to create a texture with one channel using GL_LUMINANCE and pass that to the shader?

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

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

发布评论

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

评论(1

陪我终i 2024-10-12 13:25:06

您的可用制服数量有限,并且索引可能会带来麻烦,因为并非所有 GPU 都支持非常量索引。 2D Nx1 纹理不存在任何这些问题,但会返回 [0, 1] 范围内的值。您可以缩小该值以获得原始整数并使用它。

You have a limited number of uniforms available, and the indexing might be troubling since not all GPUs support non-constant indexing. A 2D Nx1 texture doesn't have any of these issues but will return values into the [0, 1] range. You can scale back this values to obtain the original integer and use it.

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