Material is a core concept in 3D rendering that determines the visual appearance of object surfaces. In the Galacean engine, materials consist of three core components:
Shaders are programs that run on the GPU, responsible for calculating the final color of each pixel. Galacean provides a powerful shader language that allows you to:
Refer to Shader Introduction to learn about Shader syntax.
Shader data contains various parameters required for rendering, such as:
Refer to Built-in Variables Documentation to learn about available built-in variables.
Render states control how the GPU processes geometry, including:
Refer to Render States to learn about all configurable render states.
If you're not familiar with creating and using materials, you can first go to Basic Material Usage to learn the basics.
Galacean provides various ready-to-use shaders:
Shader Type | Use Case | Features |
---|---|---|
PBR | Realistic rendering | Physics-based, follows energy conservation |
Unlit | Baked models | Unaffected by lighting, excellent performance |
Blinn Phong | Classic lighting | Efficient traditional lighting model |
When built-in shaders cannot meet your needs, you can create custom shaders:
// Create material
const material = new Material(engine, shader);
// Set material properties
material.shaderData.setColor("material_BaseColor", new Color(1, 0, 0, 1));
material.shaderData.setTexture("material_BaseTexture", texture);
Want to get started quickly? Jump directly to Custom Shader Tutorial to start your first custom shader!
For more practical examples, check Online Examples.