g3n / engine

Go 3D Game Engine (http://g3n.rocks)
https://discord.gg/NfaeVr8zDg
BSD 2-Clause "Simplified" License
2.82k stars 298 forks source link

Transparency / Rendering order #297

Closed t-geindre closed 1 year ago

t-geindre commented 1 year ago

Hello! I'm trying to implement a Minecraft like game. In this game, flowers are rendered like this: image

I tried to get the same rendering using four vertical plan mesh, centered on the same point and with a 90° rotation between each. Example: https://gist.github.com/t-geindre/07e2d78574157045c3a6e91cb95920d6

But the issue is that on some view angle, those plans are visible: dandelion

I'm sure the issue here is the rendering order. But I've no idea how to solve this.

I also tried to create a custom geometry to have those crossed plan in a single mesh. But, since the geometry type properties are not accessible, I think it's not possible.

Any help would be very appreciated. And thank you for the work done on this project, I love it!

danaugrs commented 1 year ago

Hi! Thanks for the kind words! You might be able to solve this by disabling the depthMask on the flower material:

myFlowerMaterial.SetDepthMask(false)

With the depth mask disabled, when the flower planes are rasterized they won't write to the depth buffer, and so the occlusion artifact should disappear. However, this will probably lead to another problem where a plane is visible through the other. You may have to draw four planes instead of two (and keep the depthMask on).

Also - please consider joining our Discord if you haven't already: https://discord.gg/NfaeVr8zDg. Would love to see screenshots of your game!

t-geindre commented 1 year ago

Thank you for your quick answer.

It kind of solve my issue. But, as you guessed, I can now see flowers through flowers on some angles: floxwer (sorry for poor quality, but I had to deal with Github file size limitation)

So more plans it is, and split the texture I guess, to apply half of it on each plan.

This game is at a very early stage, and I'm sure you know how side projects go. But I'll definitely join the Discord server at some point.