API Reference

Material API

Reference for defineMaterial, resolveMaterial, and material contract types.


API contracts for material authoring and compilation boundary.

Entrypoints

Entrypoint Exports
@motion-core/motion-gpu/svelte
defineMaterial
@motion-core/motion-gpu
defineMaterial
,
resolveMaterial

defineMaterial(input)

Validates and freezes material definitions. Use this for all user-facing material creation.

Input:
FragMaterialInput

Field Type Required
fragment
string
Yes
uniforms
UniformMap
No
textures
TextureDefinitionMap
No
defines
MaterialDefines
No
includes
MaterialIncludes
No

Output:
FragMaterial

Immutable, validated object with frozen top-level maps:

  • fragment
  • uniforms
  • textures
  • defines
  • includes

signature
and preprocessed WGSL are internal runtime outputs, not public fields of
FragMaterial
.

resolveMaterial(material)

Framework-agnostic core helper that turns a validated

FragMaterial
into runtime-ready payload:

  • preprocessed WGSL source
  • uniform layout metadata
  • texture binding metadata
  • deterministic material signature

Use this in adapter implementations or low-level tooling.

Hard contracts

Contract Behavior
Fragment entrypoint must be
fn frag(uv: vec2f) -> vec4f
Throws during validation
Uniform/texture/define/include keys must be WGSL-safe identifiers Throws during validation
Matrix uniforms should use typed form
{ type: 'mat4x4f', value: [...] }
Ensures stable layout and packing

Related docs