PreprocessedMaterial class Materials

A material driven by a .fmat custom-material shader and its sidecar metadata (produced at build time by buildMaterials).

Construct one from a shader bundle entry and its metadata, then set parameters by name through parameters:

final library = (await gpu.loadShaderLibraryAsync('build/shaderbundles/materials.shaderbundle'))!;
final metadata = jsonDecode(await rootBundle.loadString(
    'build/shaderbundles/materials.fmat.json')) as Map<String, Object?>;
final toon = PreprocessedMaterial(
  fragmentShader: library['Toon']!,
  metadata: (metadata['Toon'] as Map).cast<String, Object?>(),
)..parameters.setColor('base_color', const Color(0xff8844ff));

A lit material is lit by the engine's physically based pipeline (the shader's Surface() fills the surface description); an unlit material outputs its base_color directly. The render state (blending, culling) comes from the material's metadata.

Inheritance

Constructors

PreprocessedMaterial({required Shader fragmentShader, required Map<String, Object?> metadata, Map<String, Shader>? vertexShaders})

Properties

doubleSided bool
Whether to render both faces of triangles drawn with this material (glTF's material.doubleSided). When true, bind disables back-face culling so the geometry is visible from both sides; otherwise back faces are culled. Defaults to false. The runtime importer sets it from the glTF material.
getter/setter pairinherited
environment EnvironmentMap?
Per-material image-based-lighting environment, overriding the scene-wide environment when set. Only used for FmatShadingModel.lit materials.
getter/setter pair
fragmentShader Shader
The fragment shader used when rendering geometry with this material.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
name String
The name of this material, used for identification.
getter/setter pairinherited
parameters MaterialParameters
The material's parameters, set by name. See MaterialParameters.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sceneInputs Set<RenderInput>
Per-frame engine inputs this material samples, produced only when a visible material asks for them: RenderInput.depth binds the linear scene depth of the opaque geometry (forcing the depth prepass), and RenderInput.opaqueSceneColor binds a snapshot of the scene color taken after the opaque phase (splitting the scene pass in two). Together they enable refraction, depth-fade absorption, shoreline foam, and soft-particle style effects on translucent surfaces. The base material requests nothing; a .fmat material declares these with engine_inputs:.
no setteroverride
shadingModel → FmatShadingModel
Whether the engine runs its lighting (FmatShadingModel.lit) or the shader's color is output directly (FmatShadingModel.unlit).
no setter

Methods

bind(RenderPass pass, TransientWriter transientsBuffer, Lighting lighting) → void
Binds this material's render-pass state, uniforms, and textures.
override
bindVertexStage(RenderPass pass, Shader vertexShader, TransientWriter transientsBuffer) → void
Binds this material's vertex-stage uniforms to vertexShader, called by the encoder only when it used a material-supplied vertex shader (see materialVertexShader). The base implementation is a no-op; a material with vertex-stage parameters binds them here.
isOpaque() bool
Whether geometry rendered with this material is fully opaque.
override
materialVertexShader(String variant) Shader?
The vertex shader this material supplies for a geometry's variant ('unskinned' / 'skinned' for the color pass, 'depth' for the position-only depth/shadow pass; see Geometry.materialVertexVariant), or null to use the engine's standard vertex shader for the geometry.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
setFragmentShader(Shader shader) → void
Assigns the fragment shader used when this material is drawn.
inherited
setFragmentShaderName(String name) → void
Assigns the fragment shader by name from baseShaderLibrary.
inherited
toString() String
A string representation of this object.
inherited
updateFromMetadata(Shader fragmentShader, Map<String, Object?> metadata) → void
Re-reads the render state and parameters from a regenerated fragmentShader and sidecar metadata (a hot-reloaded .fmat), in place.

Operators

operator ==(Object other) bool
The equality operator.
inherited