Hi. In my project I use 150+ unique materials in scene, most of which share the same or very similar shader chunks — in many cases the only difference is in uniform values.
The issues I’m facing:
On first scene load, the Editor takes a long time compiling shaders — it seems like a new shader variant is created for every material, even if the chunks are the same.
There’s no way to preview custom chunks in the Editor, which makes material editing harder.
I’d like to understand:
-
Is there a way to reduce the number of shader compilations, if materials share the same chunks and only differ by parameters?
-
Does PlayCanvas support reusing shader variants when shaderDefinition is identical?
-
Is there any way to speed up initial scene load when many materials are present?
-
Is it possible to preview custom chunks in the Editor, or at least see the result somehow?
-
What are the overall plans for the material and shader system in PlayCanvas?
Any insights or recommendations would be really appreciated
1 Like
Are you concerned about loading your project into the Editor? But not running your project itself?
- Material’s need to use the same chunks and be configured the same way for them to share the shader. For example if one uses diffuseMap and the other does not, those will be two different shaders. So ideally you minimize number of these combinations you use.
- yes. If the result would be the same shader based on material properties, we use a single shader under the hood.
- See point 1 - configure your materials in the same way so that the shaders are shared.
- You can log in shader creation, but that applies to when the project runs, not when the Editor runs. See Tracing | Engine API Reference - v2.8.0 using
TRACEID_SHADER_COMPILE
- There are few tickets, for example this: Optimize shader generation / processing / compilation · Issue #6085 · playcanvas/engine · GitHub. The work on this has been happening in the background, but all if this comes down to your material configuration. We can do only so much, as compiling many shaders is really expensive.
2 Likes
Also, it would be great if the whole shader/material process was more open and controllable.
For example — being able to define “master materials” with all the needed slots and shader chunks set up (like which texture maps are used, what lighting model, etc). Then create material instances that only store the necessary uniform values.
Right now, every material stores a pretty big JSON blob, even if most of it isn’t used.
With instances:
- You could skip storing unused parameters
- Keep material data smaller and cleaner
- Reuse a single compiled shader across all instances
Basically: we set up a few “core” materials manually, and everything else just inherits and overrides what’s needed — no redundant shader generation, no bloated JSON.
1 Like
We considered this multiple times, but have not found time to implement something like this unfortunately.
3 Likes