Receive Shadows with Custom Shader

Could someone help me out with what shader chunks I can use to get access to the realtime shadow data? Is there data that I need to pass into the Vert as well as the Frag?

The way I would approach this would be to create the material in the editor that is similar / close to where I want to go with it. And then capture it with Spector JS (install Chrome plugin) and inspect the shader that is generated for it. From there find what parts you might want to customise and find the appropriate chunk by searching the shader code. Note that not all code is in chunks, especially related to lighting. But a lot of it is.

2 Likes

Thanks for the tips - I’ll try that out! :slight_smile:

Ok, so I managed to get all data into the shader, but I’m getting this error when trying to access the light0_shadowMap:

Trying to bind current color buffer as a texture

Is there something I’m meant to do to pass the shadow map data to my shader?

it kind of feels like the object you attached this custom shader onto is being set up for rendering to shadow map … and so the error message basically says that you cannot read shadow map white rendering to it.

If that’s the case, you might need to disable your object from casting shadows. Or maybe it needs different shader when rendering to shadow map … but I’m not sure at the moment how / if this can be easily set up.

1 Like

I don’t need it to cast shadows, so that fixes the error.

Issue is now as soon as I try to make use of the light0_shadowMap in the shader my object just disappears (even if I don’t do anything with it).

Is light0_shadowMap a global variable or do I need to some how pass it in to the shader?

EDIT: It does work! Just the shadow needs to be set to PCF on the light.
Thanks for your help!

1 Like