Shader

In the Shader Introduction, we learned the basic concepts of shaders. The Galacean engine encapsulates other rendering-related information based on shader programs to form a Shader object. The Shader object, together with the material, determines the final rendering result of the rendered object.

Shader

The Shader object contains the following:

  • name

The name of the Shader instance. Once created, the Shader object is cached by the engine and can be reused by finding it through Shader.find() using Shader.name as the index. Therefore, the engine requires that the name attribute of the Shader must be unique within a single engine instance.

  • SubShader

A Shader object contains at least one SubShader object.

SubShader

A shader program may run on different GPU hardware platforms and different rendering pipelines. Therefore, the Shader object specifies different rendering logic for different hardware platforms and rendering pipelines through key-value pairs of tags, which are the SubShader objects.

The SubShader contains the following:

  • Tags

Tags are key-value pairs consumed by the rendering pipeline, usually used to specify information such as the hardware platforms and rendering pipelines compatible with the Shader. The current engine's built-in pipeline consumes the following Tags:

Keyvalue
pipelineStageForward
pipelineStageDepthOnly
pipelineStageShadowCaster
pipelineStageDepthOnly

Additionally, you can specify the replacementTag of the rendering pipeline through Camera.setReplacementShader to achieve the purpose of replacing the SubShader with the specified Tag.

Tags can be specified through SubShader.setTag and ShaderPass.setTag. For details on specifying Tags in ShaderLab, see the documentation.

  • Passes

A SubShader contains at least one ShaderPass object.

  • RenderStates

RenderState rendering states shared by all ShaderPasses under the SubShader.

ShaderPass

ShaderPass encapsulates the specific shader program and the rendering state when performing the final rendering.

The ShaderPasses under the same SubShader are rendered sequentially according to the array order, with the rendering effects gradually superimposed to form the final rendering result of the Shader in the current frame.

Was this page helpful?