@vertex
Attribute
Marks the pipeline's vertex-stage entry point, on the function declaration: @vertex export function vs(…) { … }.
@vertex makes the function it marks the entry point of the vertex stage. The GPU calls it once per vertex of a draw.
Compare examples
Compare the three vertices of one triangle. Each call reads its own vertex index and returns its own position.
Example program@vertex
export function vs(i: builtin<"vertex_index">): vec4 {
return vec4(f32(i) - 1., 0., 0., 1.);
}
Example 1i = 0
- Result
vec4(-1, 0, 0, 1)
Example 2i = 1
- Result
vec4(0, 0, 0, 1)
Example 3i = 2
- Result
vec4(1, 0, 0, 1)
The examples are calculation models and do not run GPU work. The reference below gives the syntax of the attribute. 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 the function that places each vertex in clip space and passes values on to the fragment stage.
Inputs and limits
Write it before a top-level function declaration; the entry takes the name of the declaration. A vertex entry must produce a position: a vec4 return, or a struct field typed builtin<"position">.
For shader input rules and precision, consult WGSL and GLSL ES 3.00.
Related attributes
The signature, the sentence and any message are the compiler's own text at commit af54ddad5.
Syntax
declare function vertex(target: Function, context?: unknown): voidParameters
This decorator is written on its own and takes no arguments.
The declaration also names what the TypeScript decorator runtime hands a decorator, target and context. A call passes neither.
Description
The entry takes the function's name.
Examples
gallery/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/array-literal-ramp/array-literal-ramp.shade.tsgallery/array-methods/array-methods.shade.tsgallery/bare-position/bare-position.shade.tsgallery/bit-bump/bit-bump.shade.tsgallery/bitfield-bands/bitfield-bands.shade.tsgallery/block-scope/block-scope.shade.tsgallery/bool-select/bool-select.shade.tsgallery/class-builder/class-builder.shade.tsgallery/class-parts/class-parts.shade.tsgallery/class-syntax/class-syntax.shade.tsgallery/clip-planes/clip-planes.shade.tsgallery/closures/closures.shade.tsgallery/convert-grid/convert-grid.shade.tsgallery/cube-array-gather/cube-array-gather.shade.tsgallery/cube-env/cube-env.shade.tsgallery/cutout/cutout.shade.tsgallery/default-args/default-args.shade.tsgallery/feedback-trail/feedback-trail.shade.tsgallery/generic-class/generic-class.shade.tsgallery/generic-helpers/generic-helpers.shade.tsgallery/gradient-twin/gradient-twin.shade.tsgallery/hello/hello.shade.tsgallery/hello-uniform/hello-uniform.shade.tsgallery/hello-uniform-struct/hello-uniform-struct.shade.tsgallery/hello-vsin/hello-vsin.shade.tsgallery/hello-vsout/hello-vsout.shade.tsgallery/higher-order/higher-order.shade.tsgallery/id-pick/id-pick.shade.tsgallery/imported-noise/imported-noise.shade.tsgallery/inferred-returns/inferred-returns.shade.tsgallery/integer-math/integer-math.shade.tsgallery/loops-over-data/loops-over-data.shade.tsgallery/mixin-surface/mixin-surface.shade.tsgallery/module-const/module-const.shade.tsgallery/msaa-resolve/msaa-resolve.shade.tsgallery/normal-matrix/normal-matrix.shade.tsgallery/null-values/null-values.shade.tsgallery/optional-fields/optional-fields.shade.tsgallery/optional-values/optional-values.shade.tsgallery/orbit-inout/orbit-inout.shade.tsgallery/packed-bytes/packed-bytes.shade.tsgallery/packing-bitcast/packing-bitcast.shade.tsgallery/palette-const/palette-const.shade.tsgallery/pick-composite/pick-composite.shade.tsgallery/private-state/private-state.shade.tsgallery/ray-class/ray-class.shade.tsgallery/reference-parameters/reference-parameters.shade.tsgallery/rng-method/rng-method.shade.tsgallery/sample-branch/sample-branch.shade.tsgallery/separable-blur/separable-blur.shade.tsgallery/shadow-compare/shadow-compare.shade.tsgallery/shape-inheritance/shape-inheritance.shade.tsgallery/textured-quad/textured-quad.shade.tsgallery/tuple-and-brand/tuple-and-brand.shade.tsgallery/twin-structs/twin-structs.shade.tsgallery/uniform-array/uniform-array.shade.ts