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.
Constructors
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.litmaterials.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
.fmatmaterial declares these withengine_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; seeGeometry.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
shaderused when this material is drawn.inherited -
setFragmentShaderName(
String name) → void -
Assigns the fragment shader by
namefrom 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
fragmentShaderand sidecarmetadata(a hot-reloaded.fmat), in place.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited