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:
Constructors
-
MaterialParameters.fromMetadata(Shader shader, Map<
String, Object?> metadata) -
Builds parameters from a shader's reflection plus a
.fmatsidecar 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 {}}) -
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
- 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, HostBuffer transientsBuffer) → void -
Binds the uniform block and the sampler parameters on
shaderintopass. -
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_colorhint, the rgb channels are sRGB-decoded to linear (matching the shader'sSRGBToLinear); 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
shaderandmetadata(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.