Arcanelab Blog
text

OpenGL ES GLSL Types void bool, bvec2, bvec3, bvec4 int, ivec2, ivec3, ivec4 float,…

OpenGL ES GLSL

Types

  • void
  • bool, bvec2, bvec3, bvec4
  • int, ivec2, ivec3, ivec4
  • float, vec2, vec3, vec4
  • mat2, mat3, mat4
  • struct
  • arrays
  • sampler2D, samplerCube

Qualifiers

  • const
  • attribute: shared between the app and the vertex shader
  • uniform: shared between the app and both shaders
  • varying: shared between the two shaders

Precision Qualifiers

  • highp
  • mediump
  • lowp

Input Qualifiers

  • in: read only
  • out: write only
  • inout: r/w

Built-in Variables

Vertex Shader

  • inout highp vec4 gl_Position
  • in mediump float gl_PointSize

Fragment Shader

  • in mediump vec4 gl_FragCoord (in window coordiante system)
  • in bool gl_FrontFacing
  • in mediump int gl_PointCoord (only if the rendered primitive is a point)
  • inout mediump vec4 gl_FragColor (RGBA)

Built-in Constants

Vertex Shader

  • const mediump int gl_MaxVertexAttribs >= 8
  • const mediump int gl_MaxVertexUniformVectors >= 128
  • const mediump int gl_MaxVaryingVectors >= 8
  • const mediump int gl_MaxVertexTextureImageUnits >= 0
  • const mediump int gl_MaxCombinedTextureImageUnits >= 8

Fragment Shader

  • const mediump int gl_MaxTextureImageUnits >= 8
  • const mediump int gl_MaxFragmentUniformVectors >= 16
  • const mediump int gl_MaxDrawBuffers = 1

Built-in Functions

T can be: float, vec2, vec3, vec4 M can be: mat2, mat3, mat4 V can be: vec2, vec3, vec4 bV can be: bvec2, bvec3, bvec4

  • radians: degrees to radians
  • degrees: radians to degrees
  • sin, cos, tan, asin, acos, atan
  • pow(T x, T y): x^y
  • exp(T x): e^x
  • log: natural logarithm
  • exp2(T x): 2^x
  • log: natural logarithm
  • log2: base 2 logarithm
  • sqrt, inversesqrt
  • abs, sign, floor, ceil, fract, mod, min, max
  • T clamp(T x, T min, T max): restrict x to [min, max]
  • T mix(T x, T y, float t): linear interpolations in [x, y], t = [0,1]
  • T step(float edge, T x): xmax? 1.0: mix(min, max, x))
  • float length(T x)
  • float distance(T p0, T p1)
  • float dot(T a, T b): |a||b|cos(phi), 0 if phi = 90+(180*N), N=0,1,2,…
  • vec3 cross(vec3 a, vec3 b): axb = |a||b|sin(phi)n, n = perpendicular unit vector. if a||b => axb = 0 vec
  • T normalize(T x): x/|x|
  • T faceforward(T n, T i, T nref)
  • T reflect(T i, T n)
  • T refract(T i, T n, float eta)
  • M matrixCompMult(M a, M b): component multiplication
  • bV lessThan(V a, V b): component-wise comparison
  • bV lessThanEqual(V a, V b)
  • bV greaterThan(V a, V b)
  • bV greaterThanEqual(V a, V b)
  • bV equal(V a, V b)
  • bV notEqual(V a, V b)
  • bool any(bV x)
  • bool all(bV x)
  • bV not(bV x)
  • vec4 texture2D(sampler2D sampler, vec2 coord): returns a texel (color) from the texture at given coord
  • vec4 textureCube(samplerCube sampler, vec3 coord): same as texture2D, but for 3d textures