[OpendTect_Developers] transparency and layers

Karthika Sivaramakrishnan karthika.sivaramakrishnan at dgbes.com
Fri Nov 12 15:14:29 CET 2010



   Hi all!
When multiple visual objects are present in a scene, some objects  
might be obscured by the objects in front of them. In order to view  
the objects in the background, we can manipulate the transparency of  
the foreground objects. For example, we can examine two or more  
attributes on the same inline by judicious use of transparencies (as  
in the attachment scene1.jpg, where the porosity cube attribute is  
fully transparent in undefined areas and 50% transparent in all other  
areas). Or, we can let the background partially show through an object  
(as in scene2.jpg, where a 75% opacity is assigned to the material of  
the fault). In this post, I am going to explain the different  
transparencies in OpendTect and how they are implemented.

  TRANSPARENCIES:
OpendTect has a powerful scheme of transparency setting. We first need  
to understand the concept of alpha channels in OpendTect before  
working with the transparencies of the layers. An alpha channel is a  
component of the RGBA color quadruplet that represents the degree of  
transparency of the color. Basically, there are 4 alpha channels  
defined in OpendTect.

1. Alpha channel used to specify the degree of opacity of the  
undefined values (1e30). It can be found per color table in the color  
table manager, by clicking on the button "Undefined color". (Note: the  
color table manager is accessible from the menu obtained by clicking  
the color bar displayed in the toolbar).

This alpha channel ranges from 0 (default - fully transparent) to 255  
(fully opaque).

2. Alpha channel used to specify the amplitude (color)-dependent  
degrees of opacity for all non-undefined values. It can also be found  
per color table in the color table manager, as an editable red line  
with at least two nodes, above the colorbar display. Since it varies  
per color, it is interpolated like the color value RGB.

This alpha channel ranges from 0 (default - fully opaque) to 255  
(fully transparent). In the graphic, it linearly increases from bottom  
to top, with the bottom being fully opaque.

3. Alpha channel used to specify the degree of opacity of the layer as  
a whole. It can be found per layer in the tree, using the right-click  
menu option "Change transparency".

This alpha channel ranges from 0 (fully transparent) to 255 (default -  
fully opaque). In the slider, the value linearly decreases from left  
to right.

4. Alpha channel of the material belonging to the visual object. This  
can be found in the dialog obtained by choosing the "Display  
Properties" option after right-clicking the visual object in the tree.  
(Display Properties: Material: Transparency). This alpha channel  
affects all the layers that compose the object.

Just like alpha channel #3, this alpha channel ranges from 0 (fully  
transparent) to 255 (default - fully opaque). In the slider, the value  
linearly decreases from left to right.

The final alpha channel per tree element is a composition of the first  
three alpha channels for every layer, and finally the application of  
the alpha channel (4).

  HOW THIS IS IMPLEMENTED:
The TextureChannel2RGBA object is responsible for converting the  
texture channels to RGBA textures for use by OpenGL, optionally with  
shaders. The ColTabTextureChannel2RGBA, derived from  
TextureChannel2RGBA, takes a color sequence for each channel and  
blends them all into an RGBA image. Most of the visual objects have a  
ColTabTextureChannel2RGBA object for texture-mapping. This class does  
the bulk of the work related to the implementation of transparency in,  
for example, inlines, crosslines and random lines.

