Tell me about vertex shader

So it is executed multiple times for each vertex

each vertex in opengl has things like position, color, normal etc. These are called the "attributes" of that vertex. These attributes are passed to a vertex shader program as inputs.

Calculate the final position of the vertex in a rendered scene. this value is given out as a built in variable called "gl_position".

vertices are transformed into geometric primitives such as triangles and lines by taking into consideration eye point, and frustum.

A process that converts primitives into 2 dimensional "fragments' which are processed by fragment shader to convert them to pixels. Fragment reader only gets the (x,y) coordinates.


//Previously
varying vec4 v_color;

//or
out vec4 v_color;

All declared out variables
These are varying variables

//built in variables
//these are not varying
gl_position
gl_FrontFacing
gl_PointSize

Same are the inputs to a fragment shader


gl_FragColor

Some literature seem to indicate any single output from this is considered color as long as it is declared as an out variable.

A fragment produced by rasterization with (x,y) screen coordinates can only modify the pixel at (x,y)

From Open GL ES 2.0 Programming Guide


uniform mat4 uMVPMatrix;
attribute vec4 aPosition;
void main() 
{
   gl_Position = uMVPMatrix * aPosition;
}

void main() 
{
   gl_FragColor = vec4(0.5, 0.25, 0.5, 1.0);
}

uniform mat4 uMVPMatrix;
attribute vec4 aPosition;
attribute vec2 aTextureCoordinate;
varying vec2 v_TextureCoordinate;
void main() 
{
   gl_Position = uMVPMatrix * aPosition;
   v_TextureCoordinate = aTextureCoordinate;
}

precision mediump float; //Appears Mandatory for this version of GLSL 
varying vec2 v_TextureCoordinate;
uniform sampler2D s_2DtextureSampler;
void main() 
{
   gl_FragColor = texture2D(s_2DtextureSampler, v_TextureCoordinate);
}