GLSL Syntax
Further information for people interesting in writing GLSL
Additional shader example for understanding syntax
#ifdef GL_ES
precision highp float;
#endif
IN vec2 texCoord;
// Uniform variables:
// bridge between CPU - GPU that allows mapping external information
// For example: time
uniform float uTime;
{{MODULES_HEAD}}
void main()
{
/* Declaration of variables
type name = value; */
// Real numbers
float number_0 = 1.0; // with dot
int number_1 = 1;
// Vectors
// 2 dimensions [_ ,_ ]
vec2 v2_0 = vec2(0.,1.);
vec2 v2_1 = vec2(number_0,number_1);
//3 dimensions [_ ,_ ,_ ]
vec3 v3_0 = vec3(0.,0.5,1.);
vec3 v3_1 = vec3(v2_0,1.);
vec3 v3_2 = vec3(v2_0,number_0);
//4 dimensions [_ ,_ ,_ ,_ ]
vec4 v4_0 = vec4(0.,0.25,0.5,1.);
vec4 v4_1 = vec4(v2_0,v2_1);
vec4 v4_2 = vec4(v3_0,0.);
// Referencing vectors information
// [r, g, b, a] || [x , y , z , w]
float numero_2 = v4_0.r; // is equivalent to v4_0.x
vec2 v2_2 = v4_0.rg; // is equivalent to v4_0.xy
vec3 v3_3 = v4_0.gbr; // is equivalent to v4_0.yzx
gl_FragColor = vec4(0.5); // [ (r, g ,b , a) ] with values in between 0. y 1.
}
Functions to explore
FUNCTIONS
Trigonometry
Exponentials
Logarithms
Geometry
Other
Last updated