Types
Core data types in BWSL for shader programming.
Turn the guide into code
Take the key idea from this page into the playground and validate it in a real shader instead of leaving it as theory.
Open PlaygroundBWSL's current type surface is centered on 32-bit scalars, vectors, matrices, enums, structs, arrays, and pointers.
Scalar Types
Basic single-value types for fundamental operations.
bool
Boolean value representing true or false.
int
32-bit signed integer.
uint
32-bit unsigned integer.
float
32-bit floating point number.
Vector Types
Multi-component types for spatial and color operations.
Integer Vectors
int2
2-component signed integer vector.
int3
3-component signed integer vector.
int4
4-component signed integer vector.
Unsigned Integer Vectors
uint2
2-component unsigned integer vector.
uint3
3-component unsigned integer vector.
uint4
4-component unsigned integer vector.
Float Vectors
float2
2-component floating point vector. Commonly used for texture coordinates.
float3
3-component floating point vector. Used for positions, normals, and RGB colors.
float4
4-component floating point vector. Used for homogeneous coordinates and RGBA colors.
Matrix Types
Square matrices for transformations and linear algebra operations.
mat2
2x2 floating point matrix.
mat3
3x3 floating point matrix. Used for rotations and normal transformations.
mat4
4x4 floating point matrix. Used for full 3D transformations including translation.
Enums
BWSL enums support variants with associated data, pattern matching, and compile-time evaluated methods.
enum SDFShape {
Sphere(float radius),
Box(float3 size),
Torus(float major, float minor),
eval distance :: (float3 p) -> float {
Sphere(r): length(p) - r
Box(size): {
float3 d = abs(p) - size;
float outside = length(max(d, 0.0));
float inside = min(max(d.x, max(d.y, d.z)), 0.0);
return outside + inside;
}
Torus(major, minor): {
float2 q = float2(length(p.xz) - major, p.y);
return length(q) - minor;
}
}
}
See the Enums page for full documentation on variants, pattern matching, bitflags, and eval methods.
Structs, Arrays, and Pointers
User-defined structs and fixed-size arrays are part of the active language surface:
struct Light {
float3 position;
float intensity;
}
struct SkinningData {
mat4 boneMatrices[64];
}
Pointers use ^ for address-of and dereference:
int x = 42;
int^ ptr = ^x;
int value = ptr^;
ptr^ = 100;
Type Constraints
Type constraints define sets of types for use with generic functions:
constraint FloatVectors = float2 | float3 | float4;
constraint AllFloats = float | float2 | float3 | float4;
constraint Scalars = float | int;
Constraints enable generic functions that work with any type in the set:
scale :: (FloatVectors v, float s) -> FloatVectors {
return v * s;
}
See the Generics page for complete documentation on type constraints and type-pattern dispatch.
Usage Examples
bool enabled = true;
int count = 42;
uint flags = 0xFFu;
float intensity = 0.75;
float3 position = float3(1.0, 2.0, 3.0);
float4 color = float4(1.0, 0.5, 0.0, 1.0);
int2 dimensions = int2(1920, 1080);
mat4 transform = mat4(
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
);
Type Conversions
BWSL supports explicit conversions between compatible types:
float f = 3.14;
int i = int(f);
uint u = uint(i);
float3 v3 = float3(1.0, 2.0, 3.0);
float4 v4 = float4(v3, 1.0);
float2 v2 = v3.xy;
The examples on this page match the current compiler and regression suite rather than older draft syntax.