rasterize
Draw a grid's cells as a sheet of triangles into a texture.
rasterize(
grid: GridSim | InputNode,
opts: {scale?: number; holes?: string} = {},
): RasterizeInput
Import rasterize from shaders/std.
Each cell of grid holds a position: .xy in uv, .z depth (0 nearest, 1 farthest). Read name(uv): .xy the sheet's own coordinate at this pixel (0–1 across the grid: cell c sits at vec2f(c) / vec2f(gridSize - 1)), .z depth, .w 1 where the sheet covers the pixel; and name.normal(uv).xyz, the facing direction (toward the viewer, in true proportions on any frame shape). Give the grid precision: 'full' when cells hold positions: half precision rounds a cloth's small per-frame moves to nothing. holes is WGSL returning false for cells to leave out (tears, cut-outs; it sees cell and cellUV).
Parameters
| Name | Type | Notes |
|---|---|---|
grid | GridSim | InputNode | |
opts | {scale?: number; holes?: string} | Optional. Default {}. |
Example
const cloth = simulate.grid({resolution: [64, 48], history: 2, init: wgsl`return vec4f(cellUV, 0.5, 0.0);`, step: [op.kernel(verlet)]})
inputs: {cloth, sheet: rasterize(cloth)},
effect: wgsl`
let s = sheet(uv);
if (s.w < 0.5) { return vec4f(0.0); }
return textureSample(childTexture, childSampler, s.xy);
`,