I have made a custom shader that does what I want, except for receiving shadows. Is there a simple way to implement shadows in my shader? Can I access calculated shadow maps from my scripts?
You can use the shader chunks system. The PlayCanvas engine uses lots of little chunks of shader code that control various parts of the final rendered image. You can change those chunks and plug in your shader code and the rest of the built-in chunks will handle shadows.
Here are some examples:
Thanks! And sorry for the late reply…
Given that I use this technique (plugging in code to the chunks system), how can I detect in a shader whether a fragment is in the shade or not?
To detect which shaderChunk is used by material? There is no such feature yet.
I mean is there a way to detect whether my fragment is in a shadow or not, from inside a fragment shader.
I have a plane with a home made water shader that creates waves and ripples and all. Now I want other objects to cast shadows onto the water surface. So I turn on “receive shadows” for my water plane and “cast shadows” for the other objects. But since I wrote my own shader I guess I will need to handle shadows myself somehow.
Maybe this is a better question: Is there a way to make use of the “receive shadows” feature when using custom shades?
If you are using fully custom shader, then it will be too complex.
But by using shaderChunks, it will be easier, as this data will be available in one of shaderChunks that implements shadowmaps.