Skip to content

Vertex

A single vertex: a required 2D or 3D position plus any per-vertex attributes your shader declares (commonly uv and color, but any key the shader’s vertex stage reads is fair game). Build vertices and feed them into a Mesh to draw.

use fragmentcolor::mesh::Vertex;
let v = Vertex::new([0.0, 0.0, 0.0]).set("uv", [0.5, 0.5]);

Construct a Vertex from a 2D or 3D position. Set additional attributes (uv, color, custom keys) with set to match the per-vertex inputs your shader declares.

use fragmentcolor::mesh::Vertex;
let v = Vertex::new([0.0, 0.0]);

Attach an arbitrary property to the vertex.

Locations and mapping:

  • When you call set(key, value) for the first time for a given key, the Vertex assigns the next available @location(N) to that property (starting after position). Subsequent calls reuse the same location.
  • At render time, shader vertex inputs (declared with @location(N)) are derived from the Shader and matched to Vertex/Instance properties by:
    1. explicit location (instance first, then vertex), then
    2. name (instance first, then vertex).
  • There is no special-case for location(0) in the mapping; position is just another vertex attribute exposed as position with a 2- or 3-component format depending on how you constructed the Vertex.

Planned explicit control:

  • You will be able to pin a property to a specific location using a fluent API: vertex.set(key, value).at(index).
  • Vertex construction may also support Vertex::from_shader(&Shader) to derive an initial layout directly from the shader AST.
use fragmentcolor::mesh::{Vertex, VertexValue};
let v = Vertex::new([0.0, 0.0, 0.0]).set("weight", 1.0).set("color",[1.0, 0.0, 0.0]);

Create an Instance that inherits this vertex’s attributes. Use this when you want a starting point for an instance whose per-instance values mostly match the source vertex, then call set on the result to change the fields that differ.

use fragmentcolor::mesh::Vertex;
let v = Vertex::new([0.0, 0.0]);
let inst = v.create_instance();
1 collapsed line
_ = inst;