Skip to main content

Primitive types

Types

Now that you know how to write a basic node, you might wonder what all the possibilities are. Here are the types you will use most often as inputs and outputs of your main function:

  • UV: The 2D coordinates that we use to sample our images. (vec2 under the hood).
  • float: Just a regular number.
  • SignedDistance: A distance to an object, used for SDF rendering. (float under the hood).
  • Color (Oklab, sRGB, LinearRGB or Okhsl). See the Color Spaces section to learn all about the various color types. (vec3 under the hood).
  • Color and alpha. (Oklab_PremultipliedA, Oklab_StraightA, LinearRGB_PremultipliedA, LinearRGB_StraightA, sRGB_PremultipliedA, sRGB_StraightA, Okhsl_PremultipliedA or Okhsl_StraightA). See the Color Spaces section to learn all about the various color types. (vec4 under the hood).

And here are all the remaining types, that are seldom used:

  • bool
  • int
  • vec2
  • vec3
  • vec4
  • mat2
  • mat3
  • mat4
  • Angle (float under the hood).
  • Hue (float under the hood).
  • Direction2D (vec2 under the hood, guaranteed to be of length 1).
info

It is important to note that these types are purely semantic, and in your code you can just treat them as a regular int / float / vec2 / vec3 / vec4.

Examples

Here are a few examples of typical main functions you might define:

Color Transformation
Oklab main(Oklab Color)
{
// ...
}
2D Modifier (Zoom, Distortion, ...)
UV main(UV Input)
{
// ...
}
Image
Oklab main(UV uv)
{
// ...
}
Math function
float main(float x)
{
// ...
}
Parametric curve
UV main(float Percentage)
{
// ...
}
Mask / Greyscale image
float main(UV uv)
{
// ...
}
Blend Mode
Oklab_PremultipliedA main(Oklab_PremultipliedA Over, Oklab_PremultipliedA Under)
{
// ...
}
Conversion to Black & White
float main(Oklab Color)
{
// ...
}
Colorizer
Oklab main(float Greyscale)
{
// ...
}
2D SDF
SignedDistance main(UV uv)
{
// ...
}
3D SDF
SignedDistance main(vec3 pos)
{
// ...
}