Making Fog affect material made at run time with custom shader - Toon Water

I found this neat tutorial and I’m trying to figure out how to make the fog affect the water material

https://playcanvas.com/project/533435/overview/toon-water--tuts-tutorial

I’ve seen posts on overriding chunks and such, can anyone assist me with this?

Hi @Grayson_Ewing,

Shaders chunks are small shader programs that get assembled by the Playcanvas Programs library to dynamically create the shaders required by each scene material. Here is a list of all the shader chunks available in the engine:

To override a shader chunk is quite easy and powerful, too. Here is an example tutorial:

https://developer.playcanvas.com/en/tutorials/warp-a-sprite-with-glsl/

It allows you to write shader logic without having to rework things that Playcanvas already has in place for you: tonemapping, fog, shadows etc.

Now in this case, this project uses a complete separate shader, so it doesn’t leverage the shader chunks system.

Your best bet, to start interacting with how fog is rendered in Playcanvas, is to rewrite the shader using shader chunks. You will have to do both the vertex part (translate.vert is a good chunk to start with) and the pixel/fragment one (diffuse.frag is an easy one to start playing with).

@Leonidas thank you for the helpful information. I’m on it at the moment. Any tips on how to go about writing a shader to use chunks?

Check the tutorial I’ve posted above (2nd link), it’s simple and to the point on how to write a shader using chunks.