Language Overview
An introduction to BWSL syntax and core concepts.
Pressure-test the syntax
Take the concept from this page into the playground and deliberately break a pass, binding, or type signature to see how the compiler responds.
Try a Live EditBWSL (Brawl Shading Language) is designed to be familiar to developers who know C-style languages while providing modern features for shader development.
Core Concepts
Pipelines
Every BWSL program starts with a pipeline definition. A pipeline represents a complete rendering setup that can contain multiple passes.
pipeline MyPipeline {
// Pipeline contents
}
Passes
Passes represent individual render passes within a pipeline. Each pass contains vertex and fragment shader code.
pass "MainPass" {
vertex { /* ... */ }
fragment { /* ... */ }
}
Attributes
Attributes define the vertex input data for your shader:
attributes {
position: float3
normal: float3
texcoord: float2
color: float4
}
Resources
Resources are shader-visible values declared directly in the pipeline and provided by the host at runtime:
resources {
modelViewMatrix: mat4
projectionMatrix: mat4
normalMatrix: mat3
time: float
sceneColor: texture2D
sceneSampler: sampler
}
Type System
BWSL provides a strong type system with the following primitive types:
| Type | Description |
|---|---|
float | 32-bit floating point |
float2 | 2-component float vector |
float3 | 3-component float vector |
float4 | 4-component float vector |
int | 32-bit signed integer |
uint | 32-bit unsigned integer |
bool | Boolean value |
mat2 | 2x2 float matrix |
mat3 | 3x3 float matrix |
mat4 | 4x4 float matrix |
Resource types are declared in resources {} blocks:
| Type | Description |
|---|---|
texture2D | 2D texture resource |
texture3D | 3D texture resource |
textureCube | Cube texture resource |
texture2DArray | 2D texture array resource |
sampler | Sampler state used with texture resources |
buffer<T> | Structured buffer resource |
cbuffer<T> | Constant-buffer-style resource |
Variables and Constants
// Local variables
float x = 1.0;
float3 color = float3(1.0, 0.5, 0.0);
// Constants
const float PI = 3.14159265359;
const float3 UP = float3(0.0, 1.0, 0.0);
Control Flow
BWSL supports standard control flow statements:
// Conditionals
if (condition) {
// ...
} else {
// ...
}
// Loops
for (int i = 0; i < 10; i++) {
// ...
}
// Early returns
if (alpha < 0.01) {
discard; // Fragment shader only
}
Swizzling
Vector components can be accessed and rearranged using swizzle notation:
float4 color = float4(1.0, 0.5, 0.3, 1.0);
float3 rgb = color.rgb; // (1.0, 0.5, 0.3)
float2 rg = color.rg; // (1.0, 0.5)
float r = color.r; // 1.0
// Rearranging
float3 bgr = color.bgr; // (0.3, 0.5, 1.0)
float4 rrra = color.rrra; // (1.0, 1.0, 1.0, 1.0)
You can use either rgba or xyzw notation for swizzling. They're interchangeable.
Next Steps
- Learn about The Pipeline in detail
- Understand Types and type conversion
- Explore built-in Intrinsics