voxelSurface

Rebuild the shape from blocks and shade each block with your surface.

voxelSurface(spec: VoxelSurfaceSpec): ShapedSurfaceEffect

Import voxels from shaders/std and use voxels.voxelSurface.

Returns {extraFields, compute, gpu} to spread into a shape-effect definition. Your props must include the standard shape props (center, scale, rotation, shape, shapeSdfUrl, shapeType), a shadows amount (0–1) and everything the spec names. Your surface gets a VoxelFrame per block and returns vec4(rgb, vox.coverage). Geometry props re-build the model when they change. Color and light props never do.

Parameters

NameTypeNotes
specVoxelSurfaceSpec

Example

...voxelSurface({style: p('voxelShape'), gridSpace: p('gridSpace'), voxelSize: p('voxelSize'), fill: p('fill'), voxelScale: p('voxelScale'), bevel: p('bevel'), shadowSoftness: p('shadowSoftness'), lightAngle: p('lightAngle'), lightElevation: p('lightElevation'), depth: p('depth'), surface: (vox, frame, params) => math.vec4(shade(vox), vox.coverage)})

Tip. Light with materials.lambert(vox.normal, L, {wrap: 0.12}) times 1 − vox.shadow · shadows and the blocks read as solid.

See also

  • shapedSurface — Turns a shape prop into a surface your material shades.
  • lambert — How much a light falls on a surface: 0 facing away, 1 facing it.

Used by

Voxels