HELP! TRANSPARENCY ON SGI!!!

Alain Dumesny alain at paris.asd.sgi.com
Wed May 29 14:22:04 AEST 1991


use the getgdesc(GD_BLEND) routine to see if the blendfunction() routine is
available on your machine (GT/GTX/VGX have it, PIs don't).

1) if you do then

blendfunction(BF_SA,BF_MSA) will turn alpha blending on and
blendfunction(BF_ONE,BF_ZERO) turns it back off.

You specify the transparency of an object using the ALPHA value when specifying
a material in lmdef(). 

To get transparency to really work correctly though, you will need to
render the transparent polygons from back to front after you have rendered the
regular polygons. A quick and easy hack which doesn't require the sortings of
the polygons and which partially works is to :
    a) render all regular polygons (zbuffer on)
    b) render all transparent polygon in the order they come, have zbuffer on
    for correct clipping, BUT turn off the zbuffer write mask so that 
    transparent polygones behind other transparent ones still get drawn.
    Turning backfacing off also helps.


2) If you don't have blendfunction(), or don't want to sort your transparent
polygons and your transparency needs are pretty basic (i.e. only a few discreat
transparency levels) then you need to define transparency patterns using
defpattern()/setpattern().

for example :
unsigned short mask1[] = {
    0x5555, 0xAAAA, 0x5555, 0xAAAA,
    0x5555, 0xAAAA, 0x5555, 0xAAAA,
    0x5555, 0xAAAA, 0x5555, 0xAAAA,
    0x5555, 0xAAAA, 0x5555, 0xAAAA,
};

main()
{
    defpattern(1,16,mask1);
    .... start drawing your scene ....
    setpattern(1);  // call before transparent polygones.
    setpattern(0);  // back to solid pattern.
}

this will draw with a pattern with half of the pixels on, half off, which 
looks like 50% tranparent.

I have 16 contiguous patterns like that to define different levels of 
transparency. send me mail if you want a copy of them...

Enjoy !,

P.S. I would recommend using #2 in most cases because it doesn't require pre-
sorting or a two passes approach, and works pretty well in most cases where
only a few transparency levels are needed. The hard thing is to pick a nice
set of patterns which limit the aliasing affect of 16x16 patterns...

-------------------------------------------------------------------------
Alain Dumesny	alain at sgi.com	(415)335-7250	    Silicon Graphics Inc.



More information about the Comp.sys.sgi mailing list