Shadows for transparent textures

Michalis said in another topic: “Having lots of 3D shapes, each with 2 quads arranged to form a cross, will be both easier to do and faster to render.”
I am now working with cross-quads to draw grass, as I asked. The textures are transparent. However, when I activate the shadow, it simply draws the quad as the shadow and not the transparent blades of grass. So, the shadow is rectangular and does not show the blades.
Is there an example for this?

A second question in this context would be: when I create a cube in a scene, the back cubes are actually hidden. However, when I use a PNG texture that has transparent areas (for the grass), grass behind it is sometimes drawn in front of the foreground grass. Do I need to enable different depth checks compared to the cube, just because I’m using transparent textures?

That is indeed the unavoidable problem of the “shadow volumes” approach, which I understand you use, as it is used when you just toggle the Shadows checkbox on a light source. See Shadow Volumes | Manual | Castle Game Engine , in particular sentence there " Applying a texture with transparency (alpha testing) on the object has no effect on the shadows cast." .

This is unfortunately not fixable with shadow volumes, that necessarily need to follow the geometry.

We have alternative shadows algorithm, shadow maps, Shadow Maps | Castle Game Engine , that doesn’t have this limitation. The textures with alpha (using alpha testing) are then accounted OK, e.g. tree leaves can cast correct shadow.

But using “shadow maps” in CGE is right now much harder. You need to add a light source, to the same scene (TCastleScene) where the shadow casting objects (like grass) are, as X3D light node.

Exposing the shadow maps algorithm better is a work in progress. I’d like to have a simple ShadowsMethod choice at each light source, and just allow you to choose shadow volumes or shadow maps, but for now this still requires some work to be possible – namely, our shadow maps should be able to cast from one scene to another, this is tracked in ticket MainScene's light source does not cast shadow (shadow maps) to other scenes · Issue #284 · castle-engine/castle-engine · GitHub .

So, unfortunately, the simple answer to this is that there’s no easy fix. You can change your approach to use shadow maps, but that will be a complicated change for now, you can follow the docs from Shadow Maps | Castle Game Engine . I want to make it trivial in the future in CGE, but this takes time.

I don’t understand this issue completely. If you have a simple testcase (that can be run) it would be helpful.

Is it possible you use blending for your grass texture? In this case, see Blending (Rendering Partially-Transparent Objects) | Manual | Castle Game Engine how blending works. The simplest advise is to not use blending for the grass, you should use alpha testing, that doesn’t require any sorting. How to set it up, depends on how you construct your grass – if you do it in Blender, set “Blend Mode” to “Alpha Clip”. If you set it up in code, set TApperanceNode.AlphaMode to amMask.

But it is possible my advise is wrong here – it would help if you can explain / demonstrate the problem better, so that I can better advise :slight_smile:

Blending is working now. Thank you so much for informing me about that switch. It was easy enough to fix :wink:
Regarding the shadows: I might wait for your engine to have a more straightforward approach. I’m not sure if I would be able to get “shadow mapping” to work.
Thanks again.