Shadertoy Glsl-创建一个大矩阵并将其显示在屏幕上

发布于 2025-02-04 03:13:46 字数 92 浏览 2 评论 0原文

我有64种颜色的调色板。我需要创建一个512*512表,然后将调色板中的颜色索引写入其中,然后在屏幕上显示所有内容。问题是GLSL不支持二维数组,并且不可能在帧之间保存表

I have a palette of 64 colors. I need to create a 512*512 table and write the color indexes in the palette into it, and then display everything on the screen. The problem is that glsl does not support two-dimensional arrays, and it is impossible to save a table between frames

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

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

发布评论

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

评论(1

回心转意 2025-02-11 03:13:46

您可以做的最接近的事情是创建一个单独的缓冲区,而仅使用其中的一部分。
这是一个示例缓冲区A:

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    if(any(greaterThan(fragCoord, vec2(512)))) return;
    fragCoord -= .5;
    fragColor = vec4(mod(fragCoord.x,2.), 0, 0, 1); // generate a color at point.
}

然后在主着色器中,您可以使用以下像素访问:

// vec2 p; // p.x and p.y in range(0, 512)
texture(iChannel0, p/iResolution.xy);

如果使用OpenGL而不是Shadertoy,则可以使用纹理2D。

The closest thing you can do is create a separate buffer and only use a part of it.
here's an example buffer A:

void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    if(any(greaterThan(fragCoord, vec2(512)))) return;
    fragCoord -= .5;
    fragColor = vec4(mod(fragCoord.x,2.), 0, 0, 1); // generate a color at point.
}

then in the main shader, you can can access a pixel with:

// vec2 p; // p.x and p.y in range(0, 512)
texture(iChannel0, p/iResolution.xy);

If you are using openGL instead of shadertoy, you can use a texture 2d instead.

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