MaterialBuilder

MaterialBuilder compiles Filament material source code into binary packages.

MaterialBuilder takes high-level material definitions and generates optimized shaders for multiple backends (OpenGL, Vulkan, Metal, WebGPU). The resulting MaterialPackage can be loaded by Filament's Material system.

Initialization: Call MaterialBuilder.init before building any material, and MaterialBuilder.shutdown when finished.

Compilation: Configure material properties using methods like name(), shading(), blendingMode(), etc., then call build() to generate the package.

See also

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
data class Attribute(val name: String, val type: MaterialBuilder.UniformType, val location: VertexBuffer.VertexAttribute, val attributeName: String, val defineName: String)

A vertex attribute a material can require: its name, shader type and slot, and the names shaders use for it (attributeName, e.g. mesh_uv0, and defineName, e.g. HAS_ATTRIBUTE_UV0).

Link copied to clipboard
Link copied to clipboard

Blending modes determine how material color combines with background color.

Link copied to clipboard
object Companion
Link copied to clipboard

Type of a specialization constant.

Link copied to clipboard

Which triangle faces are culled before rasterization.

Link copied to clipboard

Vertex attribute interpolation in the fragment shader.

Link copied to clipboard

Which pipeline stage the material targets.

Link copied to clipboard

Shader optimization level applied at compile time.

Link copied to clipboard

Attachment a post-process output writes.

Link copied to clipboard

Type of a post-process output.

Link copied to clipboard

Precision level for numeric parameters.

Link copied to clipboard

Platform class to generate shaders for.

Link copied to clipboard

Source of reflections for the material.

Link copied to clipboard

Source of refracted light for refractive materials.

Link copied to clipboard

Geometry model used to compute refraction.

Link copied to clipboard

Data format for sampler parameters.

Link copied to clipboard

Sampler types for texture parameters.

Link copied to clipboard

Shader quality: lower trades accuracy for speed. DEFAULT picks per platform.

Link copied to clipboard

A shader stage, for the stages a sampler parameter is visible to.

Link copied to clipboard

Shading model determines how light interacts with the material surface.

Link copied to clipboard

How ambient occlusion is applied to specular indirect lighting.

Link copied to clipboard

Graphics API(s) to generate shaders for.

Link copied to clipboard
Link copied to clipboard

Uniform variable types in material parameters.

Link copied to clipboard

Custom vertex attribute variable slots.

Link copied to clipboard

Qualifier of a post-process output.

Link copied to clipboard

Coordinate space the vertex shader's material() output is expressed in.

Link copied to clipboard

Driver workarounds baked into the shaders.

Functions

Link copied to clipboard

Converts fragment alpha to MSAA coverage; smoother BlendingMode.MASKED edges under MSAA.

Link copied to clipboard

Sets how the material blends with the render target (BlendingMode.OPAQUE by default).

Link copied to clipboard

Compiles the material and returns the resulting package (check MaterialPackage.isValid before use).

Link copied to clipboard
fun clearCoatIorChange(clearCoatIorChange: Boolean): MaterialBuilder

Makes the clear coat layer's IOR affect the base layer (physically correct; default: true).

Link copied to clipboard
fun coloredPenumbra(coloredPenumbra: Boolean): MaterialBuilder

Enables colored shadow penumbras for this material's transparent shadows.

Link copied to clipboard

Enables/disables writes to the color buffer (default: true).

Link copied to clipboard

