我试图创建一个 uv 纹理(如果这个术语是正确的话,我不知道),就像你第一次在 Shader Toy 中所做的那样,通过获取片段坐标并将其除以分辨率。
#version 330 core
out vec4 FragColour;
uniform vec2 Resolution;
void main()
{
vec2 uv = gl_FragCoord.xy / Resolution * 2.0f - 1.0f;
FragColour = vec4(uv, 0.0f, 1.0f);
}
```glsl
The `resolution` uniform is a `vec2` of (500,500) which are my screen width and height.
I feel like the output should be a gradient of colors, but it just outputs a solid yellow.
Idk if it is a driver issue but at the same time, I'm not sure if there is any issue on the code.
I tried plugging `uv.x` in the red color channel in the frag color variable and it still doesn't show any gradient and instead, it gives a solid red.
```glsl
#version 330 core
out
vec4 FragColour;
uniform vec2 Resolution;
void main()
{
vec2 uv = gl_FragCoord.xy / Resolution * 2.0f - 1.0f;
FragColour = vec4(uv.x, 0.0f, 0.0f, 1.0f);
}
好吧,我最终把它修好了。 问题出在我传递制服的方式上。 我的宽度和高度是整数形式,在显式转换后传递,它可以工作。