# The problem with drawing transparency objects

If two objects intersect and both objects are transparent ( call method SetTransparency ) then final picture is not correct. For expample, if one object is transparent and other is not, then no problems, everything is OK. But If both objects is transparent - then sum of colors is equal, not depence which object is front of view. In a result the 3D picture come totaly not correctly.
1. Green is transparent, brown not - everything is OK (http://foto.mail.ru/bk/regdamir/7/8.html)
2. Green is transparent, brown is a little transparent (http://foto.mail.ru/bk/regdamir/7/9.html)
3. The transparency for objects are equal ( http://foto.mail.ru/bk/regdamir/7/10.html ). In this case in color of front part of brown object should be more brown than other part after green object.

Can I swith OpenCascade in other, more realistics, mode? Please, help me!

I cannot give you an answer, but maybe explain what you have run into.

The reason for the described behaviour is a fundamental principle of 3d graphics:

When drawing multiple translucent objects, the _order_ of drawing is important. Opaque objects must be drawn first, then the transparent sorted form back to front since each Transparent draw operation must take into account what pixels are on the screen already. OCC helps us with this through ensuring the correct draw order for all objects by.

However, simple depth sorting (depth as in distance from screen plane to object) can not help if two transparent objects intersect.

You will have to avoid transparent intersections, or split your objects in a way to make them depth-sortable.

Yes, of course I understand that order of drawing objects is important. In DirectX I draw shapes from back to front object ( as you described ) and picture was more realistic then OCC view ( i can see intersect of two transparent object without any problems ). OCC model also know order of objects - it can draw in mode when only one object is transparent ( see picture 1 from my top post). But when two object is transparent OCC calculate final color of surface independently of shape's order. Why? I could not understand it.
Tilman, can you tell me, that you mean when said to split objects in depth? I don't understand how it can help me, positions of shapes is strictly defined.

Best regards

I guess OCC does it's own sorting of transparent objects prior to drawing them, and thats where the problem might lie. If transparent objects intersect, parts of the objects lie both in front of and behind each other. This means it is not defined wich object should be drawn first.

I attached an example picture of this. The red and green lines can not be drawn in an order in wich one lies in front of the other. The only way to have these two lines being rendered with the correct transparency is to split them into four lines at the intersection point.

The resulting for lines do not intersect anymore an can be rendered corrextly.

The same would work for your objects, but you will be facing to problems:
1) How to split the objects
2) What to do with the common area.

I can not give you advice on how to solve either of these, sadly. A few words for you to google for might be 'clipping' and 'transparent object intersection' for a few hints.

You might want to experiment to join both you shapes to a solid compound and try to set transparency on the resulting new shape, but i don't know if that is what you need.

Attachments: