MaterialInstance

class MaterialInstance(nativeHandle: NativePointer)

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

Constructors

Link copied to clipboard
constructor(nativeHandle: NativePointer)

Types

Link copied to clipboard

Element types for boolean parameter arrays.

Link copied to clipboard
object Companion
Link copied to clipboard

Element types for floating-point parameter arrays.

Link copied to clipboard

Element types for integer parameter arrays.

Link copied to clipboard

Which face(s) the stencil operation applies to.

Link copied to clipboard

Stencil test operation determines how the stencil buffer is modified.

Link copied to clipboard

Element types for unsigned integer parameter arrays, passed as IntArray bit patterns.

Properties

Link copied to clipboard

Gets/sets the face culling mode, for both the color and shadow passes.

Link copied to clipboard

Gets/sets the depth function.

Link copied to clipboard

Gets/sets whether color write is enabled.

Link copied to clipboard

Gets/sets whether depth culling (depth testing) is enabled.

Link copied to clipboard

Gets/sets whether depth write is enabled.

Link copied to clipboard

Gets/sets whether double-sided lighting is enabled.

Link copied to clipboard

Gets/sets whether stencil write is enabled.

Link copied to clipboard

Gets/sets the alpha mask threshold for masked blending mode.

Link copied to clipboard

The Material associated with this instance.

Link copied to clipboard

The name associated with this instance.

Link copied to clipboard

The native object, for interop with code calling the Fila* C API directly. Read-only: this wrapper owns it.

Link copied to clipboard

The face culling mode for the shadow passes.

Link copied to clipboard

Gets/sets the clamping threshold used to suppress estimation errors when applying specular anti-aliasing.

Link copied to clipboard

Gets/sets the screen space variance of the filter kernel used when applying specular anti-aliasing.

Link copied to clipboard

Gets/sets the transparency rendering mode.

Functions

Link copied to clipboard
fun commit(engine: Engine)

Uploads this instance's pending parameter changes. The engine does this for every instance it renders; call it for instances only used outside of rendering, e.g. by compute.

Link copied to clipboard
fun compile(priority: Material.CompilerPriorityQueue, variants: Int = UserVariantFilterBit.ALL, callback: (MaterialInstance) -> Unit? = null)

Asynchronously ensures that a subset of this MaterialInstance's variants are compiled, taking its specialization constants into account.

Link copied to clipboard

Returns the boolean value of a specialization constant.

Link copied to clipboard

Returns the float value of a specialization constant.

Link copied to clipboard

Returns the integer value of a specialization constant.

Link copied to clipboard

Gets the value of a float parameter.

Gets the value of an integer parameter.

Gets the value of an unsigned integer parameter.

Link copied to clipboard
fun setConstant(name: String, value: Boolean)
fun setConstant(name: String, value: Float)

fun setConstant(name: String, value: Int)

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.

Link copied to clipboard
fun setCullingMode(colorPassCullingMode: Material.CullingMode, shadowPassCullingMode: Material.CullingMode)

Sets different culling modes for color and shadow passes.

Link copied to clipboard
fun setParameter(name: String, x: Boolean)

Sets a boolean parameter.

fun setParameter(name: String, x: Float)

Sets a float parameter.

fun setParameter(name: String, x: Int)

Sets an integer parameter.

fun setParameter(name: String, x: UInt)

Sets an unsigned integer parameter.

fun setParameter(name: String, texture: Texture?, sampler: TextureSampler)

Sets a texture parameter with sampler configuration.

fun setParameter(name: String, x: Boolean, y: Boolean)

Sets a 2-component boolean vector parameter.

fun setParameter(name: String, x: Float, y: Float)

Sets a 2-component float vector parameter.

fun setParameter(name: String, x: Int, y: Int)

Sets a 2-component integer vector parameter.

fun setParameter(name: String, x: UInt, y: UInt)

Sets a 2-component unsigned integer vector parameter.

fun setParameter(name: String, x: Boolean, y: Boolean, z: Boolean)

Sets a 3-component boolean vector parameter.

fun setParameter(name: String, x: Float, y: Float, z: Float)

Sets a 3-component float vector parameter.

fun setParameter(name: String, x: Int, y: Int, z: Int)

Sets a 3-component integer vector parameter.

fun setParameter(name: String, x: UInt, y: UInt, z: UInt)

Sets a 3-component unsigned integer vector parameter.

fun setParameter(name: String, element: MaterialInstance.BooleanElement, v: BooleanArray, offset: Int, count: Int)

Sets a parameter from a boolean array.

fun setParameter(name: String, element: MaterialInstance.FloatElement, v: FloatArray, offset: Int, count: Int)

Sets a parameter from a float array.

fun setParameter(name: String, element: MaterialInstance.IntElement, v: IntArray, offset: Int, count: Int)

Sets a parameter from an integer array.

fun setParameter(name: String, element: MaterialInstance.UIntElement, v: IntArray, offset: Int, count: Int)

Sets a parameter from an unsigned integer array.

fun setParameter(name: String, type: RgbType, r: Float, g: Float, b: Float)

Sets an RGB color parameter, converted to linear from type's space.

fun setParameter(name: String, x: Boolean, y: Boolean, z: Boolean, w: Boolean)

Sets a 4-component boolean vector parameter.

fun setParameter(name: String, x: Float, y: Float, z: Float, w: Float)

Sets a 4-component float vector parameter.

fun setParameter(name: String, x: Int, y: Int, z: Int, w: Int)

Sets a 4-component integer vector parameter.

fun setParameter(name: String, x: UInt, y: UInt, z: UInt, w: UInt)

Sets a 4-component unsigned integer vector parameter.

fun setParameter(name: String, type: RgbaType, r: Float, g: Float, b: Float, a: Float)

Sets an RGBA color parameter, converted to linear from type's space.

Link copied to clipboard
fun setPolygonOffset(scale: Float, constant: Float)

Sets a polygon offset that will be applied to all renderables drawn with this material instance.

Link copied to clipboard
fun setScissor(left: Int, bottom: Int, width: Int, height: Int)

Set-up a custom scissor rectangle; by default it is disabled.

Link copied to clipboard

Sets the stencil comparison function (default is A, always).

Link copied to clipboard

Sets the depth fail operation (default is KEEP).

Link copied to clipboard

Sets the depth-stencil pass operation (default is KEEP).

Link copied to clipboard

Sets the stencil fail operation (default is KEEP).

Link copied to clipboard
fun setStencilReadMask(readMask: Int, face: MaterialInstance.StencilFace = StencilFace.FRONT_AND_BACK)

Sets the stencil read mask (default is 0xFF).

Link copied to clipboard
fun setStencilReferenceValue(value: Int, face: MaterialInstance.StencilFace = StencilFace.FRONT_AND_BACK)

Sets the stencil reference value (default is 0).

Link copied to clipboard
fun setStencilWriteMask(writeMask: Int, face: MaterialInstance.StencilFace = StencilFace.FRONT_AND_BACK)

Sets the stencil write mask (default is 0xFF).

Link copied to clipboard

Disables the scissor box test; rendering is not restricted to any region.