So I've got a triangle:
And I've got a vertex shader:
uniform mat4 uViewProjection;
attribute vec3 aVertexPosition;
attribute vec2 aTextureCoords;
varying vec2 vTextureCoords;
void main(void) {
vTextureCoords = aTextureCoords;
gl_Position = uViewProjection * vec4(aVertexPosition, 1.0);
}
And I've got a fragment shader:
precision mediump float;
uniform sampler2D uMyTexture;
varying vec2 vTextureCoords;
void main(void) {
gl_FragColor = texture2D(uMyTexture, vTextureCoords);
}
And I feed in three sets of vertices and UVs, interleaved:
# x, y, z, s, t
0.0, 1.0, 0.0, 0.5, 1.0
-1.0, -1.0, 0.0, 0.0, 0.0
1.0, -1.0, 0.0, 1.0, 0.0
How does the fragment shader know to draw pixel A differently from pixel B? What changes?
A Fragment Shader is the Shader stage that will process a Fragment generated by the Rasterization into a set of colors and a single depth value. The fragment shader is the OpenGL pipeline stage after a primitive is rasterized. For each sample of the pixels covered by a primitive, a "fragment" is generated.
A fragment shader is the same as pixel shader.
A texture is an OpenGL Object that contains one or more images that all have the same image format. A texture can be used in two ways: it can be the source of a texture access from a Shader, or it can be used as a render target.
A Shader is a user-defined program designed to run on some stage of a graphics processor. Shaders provide the code for certain programmable stages of the rendering pipeline. They can also be used in a slightly more limited form for general, on-GPU computation.
As I understand it the rasterization stage of the GL pipeline interpolates vTextureCoords
across the triangle face, running the fragment shader on each pixel with the interpolated value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With