Combining materials/shaders

Assuming we need to implement some utilitary or special shader, that apply some transformation to the final color ro UVs. For example:

  1. Animation of non-transparent liquid. For example, lava.
  2. Global grid drawn on the surface of objects
  3. Make some object slightly semi-transparent (walls between character and camera in isometric games) or slightly shining (character, pointed by mouse)

…but at the same time use the power of existing general purpose shaders Lighting or PBRLighting.

The most obvious solution is to just copy *Lighting.jm3d, *Lighting.vert and *Lighting.frag and edit them to inject specific transformations you need.

Are there any non copy-n-paste way to reach similar results? For example create material that refer to some base general purpose material and defines callbacks that are injected in right places in runtime?

This is what shader nodes was for. The ability to put together parts of a shader graphically or programmatically.

…the issue is that PBRLighting has never been decomposed into nodes. So it is a monolithic “fork it to modify it” thing.

…and because it’s easier for “fork and modify” than to decompose into nodes, that’s where we are today.

Edit: and to be fair, even Blender’s PBR shader is pretty monolithic. So I suspect there may be some compromise approach that wouldn’t require total decomposition but just provide inputs and outputs for a monolithic core shader node.


one popular engine allows to create shaders based on built-in PBR model with definition of callbacks:

  • Example 1: PBR, hard culling of geometry (like roofs disappearing in Fallout 1-2, but in 3D), higlighting of specific cells (path markers, danger markers), 3D fog of war.
  • Example 2: double-sided transparent variant of built-in shader (Iit’s not PBR, but just replace Lambert with Standard and it will be).

It’s interesting, how did they solve this limitation. Sounds like this question is better adress them, but interesting to hear your opinion.

Thanks for exmplanation. Will read more about shader nodes.

I don’t know whether jmonkeyEnginee will consider adding a framework of shader scripts to write multi-pass shading in the future. Instead of writing scene processes in java code.