MaterialInstance
MaterialInstance customizes the parameters of a Material for per-object rendering.
Each Material can spawn multiple MaterialInstances with different parameter values (colors, textures, numeric uniforms, etc.). Changes to a MaterialInstance only affect renderables using that specific instance, not the Material or other instances.
Creating and destroying: Create instances via Material.createInstance() and destroy with Engine.destroy(instance). You can duplicate an existing instance using the companion object's duplicate() method.
Setting parameters: Use setParameter() overloads to set uniforms (booleans, floats, vectors, matrices, textures). Parameter names and types must match those defined in the material. Array parameters are also supported via setParameter(name, element, array, offset, count) variants.
Rendering state customization: Each MaterialInstance can override per-instance rendering behavior:
Scissor rectangle for pixel-perfect clipping
Polygon offset for depth artifacts
Culling mode (override material's cull setting)
Depth test configuration
Stencil test and operations
Color and depth write masks
These settings override the Material's defaults.
See also
Types
Element types for boolean parameter arrays.
Element types for floating-point parameter arrays.
Element types for integer parameter arrays.
Which face(s) the stencil operation applies to.
Stencil test operation determines how the stencil buffer is modified.
Element types for unsigned integer parameter arrays, passed as IntArray bit patterns.
Properties
Gets/sets the face culling mode, for both the color and shadow passes.
Gets/sets the depth function.
Gets/sets whether color write is enabled.
Gets/sets whether depth culling (depth testing) is enabled.
Gets/sets whether depth write is enabled.
Gets/sets whether double-sided lighting is enabled.
Gets/sets whether stencil write is enabled.
Gets/sets the alpha mask threshold for masked blending mode.
The native object, for interop with code calling the Fila* C API directly. Read-only: this wrapper owns it.
The face culling mode for the shadow passes.
Gets/sets the clamping threshold used to suppress estimation errors when applying specular anti-aliasing.
Gets/sets the screen space variance of the filter kernel used when applying specular anti-aliasing.
Gets/sets the transparency rendering mode.
Functions
Asynchronously ensures that a subset of this MaterialInstance's variants are compiled, taking its specialization constants into account.
Returns the boolean value of a specialization constant.
Returns the float value of a specialization constant.
Returns the integer value of a specialization constant.
Gets the value of a float parameter.
Gets the value of an integer parameter.
Gets the value of an unsigned integer parameter.
Sets the value of a specialization constant, overriding the Material's. Panics if the constant doesn't exist or has another type. Compiles new programs when the value changes, so prefer Material.Builder.constant where the value is known up front.
Sets different culling modes for color and shadow passes.
Sets a boolean parameter.
Sets a float parameter.
Sets an integer parameter.
Sets an unsigned integer parameter.
Sets a texture parameter with sampler configuration.
Sets a 2-component boolean vector parameter.
Sets a 2-component float vector parameter.
Sets a 2-component integer vector parameter.
Sets a 2-component unsigned integer vector parameter.
Sets a 3-component boolean vector parameter.
Sets a 3-component float vector parameter.
Sets a 3-component integer vector parameter.
Sets a 3-component unsigned integer vector parameter.
Sets a parameter from a boolean array.
Sets a parameter from a float array.
Sets a parameter from an integer array.
Sets a parameter from an unsigned integer array.
Sets an RGB color parameter, converted to linear from type's space.
Sets a 4-component boolean vector parameter.
Sets a 4-component float vector parameter.
Sets a 4-component integer vector parameter.
Sets a 4-component unsigned integer vector parameter.
Sets an RGBA color parameter, converted to linear from type's space.
Sets a polygon offset that will be applied to all renderables drawn with this material instance.
Set-up a custom scissor rectangle; by default it is disabled.
Sets the stencil comparison function (default is A, always).
Sets the depth fail operation (default is KEEP).
Sets the depth-stencil pass operation (default is KEEP).
Sets the stencil fail operation (default is KEEP).
Sets the stencil read mask (default is 0xFF).
Sets the stencil reference value (default is 0).
Sets the stencil write mask (default is 0xFF).
Disables the scissor box test; rendering is not restricted to any region.