Skip to content

Types & Expressions

Type System

AXSLC does not perform type checking. All types are passed through to GLSL, where the driver validates them.

Built-in Types

All GLSL types are supported:

Scalars: bool, int, uint, float, double

Vectors:

  • Float: vec2, vec3, vec4
  • Int: ivec2, ivec3, ivec4
  • Unsigned: uvec2, uvec3, uvec4
  • Boolean: bvec2, bvec3, bvec4

Matrices:

  • Square: mat2, mat3, mat4
  • Rectangular: mat2x3, mat2x4, mat3x2, mat3x4, mat4x2, mat4x3

Samplers:

  • sampler2D, sampler3D, samplerCube
  • sampler2DShadow, samplerCubeShadow
  • isampler2D, isampler3D, isamplerCube
  • usampler2D, usampler3D, usamplerCube

Images:

  • image2D, image3D, imageCube
  • iimage2D, iimage3D, iimageCube
  • uimage2D, uimage3D, uimageCube

User-Defined Types

Any identifier can be used as a type:

axsl
struct Material {
    vec3 albedo;
    float roughness;
};

Material create_default_material() {
    Material m;
    m.albedo = vec3(0.5);
    m.roughness = 0.5;
    return m;
}

Expressions

Literals

Integer:

axsl
42          // decimal
0xFF        // hexadecimal
0x1A2B      // hexadecimal

Float:

axsl
3.14159
0.5
1.0
0.          // abbreviation for 0.0
1.          // abbreviation for 1.0

Boolean:

axsl
true
false

Identifiers

axsl
position
u_time
gl_Position

Type Constructors

Vector constructors:

axsl
vec2(1.0, 0.0)
vec3(1.0)                    // all components = 1.0
vec4(vec3(1.0, 0.0, 0.0), 1.0)  // from vec3 + scalar

Matrix constructors:

axsl
mat4(1.0)                    // identity matrix
mat3(rotation_matrix)        // extract 3x3 from 4x4

Struct constructors:

axsl
Material(vec3(1.0), 0.5)

Binary Operators

Arithmetic:

axsl
a + b
a - b
a * b
a / b
a % b

Comparison:

axsl
a == b
a != b
a < b
a > b
a <= b
a >= b

Logical:

axsl
a && b
a || b

Bitwise:

axsl
a & b
a | b
a ^ b
a << b
a >> b

Unary Operators

Prefix:

axsl
!a          // logical not
~a          // bitwise not
-a          // negation
+a          // unary plus
++a         // pre-increment
--a         // pre-decrement

Postfix:

axsl
a++         // post-increment
a--         // post-decrement

Assignment Operators

Simple assignment:

axsl
a = b

Compound assignment:

axsl
a += b      // a = a + b
a -= b      // a = a - b
a *= b      // a = a * b
a /= b      // a = a / b
a %= b      // a = a % b
a &= b      // a = a & b
a |= b      // a = a | b
a ^= b      // a = a ^ b
a <<= b     // a = a << b
a >>= b     // a = a >> b

Ternary Operator

axsl
condition ? then_value : else_value

// Example:
float value = x > 0.0 ? 1.0 : -1.0;

Field Access

Vector swizzling:

axsl
position.x
position.xyz
color.rgb
color.bgr
position.xyzw

Struct field access:

axsl
material.albedo
light.position

Block instance access:

axsl
camera.view
scene.time

Array Subscript

axsl
array[0]
array[index]
matrix[row][col]

Function Calls

axsl
sin(angle)
normalize(vec)
texture(sampler, uv)
pow(base, exp)

Built-in functions:

AXSLC recognizes 70+ GLSL built-in functions:

Trigonometric:sin, cos, tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh

Exponential:pow, exp, log, exp2, log2, sqrt, inversesqrt

Common:abs, sign, floor, trunc, round, roundEven, ceil, fract, mod, modf, min, max, clamp, mix, step, smoothstep, isnan, isinf

Geometric:length, distance, dot, cross, normalize, reflect, refract, faceforward

Matrix:matrixCompMult, outerProduct, transpose, determinant, inverse

Vector Relational:lessThan, lessThanEqual, greaterThan, greaterThanEqual, equal, notEqual, any, all, not

Texture:texture, texture2D, texture3D, textureCube, textureLod, texture2DLod, textureSize, texelFetch, texelFetchOffset, textureOffset, textureGrad, textureGather

Image:imageLoad, imageStore, imageSize

Atomic:atomicAdd, atomicMin, atomicMax, atomicAnd, atomicOr, atomicXor, atomicExchange, atomicCompSwap

Derivative:dFdx, dFdy, fwidth

Geometry:emit, endPrimitive

Compute:barrier, memoryBarrier, groupMemoryBarrier

Packing:packUnorm2x16, packSnorm2x16, unpackUnorm2x16, unpackSnorm2x16, packHalf2x16, unpackHalf2x16

Operator Precedence

From highest to lowest precedence:

LevelOperatorsAssociativity
15() [] . ++ -- (postfix)Left
14++ -- (prefix) + - (unary) ! ~Right
12* / %Left
11+ -Left
10<< >>Left
9< > <= >=Left
8== !=Left
7&Left
6^Left
5``
4&&Left
3`
2?:Right
1= += -= *= /= etc.Right

Type Conversions

AXSLC does not validate conversions. The GLSL compiler handles implicit and explicit conversions:

axsl
float f = 1.0;
int i = int(f);           // explicit cast
vec3 v = vec3(1.0);       // constructor
vec4 v4 = vec4(v, 1.0);   // mixed constructor

Examples

Complex Expression

axsl
vec3 result = normalize(cross(a, b)) * dot(c, d) + mix(e, f, t);

Chained Field Access

axsl
vec3 camera_pos = scene.camera.position;
float red = material.albedo.r;

Matrix Multiplication

axsl
vec4 clip_pos = projection * view * model * vec4(local_pos, 1.0);

Ternary with Function Calls

axsl
vec3 color = is_lit ? compute_lighting(normal) : ambient_color;

Array and Swizzle

axsl
vec2 uv = vertices[index].position.xy;