uniform
Function
A uniform declaration describes data supplied by the host and shared by shader invocations during a draw or dispatch.
Compare examples
The shader reads the parameter value supplied by the host. Declaring a uniform does not upload the value.
Model assumptionsclass Params { scale: f32; }
declare const u: uniform<Params>;
Example 1host: u.scale = 1; shader: u.scale
- Result
1
Example 2host: u.scale = 2; shader: u.scale
- Result
2
Example 3host: u.scale = 0; shader: u.scale
- Result
0
The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.
When to use it
Use it for passing camera settings, dimensions, and other small parameters.
Inputs and limits
The declaration does not upload data. The host must allocate, bind, and populate a buffer with the reflected layout. Shaders cannot write a uniform binding.
For shader input rules and precision, consult WGSL and GLSL ES 3.00.
Related functions
The signature, the sentence and any message are the compiler's own text at commit af54ddad5.
Declares a uniform binding of type T; use declare const name: uniform<T> or const name = uniform<T>().
Syntax
declare function uniform<T>(slot?: number | { group?: number; binding?: number }, binding?: number): ReadView<T>A number in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.
type f32 = number & { readonly [f32Tag]?: true }
A number you write as a type is inferred from its uses, and f32, i32 and u32 fix a width; the TypeScript constructs page carries that row with the compiler's emit.
A signature may name a type the ambient file declares for its own use. These are those declarations.
ReadViewtype ReadView<T> = T extends number | boolean ? T : T extends (...args: never[]) => unknown ? T : { readonly [K in keyof T]: K extends string | number ? ReadView<T[K]> : T[K] }
Parameters
-
slotoptionalnumber | { group?: number; binding?: number } -
bindingoptionalnumber
Return value
ReadView<T>
Examples
path/uv-gradient/uv-gradient.shade.tspath/moving-wave/moving-wave.shade.tspath/sdf-shapes/sdf-shapes.shade.tspath/tile-pattern/tile-pattern.shade.tspath/fractal/fractal.shade.tspath/palette/palette.shade.tspath/bouncing-balls/bouncing-balls.shade.tspath/image-blur/image-blur.shade.tspath/ray-tracer/ray-tracer.shade.tsgallery/capsule-corp-namek-class/capsule-corp-namek-class.shade.tsgallery/domain-warp-twin/domain-warp-twin.shade.tsgallery/hillshade-twin/hillshade-twin.shade.tsgallery/julia-twin/julia-twin.shade.tsgallery/kaleidoscope-twin/kaleidoscope-twin.shade.tsgallery/mandelbrot-twin/mandelbrot-twin.shade.tsgallery/ocean-twin/ocean-twin.shade.tsgallery/path-tracer/path-tracer.shade.tsgallery/plasma-twin/plasma-twin.shade.tsgallery/rt-renderer-class/rt-renderer-class.shade.tsgallery/starfield-twin/starfield-twin.shade.tsgallery/tunnel-twin/tunnel-twin.shade.tsgallery/voronoi-twin/voronoi-twin.shade.tsgallery/fp64-burning-ship-twin/fp64-burning-ship-twin.shade.tsgallery/fp64-cancellation-twin/fp64-cancellation-twin.shade.tsgallery/fp64-checker-plane-twin/fp64-checker-plane-twin.shade.tsgallery/fp64-clock-twin/fp64-clock-twin.shade.tsgallery/fp64-deep-zoom-twin/fp64-deep-zoom-twin.shade.tsgallery/fp64-julia-twin/fp64-julia-twin.shade.tsgallery/fp64-lane-stripes/fp64-lane-stripes.shade.tsgallery/fp64-loran-twin/fp64-loran-twin.shade.tsgallery/fp64-mandelbrot-de-twin/fp64-mandelbrot-de-twin.shade.tsgallery/fp64-newton-twin/fp64-newton-twin.shade.tsgallery/fp64-rtc-twin/fp64-rtc-twin.shade.tsgallery/fp64-sine-sweep-twin/fp64-sine-sweep-twin.shade.tsgallery/bit-bump/bit-bump.shade.tsgallery/clip-planes/clip-planes.shade.tsgallery/compute-reduction-twin/compute-reduction-twin.shade.tsgallery/gradient-twin/gradient-twin.shade.tsgallery/hello-camera/hello-camera.shade.tsgallery/hello-uniform/hello-uniform.shade.tsgallery/hello-uniform-struct/hello-uniform-struct.shade.tsgallery/imported-noise/imported-noise.shade.tsgallery/integer-math/integer-math.shade.tsgallery/loops-over-data/loops-over-data.shade.tsgallery/normal-matrix/normal-matrix.shade.tsgallery/packed-bytes/packed-bytes.shade.tsgallery/particle-step/particle-step.shade.tsgallery/sample-branch/sample-branch.shade.tsgallery/separable-blur/separable-blur.shade.tsgallery/uniform-array/uniform-array.shade.tsgallery/workgroup-tile-2d/workgroup-tile-2d.shade.ts