10. A few additional words on blending and transparency:
It may seem odd, especially to those who are not familiar with OpenGI or other 3D graphics
development environments, that transparency is one of the most difficult tasks to be solved in
real time 3D graphics. As already mentioned, OpenGI uses the so-called Depth Buffer to keep
track of the distance of each pixel (fragment) of the image from the point of view of the viewer, ie.
the camera.
If in the course of the calculations a given fragment (the smallest element calculated in OpenGl is
called a fragment) of the object about to be shown receives a depth value that is bigger than the
corresponding value already in the buffer, it means that there is already a fragment closer than
the new one, so the new one can be discarded. This method works perfectly as long as the object
that is closer is not transparent at all. Because if it is, and we can see through it, we should be
able to see the object behind it as well.
OpenGI has a separate setting for taking transparency into consideration, for deciding whether to
calculate or not the blending of a fragment already rendered with one that is just being calculated
and is at least partially transparent. This process is called Blending. When Blending is switched
off, OpenGI will not calculate transparency, everything will remain non transparent and will cover
everything behind it. When Blending is on, the Depth Buffer cannot be used or can be used only
in part. In this case how do we calculate which object should cover the other? As a matter of fact
no hardware assisted methods are available for this. The order in which you place your Objects
on a Page determines the order in which they are being drawn. In Nemo this means that the
closer the Object is to the camera the lower it should be in the tree view list of the Objects panel.
Consequently care should always be taken to place Objects in the right order, according to their
distance from the camera, particularly those Objects which have transparent parts. This is the
main purpose of the possibility of dragging and dropping objects to change their order.
Even bearing this in mind we have to overcome another problem. First, we have to know whether
an object has a transparent part. In the simplest case the value of Transparency, one of the
common properties, is smaller than 1.
But there is a Transparency property for Materials, too and an Object can have several Materials
applied on it. More complicated still if neither the Object nor any of its Materials have
Transparency values set below one, but one of the Textures attached to one of the Materials
have pixels with alpha values that make them part transparent. These pixels cannot be checked
automatically by NemoEngine all the time, you have to intervene manually.
Using this manual solution is much simpler than explaining the reason why you need to use it. If
you apply 32-bit texture, about which you know that it has transparent pixels, you should set
either the Transparency property of the Material or the Object itself to a value very slightly less
than 1 (0.998 is perfect). This way NemoEngine is instructed to switch to Blending mode and do
not cover the Objects behind with this one. Still, this value being almost 1 ensures that if you don't
really want to make the whole object transparent it will still look opaque.
110
Kommentare zu diesen Handbüchern