Skip to content

Materials

Overview of Materials

Our engine adds the corresponding material object to the object through the MeshRenderer component to simulate its color, lighting, texture, etc. Currently, the engine has two built-in classic material models:

NameDescription
UnLitMaterialDoes not calculate lighting, only renders original color and texture information
LitMaterialPBR is based on physical rendering, aiming to simulate the lighting effects of the real world

We recommend that users use the glTF format file to contain the material information of the object. Users can design and modify the model file through common modeling software. After the engine parses the model file, it automatically assigns the corresponding material to the object.

Basic Usages

ts
import {Object3D. MeshRenderer, LitMaterial, SphereGeometry, Color} from '@orillusion/core'

let object = new Object3D();
// Add MeshRenderer component
let mesh = object.addComponent(MeshRenderer);

// Set material of MeshRenderer
mesh.material = new UnLitMaterial();
mesh.material.baseColor = new Color(1, 1, 1, 1);

// Switch Material
mesh.material = new LitMaterial();

Unlit Material

The engine provides the UnLitMaterial class for rendering Unlit materials.

AttributeDescription
baseColorBase color
baseMapBase map
envMapEnvironment map
shadowMapShadow map

WebGPU is not supported in your browser
Please upgrade to latest Chrome/Edge

<
ts
import { Camera3D, DirectLight, Engine3D, AtmosphericComponent, View3D, HoverCameraController, KelvinUtil, MeshRenderer, Object3D, Scene3D, SphereGeometry, UnLitMaterial, Color } from '@orillusion/core';

class Sample_Materials {
    scene: Scene3D;
    lightObj: Object3D;

    constructor() {}

    async run() {
        await Engine3D.init();
        this.scene = new Scene3D();

        let cameraObj = new Object3D();
        let mainCamera = cameraObj.addComponent(Camera3D);
        this.scene.addChild(cameraObj);
        mainCamera.perspective(60, Engine3D.aspect, 1, 5000.0);
        mainCamera.object3D.addComponent(HoverCameraController);

        await this.initScene();

        // add an Atmospheric sky enviroment
        this.scene.addComponent(AtmosphericComponent).sunY = 0.6;
        // create a view with target scene and camera
        let view = new View3D();
        view.scene = this.scene;
        view.camera = mainCamera;
        // start render
        Engine3D.startRenderView(view);
    }

    async initScene() {
        {
            this.lightObj = new Object3D();
            this.lightObj.x = 0;
            this.lightObj.y = 0;
            this.lightObj.z = 0;
            this.lightObj.rotationX = 0;
            this.lightObj.rotationY = 0;
            this.lightObj.rotationZ = 0;
            let lc = this.lightObj.addComponent(DirectLight);
            lc.lightColor = KelvinUtil.color_temperature_to_rgb(5355);
            lc.intensity = 1.7;
            this.scene.addChild(this.lightObj);
        }

        {
            // UnLitMaterial
            let sphere = new Object3D();
            let mr = sphere.addComponent(MeshRenderer);
            mr.geometry = new SphereGeometry(2.5, 30, 30);
            let mat = new UnLitMaterial();
            mat.baseColor = new Color(1, 1, 1, 1);
            mr.material = mat;
            this.scene.addChild(sphere);
            sphere.localPosition.set(0, 0, 0);
        }
    }
}

new Sample_Materials().run();

PBR Material

We recommend using the PBR material for rendering, PBR stands for Physicallly-Based Rendering, which is a material based on physical rendering. That means to be more in line with the physical lighting model of reality.

AttributeDescription
baseColorBase color
emissiveColorEmissive color
emissiveIntensityEmissive intensity, need to open BloomPost to display the glow effect
roughnessRoughness of the material
metallicMetallic of the material
normalScaleThe effect of the normal map on the material
clearCoatClear coat intensity
envMapEnvironment map
envIntensityEnvironment light intensity
materialF0Material reflectance
aoAmbient Occlussion, handles the effect of ambient light on the occlusion of objects
aoMapAmbient light occlusion map
baseMapBase map
normalMapNormal map
maskMapMask map
emissiveMapEmissive map
brdfLUTBRDF lookup table

