The shader chunk challenge

For our game we need a animated scifi wormhole portal that really looks good. We created a texture atlas with a real cool animation. For best effect we want to blend between different pictures from this atlas. I understood that for this we would need to write our own shader chunk.

Normally I would not even dare to think about that. But until now we managed to do (for us) rather complex things in PlayCanvas thanks to the clean API and lots of help from this forum. So why not give it a try? I studied the OpenGL shader language. Not to difficult for a C programmer.

The biggest problem is that there is very little documentation about the shader chunk system. So even to get started we would need some help.

We do not want to write a complete fragment shader. I guess it is better to adapt a fragment shader that already does some things we need. But the standard shader may already be to complex to adapt.
To render the wormhole effect we only need diffuse and emission. No metalic or reflections. But we may want to use parallax mapping (or add that later ourselve?).

So what is the best way to start?

Some questions:

  • Which version of the OpenGL shader language is supported / is used?
  • We need transparency in the textures. What are the consequences of that?
  • Is there any demo that swaps the fragment shader with a custom one?
  • Can we use the standard shader and adapt it (or does it consist of more then one pieces?)
  • Is it best to give our object already some textures so that we only have to change the textures?
  • Or is it best to begin without any texture and add them by software?

Maybe these questions make no sense. But that is because we probably do not understand the chunk system and will have to learn that.

The shader chunk was never an official API and been one of those things that kept being kicked down the road till more recently.

We are currently in the process of getting materials into a much more stable state and also prepare on integrating a node graph shader editor to help with this type of thing.

TLDR at the moment, the chunk system is where each chunk represents some behaviour on the standard material. eg diffuse chunk for the diffuse channel, etc.

You can override each chunk from the standard behaviour to use your own bespoke behaviour.

Here’s a thread with an example of overriding the diffuse and opacity chunk

And one by Leonidas too

Wanted to ask a quick question on Shader Chunks and I’m on a time sensitive project so can’t really wait around for new material integrations.

I need to create a custom opacityPS shader. I’ve done chunks in the past so the concept isn’t new to me, buuut there used to be a git folder containing all of the default chunks and now it is gone. It was a great reference and at worst a starting point for a custom chunk. Has that moved somewhere new because the old link gives me a 404 :frowning:

Is this the folder you are looking for? engine/src/scene/shader-lib/chunks/standard/frag at main · playcanvas/engine · GitHub

It is indeed! Thank you so much :slight_smile: