• 3D
  • Depth rendering issue on tree leaves with directional light

Hello !

I am quite new to Godot and I'm trying to make a landscape scene. I managed to solve all my problems until now by searching on the web, but this time I'm stuck with this :

As you can see, my trees seem to render in the wrong order : the farthest trees appear on top of the closest ones. I've played around with some options, and here is what I can get : - This only happens with a directional light, other light types are a fine (although a bit ugly but they don't seem to mess up the rendering order) - This only happens when the directional light points towards the camera (if looking the same way as the light, the trees render correctly) - This is most likely caused by the "shadow_enabled" option of the light. When I deactivage this option, the probelm disappears, but when I activate "unshaded" in the leave material, the problem persists. Turning off the "cast shadow" option on the tree mesh also "solves" the problem.

Here are screenshots of the directional light and leaves material properties :

Big thanks to anyone who can help

I've edited the formatting in OP to fix the image links. For the issue itself I think you might want to try the other Depth Draw Modes in your material properties. One should be Opaque Pre-Pass. That might solve it.

---

This discussion was caught in the moderation queue since you have not confirmed your account yet.
Upon creating your account you should have received an account verification email. The confirmation email may have been incorrectly flagged as spam, so please also check your spam filter. Without confirming your account, future posts may also be caught in the moderation queue. You can resend a confirmation email when you log into your account if you cannot find the first verification email.
If you need any help, please let us know! You can find ways to contact forum staff on the Contact page. Thanks! :smile:

Tank you for fixing the links and answering !

Unfortunately, the leaves material is already set to Opaque Pre-Pass. Switching it back to Opaque only does not solve the problem, it only suppress the shadows of the leaves. I really have the impression that it has to do with the Directional Light rather than the material...

So I made a test scene to have a better view of the problem. Here are screeshots with and without the directional light's "cast shadow" option: https://imagizer.imageshack.com/img923/4089/ntHWy2.png

We can see that, with the "cast shadow" activated, some parts of the blue grid (in the back) tend to overlap with the red grid (in the front). However, it doesn't seem to be consistent, so maybe it's not exactly a problem of depth rendering...

If it turns out that this is an issue with the engine itself, I can provide you this test project for reproduction.

It does not seem to work. The shadows themselves are affected but the blue grid is still visible without a single change...

If you select the "grid" texture in file browser tab and then look at the import tab, what are the import settings for the texture?

Here are screenshots with the import options.

For the blue grid: For the red grid:

I tried to modify randomly most of the import options, and it didn't seem to do anything (even after hitting "re-import")

Oops... sorry... I rarely upload images online and I'm not used either to this forum's formatting conventions '

I edited the above post (try open the image in new tab for the best visibility).

Yeah, so there are things you can try doing with the import settings. First try the Premult(iply) Alpha setting. Second you can try adjusting the Lossy Quality slider to see if that helps anything(Note that this value already differs between the blue and the red texture). And last you can try changing the Compression Mode from Video RAM to something else.

4 days later

Hello ! I wanted to work on another aspect on my game before returning on this problem.

It seems Permult Alpha does nothing on its own, Lossy Quality does nothing on its own Compression mode does nothing on its own.

Activating Permult Alpha and le "lossy" compression mode creates strange shades on the grids, but does not solve the issue. Modifying the Lossy Quality and Lossy option does nothing (for lossless and uncompressed I don't even have the slider). Modifying the Lossy Quality and Permult Alpha does nothing.

Modifying the three parameters at onces does not solve the issue, but the "Lossy Quality" slider diminishes the size of the strange shadows caused by the Lossy compress mode.

6 days later

Good news everyone ! I found the solution a workaround.

So the problem is, Godot (Or maybe my graphic card, I really don't know) is unable to process transparency correctly when the light comes from the front. But this only true on half-transparent pixels (those which are partially opaque). The grids I use in my example are not completely opaque. Forcing them to have binary transparency solved the issue.

The workaround consists in two steps:

1) Make sure your source image only has binary transparency (each pixel is either 100% transparent or 100% opaque). You can use GIMP's "alpha threshold" option for this.

2) Disable mipmaps in the import tab. I know it's recommended for 3D, and disabling it makes the game both less optimized and slightly uglier, but if your material is far away, mipmaps is going to calculate semi-transparent pixels even though the source image only has binary transparency.

I hope this helps some people ! And if you have a better solution, please share it

Thanks to Megalomaniac for their time ! I greatly appreciated it !