Overview
Filament materials are defined in.mat files using a domain-specific language that combines:
- Material properties (shading model, blending, etc.)
- Parameter definitions
- Vertex and fragment shader code
matc compiler transforms .mat files into binary material packages that can be loaded at runtime.
Material Structure
A material file has two main sections:Basic Examples
Unlit Color Material
The simplest material - displays vertex colors without lighting:Key properties:
name: Material identifierrequires: Vertex attributes needed (color, uv0, tangents, etc.)shadingModel:unlit(no lighting) orlit(with lighting)culling:none,back, orfrontfeatureLevel: Minimum feature level (0, 1, 2, or 3)
getColor() function retrieves interpolated vertex colors.PBR Material with Parameters
A physically-based material with configurable properties:Parameters are accessed via
materialParams in shader code. Set them in C++:Custom Vertex Shader
Materials can include custom vertex processing:Update time parameter each frame:
Transparent Material
Materials with alpha blending:Blending modes:
transparent: Alpha blendingadd: Additive blendingmultiply: Multiplicative blendingscreen: Screen blending
default: Single-sided, single passtwoPassesOneSide: Two passes, single-sidedtwoPassesTwoSides: Two passes, double-sided
Material Properties
Shading Models
Parameter Types
Required Attributes
Culling Modes
Depth Testing
Material Inputs
TheMaterialInputs struct contains all surface properties:
Built-in Functions
Fragment Shader
Vertex Shader
Compiling Materials
Using matc
Compile a material file:-a: API (opengl, vulkan, metal, all)-p: Platform (mobile, desktop, all)-g: Generate debug info-O: Optimization level (0-3)
CMake Integration
Loading in C++
Advanced Techniques
Material Domains
Specialize materials for specific use cases:surface(default): Standard surface materialspostprocess: Post-processing effects
Custom Interpolators
Pass custom data from vertex to fragment shader:Vertex Attribute Access
Direct access to vertex attributes:Best Practices
- Always call prepareMaterial() at the start of the material function
- Use linear color space for all color parameters
- Normalize normal maps after unpacking from textures
- Clamp PBR values to valid ranges (metallic, roughness, etc.)
- Consider mobile performance when writing complex shaders
- Use feature levels to provide fallbacks for older hardware
Debugging
Validation
Visual Debugging
Output intermediate values:Next Steps
- Explore the Material Guide for more details
- Learn about Shader Optimization
- See the Material Reference for all available options