Shadows on a skybox collision mesh

I would like to cast shadows from a directional light source on a collision mesh. The collision mesh itself is transparent (because it is surrounded by a skybox), but I would like to cast shadows of other objects in the scene to the collision mesh (so that only the shadow can be seen, but other parts of the mesh are transparent). Can this be done with the auto shader? Thank you.

The collision mesh is designed for mathematical calculations and no more, and even more so for not rendering.

That makes sense. But even if I create a seperate object which will be rendered(and has the same shape as the collision mesh/ground mesh), it should only render the shadows, and hide the surface which is not hit by a shadow. Little bit hard to explain.
I think it is nothing special what I need, although I didn’t find a lot by searching for it.
Basically what I need is to render shadows in a skybox. And the shadows should not be casted to the walls of the skybox (of course) but instead should be casted to the environment/ground which the skybox shows. Thanks for your help.

Hmm… It’s a tricky thing, if one sticks to the auto-shader–or at least so it seems to me offhand. Perhaps you could do something with texture combine modes–give the base mesh a flat white colour, unshaded, and then use combine modes to convert white to transparency…

(My first instinct, conversely, would be to use a custom shader–that should be fairly straightforward, as one could take the result of the shadow-test and apply it to the rendered transparency.)

Thank you. I will look into that.

1 Like

I now have a custom shader (from simplepbr). Can you explain a little more detailed, how to create a shadow for the transparent surface? Thank you.

Okay, first of all do you yet know how to implement shadows in a custom shader? If not, then I’d suggest looking that up first–I think that there might be some relevant threads on this forum, for a start at least.

If you do already have standard shadow-casting implemented, then the basic idea is this:

In your shader, where your shadow-casting indicates shadow, output a high alpha-value; where your shadow-casting indicates no shadow, output a zero alpha-value.

This should result in your object rendering as transparent everywhere but those places that are shadowed.

But don’t forget to activate transparency on the object, if called for! Without having done so you might find that, even though you’re outputting transparency in your shader, the object remains entirely opaque.

Thank you for your answer. I will need to dig a little deeper into shader programming, and let you know if it worked. Thanks so far.

1 Like

That’s fair, and I hope that it goes well! :slight_smile:

1 Like

Thanks again. It works. I use:

    if (shadow<0.5) 
        color=vec4(tex.rgb*(light*shadow+ambient), 0.5);

in the fragment shader.