PDA

View Full Version : problem with transparency



alex2
04-11-2011, 10:47 PM
I have 2 cubes, one is closer, second is further. When I look at straight ahead closer and further cubest looks strange (closer cube is too much transparency), when I rotate camera about 270 degrees second cube looks ok (it isn't so transparent like first one):

http://img34.imageshack.us/i/55489397.jpg/

What is going on ?
My code:



//here draw some other objects

glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

//here draw closer cube

glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);

//here draw other objects

glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

//here draw further cube

glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);

//here draw other objects

ZbuffeR
04-11-2011, 11:53 PM
Blending does not work with depth testing.
Search the forum / the web / the wiki for details, any solution will be a "performance versus visual quality" tradeoff.

alex2
04-12-2011, 12:09 AM
But when I glDisable(GL_DEPTH_TEST) then mine cubes are always closer then other objects - effect is horrible. I have strong computer so I don't need to performance - what is the solution ?

Alfonse Reinheart
04-12-2011, 12:32 AM
Did you do what ZbuffeR said and do a search?

alex2
04-12-2011, 12:48 AM
Before I had written here I searched.

ZbuffeR
04-12-2011, 12:58 AM
First, in any case, opaque objects "//here draw other objects" should be drawn FIRST. This is extremely basic stuff, and you have not done it...
So what other information did you learn from your searches ?

Alfonse Reinheart
04-12-2011, 12:59 AM
Before I had written here I searched.

Why do people think they can say "I searched" when it's so easy to show they didn't? Google for "blending depth buffer" (http://www.google.com/search?hl=en&client=firefox-a&hs=70t&rls=org.mozilla%3Aen-US%3Aofficial&q=blending+depth+buffer&aq=f&aqi=&aq l=&oq=). The very first hit (http://www.sjbaker.org/steve/omniv/alpha_sorting.html) explains your problem in detail and the solution to it.

alex2
04-12-2011, 01:28 AM
Thx it works but http://www.sjbaker.org/steve/omniv/alpha_sorting.html

"The first fix - upon which all the other fixes depend is to make sure you draw all your opaque polygons before you draw any translucent ones. This is easy to do in most applications and solves most of the problems. The only thing that remains is when you try to render one translucent polygon behind another."

Strange - for me it works when I draw first transparent objects and then not transparent - why ? And in this article they said that I should first draw not transparent and then transparent.

BionicBytes
04-12-2011, 02:10 AM
Strange - for me it works when I draw first transparent objects and then not transparent - why ? And in this article they said that I should first draw not transparent and then transparent.

....and if you change your field of view (ie rotate the scene or camera position)? I bet it does not work after that.

alex2
04-12-2011, 02:16 AM
hm yes..... you know something - could you tell ? :)

BionicBytes
04-12-2011, 02:24 AM
...otherwise you have just stumbled upon a magic formula and we'd all want to know what that is.

Your magic formula could have made you rich and famous....if it wasn't for the fact that it was just plain wrong. LOL!

alex2
04-12-2011, 06:25 AM
I must say that I don't understant your joke - English isn't my national language so I don't know what is going on.

ZbuffeR
04-12-2011, 07:08 AM
Not my native language either.
Really alex2, just draw first opaque objects, with depth test and writes.
Really.
Then learn to learn from advices given to you.
Might require more GL knowledge than you currently have, but some solutions are full sorting of triangles, depth peeling, weighted average transparency, etc, recently discussed here :
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=294075

alex2
04-12-2011, 07:21 AM
But in that way mine cubes are totally invisible :P lol

And I use materials:
GLfloat MaterialBlack[] = {0.0, 0.0, 0.0, 0.5};
GLfloat MaterialSilver[] = {0.75, 0.75, 0.75, 0.5};


so I should see them