Skip to content

Mini SKSL Guide

SKSL is a shading language developed by Google for use in their Skia graphics library, which is the foundation for rendering in many applications, including PixiEditor. It allows developers to write custom shaders that can manipulate images and graphics at a low level.

SKSL is similar to GLSL and HLSL, most of the syntax is the same, although there are some differences you should be aware of.

PixiEditor uses SKSL in the Node Graph’s Shader node, allowing you to create custom shader effects by writing SKSL code directly.

For a more comprehensive understanding of SKSL, you can refer to the following resources:

To effectively use SKSL, you should have a basic understanding of programming concepts and optimally some familiarity with graphics programming.

Knowledge of vector mathematics, color spaces, and how shaders work will be beneficial.

A basic SKSL shader consists of a main function that takes in vector2 coordinates and produces an output color. The main function is the entry point for the shader.

half4 main(vec2 coords) { // coords are not normalized
return half4(1.0, 0.0, 0.0, 1.0); // Returns a red color
}

Uniforms allow you to pass arbitrary data to the shader from the CPU. They are declared at the top of the shader code and can be of various types, such as float, vec2, half4, etc.

uniform vec2 iResolution;
uniform double someValue;

SKSL supports several basic types, such as:

TypeDescription
floathigh precision floating-point scalar
halfmedium precision floating-point scalar
vec22-component float vector
vec33-component float vector
vec44-component float vector
float2x22×2 matrix of floats
float3x33×3 matrix of floats
half22-component medium precision float vector
half33-component medium precision float vector
half44-component medium precision float vector
inthigh precision integer scalar
int22-component integer vector
int33-component integer vector
int44-component integer vector
shaderSkSL shader object for runtime composition

Skia automatically handles color spaces and color conversion, but passing half4 uniform as a color is not enough. Skia doesn’t know your half4 is a color, so you need to specify it explicitly using layout(color).

layout(color) uniform half4 iColor;

iColor will be automatically converted to the correct color space and will be recognized as a color by PixiEditor as well.

One of the main differences between SKSL and other shading languages is how textures are sampled. In SKSL, you use the eval function on shader variable type.

Sampling is done in local coordinates. For more information about coordinate spaces in Skia, check out the Skia documentation.

uniform shader iImage;
half4 main(vec2 coords) {
return iImage.eval(coords);
}