Renderer

Renderer Overview

The renderer is responsible for displaying graphics as a component. It displays the corresponding rendering effects based on different data sources. By mounting the renderer on a node and setting the corresponding rendering data, various complex 3D scenes can be displayed.

Types of Renderers

In Galacean, the following types of renderers are built-in:

You can learn more about the rendering order of various renderers in the engine through Rendering Order.

Properties

Renderer is the base class for all renderers in Galacean, and it includes the following properties:

PropertyDescription
receiveShadowsWhether to receive shadows
castShadowsWhether to cast shadows
priorityThe rendering priority of the renderer, the smaller the value, the higher the priority, default is 0
shaderDataData dependent on rendering, including some constants and macro switches
materialCountTotal number of materials contained in the renderer
boundsWorld bounding box of the renderer
isCulledWhether the renderer is rendered in the current frame

You can get these properties from any renderer derived from Renderer.

const renderer = cubeEntity.getComponent(Renderer);
renderer.castShadows = true;
renderer.receiveShadows = true;
renderer.priority = 1;
console.log("shaderData", renderer.shaderData);
console.log("materialCount", renderer.materialCount);
console.log("bounds", renderer.bounds);
console.log("isCulled", renderer.isCulled);

Methods

The Renderer base class mainly provides methods for setting and getting materials. It is important to note that a renderer may contain multiple materials, so the following methods are more like manipulating an array of materials.

MethodDescription
setMaterialSets a material in the array
getMaterialGets a material from the array
getMaterialsGets the array of materials
getInstanceMaterialGets a copy of a material from the array
getInstanceMaterialsGets copies of the array of materials

Was this page helpful?