MaterialParameters class Materials

Type-checked, name-addressed parameters for a custom material.

Parameters are set by name. The declared type comes from the material's sidecar metadata, and byte offsets come from the compiled shader's reflection, so callers never compute std140 padding and a wrong-typed value throws instead of silently corrupting the uniform block. Three tiers of access share one backing buffer:

Typed getters (getFloat, getVec4, getColor, ...) mirror the setters and read back the effective value, the explicitly assigned value if set, otherwise the sidecar default. getParameter is the type-erased equivalent, and parameters enumerates every declared parameter.

Constructors

MaterialParameters.fromMetadata(Shader shader, Map<String, Object?> metadata)
Builds parameters from a shader's reflection plus a .fmat sidecar entry.
factory
MaterialParameters.withLayout({required String blockName, required int blockSizeBytes, required Map<String, ({int offset, bool sourceColor, FmatType type})> parameters, Map<String, FmatHintKind?> samplers = const {}, Map<String, Object> defaults = const {}})
Builds parameters from an explicit layout, without shader reflection. Primarily for tests and advanced callers.
factory

Properties

assignedValues Map<String, Object>
The values explicitly assigned through the typed setters, keyed by parameter name, as last set (vectors and matrices are stored as defensive copies; textures appear as their live gpu.Texture). Sidecar defaults are not included. Used by the scene serializer to round-trip parameter overrides.
no setter
hashCode int
The hash code for this object.
no setterinherited
parameterNames Iterable<String>
The names of the scalar/vector parameters in this material.
no setter
parameters Iterable<({Object? defaultValue, String name, String type})>
Every declared scalar/vector parameter (not samplers, see samplerNames), with its GLSL type spelling and sidecar-declared default (null if none was declared).
no setter
rawBlock ByteData
The raw uniform-block bytes, for the hot-loop escape hatch. Pair with offsetOf; you own correctness (type and std140 layout) here.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
samplerNames Iterable<String>
The names of the sampler parameters in this material.
no setter

Methods

bind(RenderPass pass, Shader shader, TransientWriter transientsBuffer) → void
Binds the uniform block and the sampler parameters on shader into pass.
bindUniformBlock(RenderPass pass, Shader shader, TransientWriter transientsBuffer) → void
Binds only the MaterialParams uniform block on shader into pass, not the sampler parameters. Used to make the block available to the vertex stage, whose generated shader declares the block but not the material's samplers.
copyStateFrom(MaterialParameters other) → void
Copies the full parameter state (block bytes, explicit-set tracking, and sampler bindings) from other, which must have been built from the same compiled shader entry so the layouts agree. The editor uses this to apply a re-realized material onto the live instance in place.
getColor(String name) Color
Effective value of a vec4 parameter as a Color, the assigned value if set, otherwise the sidecar default. For a source_color-hinted parameter the rgb channels are sRGB-encoded back from the stored linear value, the inverse of setColor; alpha is read as-is. A non-source_color parameter reads its raw channels unencoded. Throws on an unknown name or wrong type.
getFloat(String name) double
Effective value of a float parameter, the assigned value if set, otherwise the sidecar default. Throws on an unknown name or wrong type.
getInt(String name) int
Effective value of an int parameter, the assigned value if set, otherwise the sidecar default. Throws on an unknown name or wrong type.
getMat4(String name) → Matrix4
Effective value of a mat4 parameter, the assigned value if set, otherwise the sidecar default. Throws on an unknown name or wrong type.
getParameter(String name) Object
Effective value of a declared parameter, boxed as double, int, Vector2, Vector3, Vector4, or Matrix4 matching its declared type. For samplers use getTexture. Throws on an unknown name.
getTexture(String name) Texture?
The texture bound to sampler name, or null when unset. The engine binds the declared placeholder at draw time for an unset sampler, so that placeholder is never surfaced here. Throws on an unknown sampler name.
getVec2(String name) → Vector2
Effective value of a vec2 parameter, the assigned value if set, otherwise the sidecar default. Throws on an unknown name or wrong type.
getVec3(String name) → Vector3
Effective value of a vec3 parameter, the assigned value if set, otherwise the sidecar default. Throws on an unknown name or wrong type.
getVec4(String name) → Vector4
Effective value of a vec4 parameter, the assigned value if set, otherwise the sidecar default. Throws on an unknown name or wrong type.
hasParameter(String name) bool
Whether a scalar/vector parameter named name is declared.
hasSampler(String name) bool
Whether a sampler parameter named name is declared.
isParameterAssigned(String name) bool
Whether name was explicitly set on this instance, as opposed to left at the sidecar default. Throws ArgumentError if name is not a declared parameter.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
offsetOf(String name) int
The std140 byte offset of name, or throws if it is unknown.
setColor(String name, Color color) → void
Sets a vec4 parameter from a Color. If the parameter has a source_color hint, the rgb channels are sRGB-decoded to linear (matching the shader's SRGBToLinear); alpha is written as-is.
setFloat(String name, double value) → void
setInt(String name, int value) → void
setMat4(String name, Matrix4 value) → void
setTexture(String name, Texture texture, {SamplerOptions? sampler}) → void
setVec2(String name, Vector2 value) → void
setVec3(String name, Vector3 value) → void
setVec4(String name, Vector4 value) → void
toString() String
A string representation of this object.
inherited
updateFromLayout({required String blockName, required int blockSizeBytes, required Map<String, ({int offset, bool sourceColor, FmatType type})> parameters, Map<String, Object> defaults = const {}, Map<String, FmatHintKind?> samplers = const {}}) → void
Test hook mirroring updateFromMetadata but with an explicit reflected layout, so the value-preservation logic can be exercised without a GPU shader (see withLayout).
updateFromMetadata(Shader shader, Map<String, Object?> metadata) → void
Re-reads parameter declarations from a regenerated shader and metadata (a hot-reloaded .fmat), preserving values the caller explicitly set.

Operators

operator ==(Object other) bool
The equality operator.
inherited
operator []=(String name, Object value) → void
Dynamic, type-checked assignment. Dispatches on the parameter's declared type and throws if value's runtime type does not match.