Transparency

A. Transparent textures

You've probably noticed that transparent textures often cause problems. For example, if you bring two trees with transparent leaves together and move the camera around them with the camera, you'll suddenly see sudden changes in luminosity, transparent rectangles around certain branches, disappearing leaves, or the branches of a distant tree appearing in front of a nearby one.

Transparency in 3D games is complicated by the current generation of graphics cards. These cards require transparent textures to be sent in the following order: from the texture furthest from the camera, to the texture closest to the camera.

Planet is therefore obliged to sort objects, clothes and particles with transparent textures. This sorting is more complicated than it sounds, because there is often no clear order: a tree can be both in front AND behind another if the branches touch; a campfire may have smoke particles colliding with a transparent flame texture.

For objects with transparent textures to be displayed correctly, it's best if they're far apart. This way, Planet can always sort them easily.

For cases where several transparent textures overlap, Planet offers two interesting options:

a) transparency priority

You can specify a transparency priority, from -7 to +7. By default, textures have priority 0. If you change the priority of a texture to 1, and it overlaps a texture with priority 0, the texture with priority 1 will be displayed IN FRONT. If you set priority -1, it will be displayed BEHIND. Please note that particles have priority -3 by default, so they are generally displayed in the background. They receive +3 priority if you set the .front parameter to true in the particle script.

b) with Z-buffer

The 'Z-buffer' option is enabled by default. If you see transparent rectangles in the middle of your tree branches, try unchecking this option. It has the effect that one part of the mesh never hides another part of the mesh. But it also has an unnatural blending effect when you turn the camera. You'll have to decide whether you prefer transparent rectangles or the blending effect. Note that particles always have this option deactivated.

Here are a few more tips

If you're creating a transparent globe, make sure you use different texture numbers for the inside and outside, otherwise you'll end up with a puzzle of facets when you turn the camera. Also set priority 1 on both globe textures.

Set a car windscreen to priority 1 to prevent your transparent mesh clothes from disappearing under certain camera angles.

If you see smoke particles appearing IN FRONT of a clear water river instead of BEHIND it, check that the transparent meshes in the river are aligned and do not overlap. otherwise planet will consider that all these meshes are held together and form a huge object around the smoke. This will often make the problem disappear. Alternatively, set the .front parameter to true in the smoke script as explained above.

If you're building a house with transparent glass on all 4 facades, and all in a single mesh, avoid using the same texture number for all 4 panes! Because if you do, and there are transparent objects in the house, you may not be able to see them properly when you look through the windows. correctly when you look through the windows from outside. This is because Planet will display the 4 panes together and won't find a clear sorting order with the object, as the windows are both in front of and behind the object. What needs to be done is to import the window texture 4 times into the mesh, so as to have different texture numbers (even if it's the same texture), and apply a different texture number to each pane. Planet will then be able to sort the panes and the transparent object, from furthest away to closest, and transparent objects in the house can be seen correctly by looking through the window from outside.

B. Stencil effects on the sea

Planet offers layer functions that allow you to cut out part of the seawater, for example, so that no water is visible inside a deep-sea boat or submarine. These options are available in the Object / Edit / Mesh / Various menu.

To avoid seeing water inside a boat, you need to split the boat into at least 3 separate meshes:

mesh 1: the outer hull of the boat. Set the "Outer hull" option.
mesh 2: the boat's inner hull. Set the "Inner hull" option. Mesh 2 can be 100% transparent, i.e. invisible, which also works. Make sure you don't have a paper-thin hull: there needs to be at least a small thickness between the outer and inner hulls. If you check this option, the water seen in front of mesh 2 will be removed, unless mesh 1 is in front of mesh 2.
mesh 3 and following: the bulk of the boat, deck, furniture, berths, etc.

If you've built the sea water yourself, set the "Drillable Water" option on this water mesh.

If your avatar enters the boat and you see everything in blue, set the "Empty Volume" option on the boat's mesh 2.

The mesh numbers shown in the example above do not have to be respected, as long as you you click on the right transparency option for each one.

So there you have it, a summary of layer techniques for making water disappear from the sea.

Given that current graphics cards have poor support for transparency, you'll find that that it takes a lot of fiddling and trial and error to display transparent objects correctly.