Basic Material Usage

Creating Materials

There are generally 3 ways to create materials:

1. Manual Creation

2. Materials from Models

Refer to the Model Import and Usage tutorial. We can first import the model into the editor. Generally, the model is automatically bound with materials, and users don't need to do anything.

2.1. Remap Materials

If you want to modify model materials, we can click the duplicate and remap button to generate a copy of that material. Note that Remap will modify the model preset, and all model instances will be affected as shown below:

2.2. Incremental Modification

If you only want to modify the material of a specific model, you can use the incremental modification feature:

3. Binding Materials

We can directly drag materials into the scene to bind them.

Switching Shaders

You can select materials in the editor and switch shaders to observe real-time rendering effect changes.

Each shader has different rendering effects and application scenarios. For more details, refer to Built-in Shader Tutorial and Custom Shader Tutorial.

Creating Custom Shaders

If built-in shaders cannot meet your needs, we can create a custom shader. In the editor asset panel, create a new Shader and choose PBR template or Unlit template:

The editor will automatically help us create the Shader file and UIScript file.

For specific shader content writing, you can quickly get started with Custom Shader Tutorial.

Shader Data Transfer

Like other programming languages, we also use many variables when writing shaders. First, the engine has many built-in variables, which we don't need to set manually and can be used directly in shaders. Next, let's see how to set and use custom data.

Declaring Variables

...
Pass "Forward" {
    // Declare custom variables
    vec4 u_color;
 
    // Declare engine built-in variables
    mat4 renderer_MVPMat;
 
    // Through including code fragments
    #include "Transform.glsl"
}
...

Next Steps

Was this page helpful?