cucapra/braid

Enumerate missing GLSL constructs

sampsyo opened this issue · 3 comments

Here's the list of GLSL intrinsics we currently support: https://github.com/sampsyo/braid/blob/19f57db2ddcd93f1d07af3f49b9cc2b375a1c1f4/src/backends/gl.ts#L128-L193

It would be awesome to have a list of what we're missing from the GLSL standard supported by WebGL 1.0.

Compare GLSL intrinsics with built-in functions in webgl reference card.

Here are missing functions in Braid.

T represents float, vec2, vec3, or vec4

  • Triangular Functions

    • T sin(T angle)
    • T cos(T radians)
    • T sin(T angle)
    • T cos(T angle)
    • T tan(T angle)
    • T asin(T x)
    • T acos(T x)
    • T atan(T y, T x): atan2 in java
    • T atan(T y_over_x)
  • Exponential Functions

    • T exp(T x): e^x
    • T log(T x): ln x
    • T log2(T x): log_2
    • T sqrt(T x): square root
    • T inversesqrt(T x): inverse square root
    • T sign(T x): returns -1.0, 0.0, or 1.0
    • T floor(T x): nearest integer <= x
    • T ceil(T x): neaerest integer >= x
    • T fract(T x): x - floor(x)
    • T mod(T x, T y): modulus
    • T mod(T x, float y): modulus
    • T min(T x, T, y) and T min(T x, float y): overloaded
    • T max(T x, T, y) and T max(T x, float y): overloaded
    • T step(T edge, T x) and T step(float edge, T x): 0.0 if x < edge, else 1.0
    • T step(T edge0, T edge1, T x) and T step(float edge0, float edge1, T x): clip and smooth
  • Geometric Functions

    • float length(T x): length of a vector
    • float distance(T p0, T p1): distance between two points
    • T faceforward(T N, T I, T Nref): returns N if dot(Nerf, I) < 0, else returns -N
    • T refract(T I, T N, float eta): refraction vector
  • Matrix functions

    • Mat matrixCompMult(mat x, mat y): multiply x by y for each entry, such that result[i][j] = x[i][j] * y[i][j]
  • Vector Relational Functions: bvec stands for a boolean vector

    • bvec lessThan(T x, T y): x < y
    • bvec lessThanEqual(T x, T y): x <= y
    • bvec greaterThan(T x, T y): x > y
    • bvec greaterThanEqual(T x, T y): x >= y
    • bvec notEqual(T x, T y) and bvec equal(bvec x, bvec y): x == y
    • bvec notEqual(T x, T y) and bvec equal(bvec x, bvec y): x != y
    • bool any(bvec x): true if any component of x is true
    • bool all(bvec x): true if all components of x are true
    • bvec not(bvec x): logical inverse of x
  • Texture Loopup Functions

    • Available in both vertex and frament shaders
      • vec4 texture2DProj(sampler2D sampler, vec3 coord)
      • vec4 texture2DProj(sampler2D sampler, vec4 coord)
      • vec4 textureCube(samplerCube sampler, vec3 coord)
    • Available only in vertex shaders
      • vec4 texture2DLod(sampler2D sampler, vec2 coord, float lod)
      • vec4 texture2DProjLod(sampler2D sampler, vec3 coord, float lod)
      • vec4 texture2DProjLod(sampler2D sampler, vec4 coord, float lod)
      • vec4 textureCubeLod(samplerCube sampler, vec3 coord, float lod)
    • Availabe only in fragment shaders
      • vec4 texture2D(sampler2D sampler, vec2 coord, float bias)
      • vec4 texture2DProj(sampler2D sampler, vec3 coord, float bias)
      • vec4 texture2DProj(sampler2D sampler, vec4 coord, float bias)
      • vec4 textureCube(samplerCube sampler, vec3 coord, float bias)

This is great; thanks! Perhaps the next step would be to group these into rough units that we might work on adding. For example, here are some patterns I see:

  • There are lots of plain vector math functions. These should be "easy" to add to our collection.
  • Boolean vectors. We don't have a type for these yet.
  • Texture functions. We already support texture2D, and the other functions look like they follow the same pattern, right?

Also, it strikes me after reading this list that it would be nice to support much of these functions on the CPU as well as on the GPU. We already do this for a few simple functions, such as matrix multiplication, but more uniform coverage would be awesome.