Materials
The MaterialService manages the lifecycle and data of materials. A Material is an instance of a shader with specific property values.
Architecture
Section titled “Architecture”Material Instance
Section titled “Material Instance”A lightweight object holding:
- Reference to a
ShaderVariantSet. - Property Block: Uniform data (colors, floats) matching the shader’s uniform buffer.
- Texture Bindings: References to
GpuTextureobjects.
Handle-Based Safety
Section titled “Handle-Based Safety”Materials use a Handle-Slot pattern.
- Materials are stored in a fixed-size pool.
- References (
RefObject<Material>) store a handle with a Generation ID. - This prevents use-after-free bugs if a material is destroyed and its slot is reused.
Network Integration
Section titled “Network Integration”- Texture Loading: Texture AssetIDs are resolved asynchronously via
TextureService.
graph TD
Data["MaterialData (Canvas)"] --> Service[MaterialService]
Service --> Create["Allocate Material Slot"]
Create --> Resolve["Resolve Textures"]
Resolve --> Check{"In Cache?"}
Check -->|Yes| Bind[Bind GpuTexture]
Check -->|No| Fetch["AssetLoader (Details)"]
Fetch --> Decode["Decode & Upload"]
Decode --> Bind