Records the compiler parameters (matc's command line) in the package.

Link copied to clipboard

Declares a specialization constant with its default value, settable per material instance.

Link copied to clipboard

Sets face culling (CullingMode.BACK by default).

Link copied to clipboard
fun customSurfaceShading(customSurfaceShading: Boolean): MaterialBuilder

Enables custom surface shading: the material provides its own surfaceShading() function.

Link copied to clipboard

Enables/disables depth testing (default: true).

Link copied to clipboard

Enables/disables writes to the depth buffer (default: true, except for blended modes).

Link copied to clipboard

Renders both faces and flips the normal on back faces; implies CullingMode.NONE.

Link copied to clipboard

Lets post-process materials read the framebuffer they write.

Link copied to clipboard

Sets the minimum feature level the material needs.

Link copied to clipboard

Flips the V texture coordinate at compile time (default: true, matching Filament's convention).

Link copied to clipboard
fun generateDebugInfo(generateDebugInfo: Boolean): MaterialBuilder

Includes debug info in the generated SPIR-V.

Link copied to clipboard

Sets a compute material's work group size.

Link copied to clipboard

Also generates ESSL 1.0 shaders, for feature level 0.

Link copied to clipboard

Enables instanced rendering: shaders get the instance index.

Link copied to clipboard

Sets the interpolation of the shading normal (default: SMOOTH).

Link copied to clipboard

Computes fog linearly rather than exponentially, a cheaper approximation.

Link copied to clipboard

Sets the alpha cutoff for BlendingMode.MASKED (default: 0.4).

Link copied to clipboard
fun material(code: String, line: Int = 0): MaterialBuilder

Sets the fragment-stage code, a GLSL void material(inout MaterialInputs); line is its first line in the source, for error messages.

Link copied to clipboard

Sets the material domain (MaterialDomain.SURFACE by default).

Link copied to clipboard

Records the material's .mat source in the package.

Link copied to clipboard
fun materialVertex(code: String, line: Int = 0): MaterialBuilder

Sets the vertex-stage code, a GLSL void materialVertex(inout MaterialVertexInputs); line as in material.

Link copied to clipboard

Simulates extra light bounces in occluded areas to reduce over-darkening from AO.

Link copied to clipboard

Sets the material's name (shown in tooling and debug output).

Link copied to clipboard

Skips validating samplers against the feature level's limits.

Link copied to clipboard

Sets the shader optimization level (Optimization.PERFORMANCE by default).

Link copied to clipboard

Adds a fragment shader output; post-process materials only. location -1 lets filamat pick.

Link copied to clipboard
fun parameter(name: String, type: MaterialBuilder.UniformType, precision: MaterialBuilder.ParameterPrecision = ParameterPrecision.DEFAULT): MaterialBuilder

Declares a uniform parameter, settable via MaterialInstance.setParameter.

fun parameter(name: String, size: Int, type: MaterialBuilder.UniformType, precision: MaterialBuilder.ParameterPrecision = ParameterPrecision.DEFAULT): MaterialBuilder

Declares a uniform array parameter of size elements.

fun parameter(name: String, samplerType: MaterialBuilder.SamplerType, format: MaterialBuilder.SamplerFormat = SamplerFormat.FLOAT, precision: MaterialBuilder.ParameterPrecision = ParameterPrecision.DEFAULT, filterable: Boolean = true, multisample: Boolean = false, transformName: String = "", stages: Set<MaterialBuilder.ShaderStage>? = null): MaterialBuilder

Declares a texture sampler parameter, settable via MaterialInstance.setParameter. transformName names a mat3 uniform transforming its UVs; stages limits the shader stages that see it (all when null).

Link copied to clipboard

Selects the platform class to generate shaders for (Platform.ALL to cover everything).

Link copied to clipboard

Sets how the post-lighting color blends with the lit result.

Link copied to clipboard

Prints the generated shaders to the log.

Link copied to clipboard

Sets the shader quality (ShaderQuality.DEFAULT by default).

Link copied to clipboard

Sets where reflections are sampled from (ReflectionMode.DEFAULT by default).

Link copied to clipboard

Sets where refracted light is sampled from (RefractionMode.NONE by default).

Link copied to clipboard

Sets the refraction geometry model (RefractionType.SOLID by default).

Link copied to clipboard

Requires the given vertex attribute to be present in rendered geometry (e.g. UV1, COLOR).

Link copied to clipboard
fun saveRawVariants(saveRawVariants: Boolean): MaterialBuilder

Saves each variant's raw shader text, for debugging.

Link copied to clipboard

Sets the API level the material is compiled against (default: 1).

Link copied to clipboard

Adds a preprocessor define to the material's shader code.

Link copied to clipboard

Sets the shading model (LIT, UNLIT, SUBSURFACE, CLOTH, SPECULAR_GLOSSINESS).

Link copied to clipboard

Fades shadows out towards the shadow far plane.

Link copied to clipboard
fun shadowMultiplier(shadowMultiplier: Boolean): MaterialBuilder

UNLIT only: multiplies the final color by the shadowing factor, for shadow-receiver planes.

Link copied to clipboard

Sets how AO is applied to specular lighting (SpecularAmbientOcclusion.NONE by default).

Link copied to clipboard
fun specularAntiAliasing(specularAntiAliasing: Boolean): MaterialBuilder

Reduces specular shimmering/aliasing on curved geometry (LIT models only).

Link copied to clipboard

Clamping threshold of the specular AA roughness increase, in [0, 1] (default: 0.2).

Link copied to clipboard

Screen-space variance of the specular AA filter kernel, in [0, 1] (default: 0.15).

Link copied to clipboard

Sets how many eyes stereoscopic rendering draws.

Link copied to clipboard

Sets the stereoscopic technique the shaders support.

Link copied to clipboard

Selects the graphics API(s) to generate shaders for; fewer APIs → smaller package.

Link copied to clipboard

Sets the transparency rendering strategy (TransparencyMode.DEFAULT by default).

Link copied to clipboard
fun transparentShadow(transparentShadow: Boolean): MaterialBuilder

Makes this transparent material cast (dithered) transparent shadows.

Link copied to clipboard

Uses Filament's default depth variant, skipping a custom vertex shader in depth-only passes.

Link copied to clipboard

Uses the legacy (non-CPU-skinning-aware) morph target implementation.

Link copied to clipboard

Names a custom interpolant (Variable slot) passed from the vertex to the fragment stage.

Names a custom interpolant with an explicit precision.

Link copied to clipboard
fun variantFilter(variantFilter: Int): MaterialBuilder

Bitmask of shader variants to exclude from compilation, shrinking the package.

Link copied to clipboard

Sets the coordinate space of the vertex output (VertexDomain.OBJECT by default).

Link copied to clipboard

Applies the view's TAA jitter to VertexDomain.DEVICE positions.

Link copied to clipboard

Sets the driver workarounds baked into the shaders.