Request for Comprehensive Documentation: Shader Chunk Manipulation via material.getShaderChunks()

Dear PlayCanvas Team,​

As a developer working extensively with custom shaders in PlayCanvas, I’ve encountered significant challenges when using the shader chunk system—specifically the material.getShaderChunks(pc.SHADERLANGUAGE_GLSL).set(“chunkName”, “chunkCode”) method. While the chunk system offers powerful flexibility for modifying standard materials (e.g., adding animations without breaking PBR or shadows ), the lack of official documentation has forced the community to work in “blind mode” .​

Key Documentation Gaps We Need Addressed:​

  1. Step-by-Step Tutorials for Chunk Manipulation​

Many developers struggle to override chunks without breaking core features. For example, modifying vertex shaders often inadvertently disables fragment shader effects like ambient lighting or shadows . A official guide explaining:​

  • How to safely override chunks using getShaderChunks().set()​

  • Best practices (e.g., modifying specific functions like getPosition() instead of full main() )​

  • Uniform parameter integration (as in emission map animations )​

  1. Complete Chunk Name Reference​

The community has compiled partial chunk lists , but these are outdated (from 2019) and lack context. We need an official, versioned list of:​

  • All chunk names (e.g., basePS, emissivePS, lightDiffuseLambertPS)​

  • Their purpose (e.g., normalMapPS for normal mapping, fogLinearPS for fog effects)​

  • Compatibility with material types (standard, particle, etc.)​

  1. Shader Chunk Pipeline Explanation​

Chunk compilation order directly impacts functionality—for instance, basePS must precede other fragments to define global variables . We need clarity on:​

  • Vertex/fragment shader chunk concatenation sequences (e.g., fragment order: basePS → opacityPS → emissivePS → endPS )​

  • Dependencies between chunks (e.g., why diffusePS relies on normalPS)

Hi @gameatp ,

It’d be definitely nice to have some additional documentation, but I do not think we’ll go as far as what you’re asking.

Shader chunk overrides are for more advanced users, and many of these questions can be answered by looking at existing chunks that you want to override.

This is the source path to explore: engine/src/scene/shader-lib at main · playcanvas/engine · GitHub

If you look at this subfolder, these are the main shaders we use, typically for normal color rendering the pass-forward is what you’re interested in.

When you inspect their source code, they use #include "" to include other chunks, including those that you override. This will give you a good undestandign of their order and dependencies, and other chunks that you can override.

I hope this helps till we have some documentation online.