WebGPU is not supported in your browser
Please upgrade to latest Chrome/Edge

<
ts
import { Camera3D, DirectLight, Engine3D, AtmosphericComponent, View3D, HoverCameraController, MeshRenderer, Object3D, Scene3D, SphereGeometry, LitMaterial } from '@orillusion/core';

class Sample_Materials {
    scene: Scene3D;
    lightObj: Object3D;

    constructor() {}

    async run() {
        await Engine3D.init();
        this.scene = new Scene3D();
        let cameraObj = new Object3D();
        let mainCamera = cameraObj.addComponent(Camera3D);
        this.scene.addChild(cameraObj);
        mainCamera.perspective(60, Engine3D.aspect, 1, 5000.0);
        mainCamera.object3D.addComponent(HoverCameraController);

        await this.initScene();

        // add an Atmospheric sky enviroment
        this.scene.addComponent(AtmosphericComponent).sunY = 0.6;
        // create a view with target scene and camera
        let view = new View3D();
        view.scene = this.scene;
        view.camera = mainCamera;
        // start render
        Engine3D.startRenderView(view);
    }

    async initScene() {
        {
            this.lightObj = new Object3D();
            this.lightObj.x = -20;
            this.lightObj.y = 20;
            this.lightObj.z = -20;
            this.lightObj.rotationX = 45;
            this.lightObj.rotationY = 45;
            this.lightObj.rotationZ = 0;
            let lc = this.lightObj.addComponent(DirectLight);
            lc.intensity = 0.2;
            this.scene.addChild(this.lightObj);
        }
        {
            // PRB
            let sphere = new Object3D();
            let mr = sphere.addComponent(MeshRenderer);
            mr.geometry = new SphereGeometry(2.5, 30, 30);
            let mat = new LitMaterial();
            mr.material = mat;
            this.scene.addChild(sphere);
            sphere.localPosition.set(0, 0, 0);
        }
    }
}

new Sample_Materials().run();

Material Settings

Color

ts
let mat = new UnLitMaterial();
mat.baseColor = new Color(1, 0, 0, 1);

WebGPU is not supported in your browser
Please upgrade to latest Chrome/Edge

Transparency & Blend Mode

ts
let mat = new UnLitMaterial();
mat.transparent = true;
mat.blendMode = BlendMode.ALPHA;
mat.baseColor = new Color(1, 0, 0, 0.5);

WebGPU is not supported in your browser
Please upgrade to latest Chrome/Edge

See more about BlendMode

Switching Cull Mode

In order to save GPU performance, Orillusion uses the back culling mode by default, that is, only the front face material of the object is rendered. Set the material cullMode property to switch the display mode.

ts
let mat = new LitMaterial();
mat.cullMode = GPUCullMode.none; // Do not cull, display both sides
mat.cullMode = GPUCullMode.front; // Cull the front, display the back
mat.cullMode = GPUCullMode.back; // Cull the back, display the front

WebGPU is not supported in your browser
Please upgrade to latest Chrome/Edge

UV Transform

The model vertex will store multiple sets of texture mapping coordinates, which define the 2D coordinates corresponding to the vertex in the texture. It is usually represented by a two-dimensional variable (u,v), so it is also called UV coordinates.
We can customize the texture mapping relationship by performing matrix transformations on the uv coordinates of the model. For example, set the material transformUV1 shader value to perform coordinate transformations of the original uv for offset and scaling:

ts
let mat = new LitMaterial();
// Get current uv transform
let uv = mat.getUniformV4(`transformUV1`)
// Set a new uv transform - Vector4(offsetU, offsetV, scalingU, scalingV)
mat.setUniformVector4(`transformUV1`, new Vector4(0, 0, 1, 1))

WebGPU is not supported in your browser
Please upgrade to latest Chrome/Edge