In the same way GLSL gives us a default output, vec4 gl_FragColor, it also gives us a default input, vec4 gl_FragCoord, which holds the screen coordinates of the pixel or screen fragment that the active thread is working on. With vec4 gl_FragCoord, we know where a thread is working inside the billboard. In this case we don't call it uniform because it will be different from thread to thread, instead gl_FragCoord is called a varying.
#ifdef GL_ES
precision mediump float;
#endif
uniform vec2 u_resolution;
void main() {
vec2 st = gl_FragCoord.xy/u_resolution;
gl_FragColor = vec4(st.x,st.y,0.0,1.0);
}
In the above code st is a variable that get vec2 value of the position of pixels that are represented between 0 and 1. We give the same codes(instructions) to each pixel, but gl_FragCoord make each of pixels ultimately have different color with others.

Can you tell where the coordinate (0.0, 0.0) is in our canvas?
- the left side below.

It is the end of the basic structure of the shader. Now, let's write the shader code in earnest.
'College Study > GLSL' 카테고리의 다른 글
[GLSL] Shaping Functions (0) | 2022.01.05 |
---|---|
[GLSL] Smoothstep (0) | 2022.01.05 |
[GLSL] Uniform (0) | 2022.01.05 |
[GLSL] Hello World (0) | 2022.01.05 |
[GLSL] What is a shader? (0) | 2022.01.05 |
댓글