GLSL frag shader outputting yellow color instead of gradient

50 Views Asked by At

I was trying to create a uv texture (idk if that term is right) like you first do in Shader Toy by getting the fragment coordinates and dividing it by resolution.

#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);
    
}

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.

#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);
    
}
1

There are 1 best solutions below

0
Alex Mathew On BEST ANSWER

Well, I eventually got it fixed. The problem was with the way I passed to the uniform. My width and height were in integer form while passing after explicit casting, it works.