Uniforms¶
Uniforms are how a shader reads values that change per frame or per setup: time, resolution, mouse state, input channels, and your own custom parameters. Shader Studio declares the built-ins for you and can read custom ones from a Script pass.
Built-in uniforms¶
These are always available — no declaration needed. Types differ slightly between GLSL, Slang, and WGSL:
| Uniform | GLSL | Slang | WGSL | Meaning |
|---|---|---|---|---|
iResolution |
vec3 |
float3 |
vec3f |
Canvas size in xy, aspect ratio in z |
iTime |
float |
float |
f32 |
Elapsed time in seconds |
iTimeDelta |
float |
float |
f32 |
Time since the previous frame |
iFrameRate |
float |
float |
f32 |
Current frames per second |
iMouse |
vec4 |
float4 |
vec4f |
As on Shadertoy: xy = pointer position while a button is held, zw = click position; z > 0 while held, w > 0 only on the click frame |
iPointer |
struct | struct | struct | Hover, individual mouse buttons, modifiers and scrolling; see below |
iFrame |
int |
int |
i32 |
Frame counter starting at zero |
iDate |
vec4 |
float4 |
vec4f |
Year, month, day, seconds since midnight |
iChannelTime |
float[1024] |
— | — | Playback time per input channel |
iChannelResolution |
vec3[1024] |
— | — | Resolution per input channel |
iSampleRate |
float |
float |
f32 |
Audio sample rate in hertz |
iCameraPos |
vec3 |
float3 |
vec3f |
Camera position in world space |
iCameraDir |
vec3 |
float3 |
vec3f |
Normalised camera look direction |
iVertexCount |
int |
uint |
u32 |
Vertices drawn by the pass: the vertices geometry's vertexCount (default 3), 3 for fullscreen, or the mesh vertex count |
iInstanceCount |
int |
uint |
u32 |
Copies of the geometry the pass draws: the geometry's instanceCount (default 1), or 1 for fullscreen |
iViewMatrix |
mat4 |
float4x4 |
mat4x4f |
The orbit camera's view matrix (world to view space) |
iProjectionMatrix |
mat4 |
float4x4 |
mat4x4f |
The orbit camera's perspective projection at the pass's aspect ratio |
iViewProjection |
mat4 |
float4x4 |
mat4x4f |
iProjectionMatrix * iViewMatrix: world space to clip space. See Camera matrices |
iInstanceIndex |
int |
uint |
u32 |
Which copy is being drawn, from 0 to iInstanceCount - 1; fragments get the value of the copy that drew them. See Instancing |
iChannel0–iChannel3 |
sampler2D (or cube/3D) |
ShaderStudioChannel2D / …Cube / …3D |
Metadata object; use iChannel0Texture and iChannel0Sampler to sample |
Input channel textures in configured slot order |
iCh0–iCh3 |
channel metadata struct | — | — | Input channel with sampler, size, playback time, and loaded state |
<name> |
named channel object | ShaderStudioChannel2D / …Cube / …3D |
Metadata object; use <name>Texture and <name>Sampler to sample |
Input channel configured with that name |
iDispatch |
— | int |
i32 |
Compute only: zero-based dispatch index |
iWorldPosition |
vec3 |
float3 |
vec3f |
Fragment only: world-space position of the fragment; zero for fullscreen geometry |
iNormal |
vec3 |
float3 |
vec3f |
Fragment only: world-space interpolated normal; zero for fullscreen geometry |
iCameraPosition |
vec3 |
float3 |
vec3f |
Fragment only: world-space camera position for mesh fragments; zero for fullscreen geometry |
iVertexUv |
vec2 |
float2 |
vec2f |
Fragment only: perspective-correct interpolated uv written by mainVertex, for every geometry and space |
iFrontFacing |
bool |
bool |
bool |
Fragment only: whether the current primitive is front-facing; always true for fullscreen geometry |
iVertexUv and iFrontFacing are available for every geometry and space. iWorldPosition, iNormal, and iCameraPosition carry values only when the pass renders 3D geometry — see Vertex Shaders.
Slang has no iChN, iChannelTime, or iChannelResolution symbols. Each
configured channel is a direct global named by its exact configuration key —
iChannel0 stays iChannel0, and a channel named noise is noise — with
metadata such as noise.size, noise.time, and noise.loaded. The former
inputs.<name> syntax was removed; only the .sha.json configuration still
uses its inputs field.
WGSL also has no iChN, iChannelTime, or iChannelResolution symbols. Its
direct channel global provides metadata such as noise.size, noise.time, and
noise.loaded; native handles are separate (noiseTexture and noiseSampler).
Use sample2D(noiseTexture, noiseSampler, uv) or the legacy
noiseSample(uv) helper. See Channels for the complete channel
API and stage-specific sampling rules.
Custom uniforms¶
Add a Script pass in the config panel to compute custom uniform values each frame from TypeScript or JavaScript:
// shader.uniforms.ts
export function uniforms(ctx: { time: number }) {
return {
uSpeed: 1.5,
uOffset: [0.1, 0.2],
};
}
Types are inferred from the return value on the first call. Supported types: float, vec2, vec3, vec4, bool — in Slang they arrive as float, float2, float3, float4, and bool; in WGSL, as f32, vec2f, vec3f, vec4f, and bool. The values are available automatically — use uSpeed and uOffset in your shader with no declaration. See The Script Pass for exporting, polling, and Node.js APIs.
Next¶
Time And Playback Controls — scrub, loop, and drive iTime
Mouse and trackpad input with iPointer¶
Use iPointer in GLSL, Slang or WGSL without declaring it. iMouse keeps its Shadertoy behavior.
| Field | Type in GLSL / Slang / WGSL | Meaning |
|---|---|---|
position |
vec2 / float2 / vec2f |
Position in canvas pixels, including hover; origin at bottom left, like iMouse.xy. Captured drags can extend outside the canvas. |
inside |
int / int / i32 |
1 inside the canvas, otherwise 0 |
held |
integer | Buttons currently held |
pressed |
integer | Buttons pressed since the previous rendered frame |
released |
integer | Buttons released since the previous rendered frame |
modifiers |
integer | Shift = 1, Ctrl = 2, Alt = 4, Meta (Cmd on Mac) = 8 |
wheel |
2D float vector | Accumulated horizontal and vertical scroll in CSS pixels |
wheelDelta |
2D float vector | Scroll since the previous rendered frame |
Button values are left = 1, right = 2, middle = 4, back = 8, forward = 16. Combine or test them with bit operations. For example, (iPointer.held & 2) != 0 tests right-click in all three languages. pressed and released can both include a button clicked between frames. Every pass sees the same frame's events. Paused previews freeze pointer uniforms along with other inputs.
Positive wheel x scrolls right and positive y scrolls down. Line-based wheel events use 16 CSS pixels per line; page-based events use the canvas's displayed dimensions. Wheel and trackpad scroll feed the shader while over the canvas. The global mouse setting below controls whether scrolling also performs its normal browser action.
The global Prevent default mouse actions setting is on by default. Over the canvas it suppresses context menus, middle-click actions, back/forward navigation and page scrolling, where the browser allows. In the browser app, open Settings and search for that label. In VS Code, search Settings for shader-studio.preview.preventMouseDefaults. Turn it off to restore those browser actions. Shaders still receive pointer buttons and scroll values in either mode. The viewer's toolbar controls remain available. This preference applies across shaders.
On macOS, Control-click is reserved for a context menu and may not expose the same events as a physical secondary click. Extra mouse buttons depend on the device, driver and browser. Trackpad pinch may arrive as scrolling with Ctrl set; it is not a separate gesture in this API. Touch has no hover; multi-touch and pen pressure are not exposed.
The browser app's Particle Swarm example uses left-drag to attract particles and right-drag to repel them. Right-click takes precedence when both buttons are held. Saved browser workspaces retain their existing shader files; import a fresh example or update your copy to try the new controls.