Now, let us take a look at the implementation of  
ColTabTextureChannel2RGBA. In the  files attached, you can see the  
scene graph implemented by this class. Depending on the support of  
hardware for shading and the user's preference, the shading group is  
selected. (Note: Shading can be turned on and off using the menu  
option, "Utilities: Settings: Look and feel: Use OpenGL shading when  
available".) When shading is not used, the non-shading group becomes  
active, and the SoOD class SoColTabTextureChannel2RGBA takes care of  
the rendering. When shading is used, the shader programs jump into  
action. The important nodes under this shading group are:

   - The texture composer info node. This node contains the  
transparency info, which is either of the following:

   * cHasNoTransparency() - 0 (opaque)
   *  cHasNoIntermediateTransparency() - 0 or 255
   *  cHasTransparency() - 1 to 255

   Such a segregation of the transparency information makes alpha  
testing quick and easy during texture composition.

- The SoTexture2 node, 'shaderctab'. This node contains (a  
concatenation of) the color tables (for color lookup) for each layer.   

- The shaderprogram node - this node has 2 shader objects - a vertex  
shader and a fragment shader. The fragment shader is more complicated  
and is of interest to us here, in the implementation of transparency.  
The fragment shader has a couple of parameters (you can look at them  
in the scene graph). The layer opacities (alpha channel #3 in the list  
above) are assigned to the shader parameter array for use by the  
fragment shader.

The fragment shader loops across every layer (and naturally processes  
all the pixels or fragments in parallel in the GPU), making use of the  
shading variables set by the setShadingVars method, to compute the  
final RGBA values of every pixel. We need find the most efficient way  
to render the object, making optimum use of the resources. Therefore,  
the setShadingVars method determines the start layer for rendering,  
depending on the transparencies of the individual layers. It is only  
sensible to render those layers that will eventually not be  
overwritten by opaque layers and to omit transparent layers. This  
method also finds the collective transparency info  
(SoTextureComposerInfo) for the visual object. This depends on the  
attributes loaded in the layers, as well as the first three alpha  
channels explained in the beginning of this post. In some cases, all  
the individual pixels need to be checked to determine the transparency  
info. (An example is when the layer opacity (alpha channel #3)  
indicates a fully opaque layer: we need to check if the individual  
pixels have any transparency). This is done in parallel by the class  
ColTabSequenceTransparencyCheck.

The processLayer function of the fragment shader is the place where  
the transparencies are used to set the final pixel color. In addition,  
alpha channel #4 is used in SoTextureComposer::GLRender to set the  
alpha testing function.

  TO PUT IT ALL TOGETHER:
OpendTect supports transparency at several levels. A visual object,  
like an inline, can have different transparencies for the different  
layers of attributes it has. There can be transparency associated with  
each color of the color tables of the attributes, and there can even  
be a single transparency for the whole object's material. The  
ColTabTextureChannel2RGBA member of the MultiTextureSurveyObject, from  
which the PlaneDataDisplay (inline display class) is derived, takes  
care of the transparency and texture mapping tasks, both with and  
without shading.

   Your questions and comments are welcome!

   Best regards,
Karthika

   --
-- Karthika Sivaramakrishnan
-- dGB Earth Sciences B.V.
-- Nijverheidstraat 11-2, 7511 JM Enschede, The Netherlands
-- mailto: karthika at dgbes.com, http://www.dgbes.com
-- Tel: +31 53 4315155, Fax: +31 53 4315104
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opendtect.org/pipermail/developers/attachments/20101112/d4a24755/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scene1.jpg
Type: image/jpeg
Size: 133622 bytes
Desc: not available
URL: <http://lists.opendtect.org/pipermail/developers/attachments/20101112/d4a24755/attachment.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scene2.jpg
Type: image/jpeg
Size: 135361 bytes
Desc: not available
URL: <http://lists.opendtect.org/pipermail/developers/attachments/20101112/d4a24755/attachment-0001.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scene graph.odp
Type: application/vnd.oasis.opendocument.presentation
Size: 17616 bytes
Desc: not available
URL: <http://lists.opendtect.org/pipermail/developers/attachments/20101112/d4a24755/attachment.odp>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scene graph1.jpg
Type: image/jpeg
Size: 29243 bytes
Desc: (In case you cannot view the scene graphs in the .odp	file).
URL: <http://lists.opendtect.org/pipermail/developers/attachments/20101112/d4a24755/attachment-0002.jpg>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: scene graph2.jpg
Type: image/jpeg
Size: 64949 bytes
Desc: (In case you cannot view the scene graphs in the .odp	file).
URL: <http://lists.opendtect.org/pipermail/developers/attachments/20101112/d4a24755/attachment-0003.jpg>


More information about the Developers mailing list