sprite: Sprite Sheet Coordinate Extraction
Grid-based texture atlas sampling
The sprite function extracts individual sprite coordinates from a sprite sheet organized in a regular grid. Given grid dimensions and a frame index, it calculates the UV coordinates for that specific sprite:
This maps the input UV coordinates to the appropriate sprite cell within the atlas.
Grid Layout System
Parameter | Description | Range |
---|---|---|
st | Input UV coordinates | |
grid | Grid dimensions (width, height) | |
index | Sprite frame index |
ライブエディター
const fragment = () => { const tileIndex = floor(uv.x.mul(6)).add(floor(uv.y.mul(6)).mul(6)) const localUV = fract(uv.mul(6)) const spriteUV = sprite(localUV, vec2(3, 3), tileIndex.mod(9)) const gradient = length(spriteUV.sub(0.5)).mul(2) const color = mix(vec3(gradient), vec3(1).sub(gradient), step(0.5, gradient)) return vec4(color, 1) }