Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


encounter weird problem when turn on the color blending.


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
24 replies to this topic

#1 eric_lie   Members   -  Reputation: 119

Like
0Likes
Like

Posted 29 June 2014 - 01:26 AM

hi guys! I am a rookie in OpenGL, so, please do not laugh at me about my silly questions, aha.

 

here is the thing.

 

I need to turn on the color blending to deliver transparent effect. But weird thing happens, the front side, which is facing the light, looks not bad, like this:QQ截图20140629143801.png

 

but the back side looks awful, seems like some parts of surface are missing, latticed holes, like this:

QQ截图20140629143822.png

 

I tried to add another light on the back side, but both sides turn out to be awful with holes then.

 

Is it a issue related to lights? or texture? or depth test? because if I disable the GL_DEPTH_TEST, holes are gone, but the whole body looks awful, not the way I want it to be looked like.

 

Or it is something else? I even do not know where to get started to solve this problem, someone please help me!

 

 

 

 

For more details, now down to only one object in the scene.

 

This is the front side of the lung:

1.png

 

This is the back side of the lung:

2.png

 

 

BUT, if I change the light in the scene to pointing at the back side:

 

The front side:

3.png

 

The back side:

4.png

 

If I turn on two lights, one pointing at the front, the other pointing at the back, both sides of the object covered with meshes. If remove all lights in the scene, the object looks dark, which is obvious, and both sides of meshes remain. This makes me believe that the light is not the cause of the issue, right?

 

More angles of view, might help you guys to see the meshes more clearly:

333333.png

 

QQ截图20140630224309.png

 

QQ截图20140630224328.png


Edited by eric_lie, 30 June 2014 - 09:14 AM.


Sponsor:

#2 WiredCat   Members   -  Reputation: 358

Like
0Likes
Like

Posted 29 June 2014 - 01:56 AM

if you show us your code , we will see what is causing this trouble

we need to see something like this

 

all opengl calls [initialization and drawing)

then drawing modelitself

all glcalls after drawing

just show us your code, 

 

 

=====

try to set up only one light in the back and see if problem occurs for back of the model) (or set ambient to the same color like diffusion color)

 

its really hard to say what is causing this problem (it may be depth test, wrong order of face drawing, wrong normals for polygons etc)



#3 Stainless   Members   -  Reputation: 1042

Like
1Likes
Like

Posted 29 June 2014 - 02:54 AM

Sounds like you may have a culling problem.

 

Try turning on the depth buffer and setting cull mode to none and see what it looks like.



#4 haegarr   Crossbones+   -  Reputation: 4437

Like
4Likes
Like

Posted 29 June 2014 - 02:56 AM

The most common problem with transparency is that rendering order of faces does not match the requirements of the rendering algorithm. The simplest algorithm needs faces to be rendered in back to front order. This implies meshes to be ordered in dependence of the view, that meshes must not be concave (or else they need to be divided up if a free view is allowed), and meshes must not touch or overlap (or else z-figthing will occur).

 

As WiredCat mentioned we need more details, but also above the code level. What algorithm is used? How are the meshes organized?

 

When you have a problem with a complex scene, reducing complexity first helps to narrow down the cause. E.g. Does the problem occur even if only a single organ is rendered, ...


Edited by haegarr, 29 June 2014 - 03:00 AM.


#5 eric_lie   Members   -  Reputation: 119

Like
0Likes
Like

Posted 29 June 2014 - 04:59 AM

 

if you show us your code , we will see what is causing this trouble
we need to see something like this
 
all opengl calls [initialization and drawing)
then drawing modelitself
all glcalls after drawing
just show us your code, 
 
 
=====
try to set up only one light in the back and see if problem occurs for back of the model) (or set ambient to the same color like diffusion color)
 
its really hard to say what is causing this problem (it may be depth test, wrong order of face drawing, wrong normals for polygons etc)

 


I set ambient to the same color like diffusion color, problem remains.

If I set a light from the back side, the back side of the model looks fine but the front face becomes the weird side instead, and if turn out all lights in the scene, then the whole model is covered with meshes. I thought the light can solve this problem someway somehow at first, but when I turn on all the lights, both in front and back, both sides of meshes remain.

So now I think may be the light is not the key point here.

My whole solution is a little bit complex, it takes time for me to the extract all OpenGL parts out, I will paste my codes here later.

#6 eric_lie   Members   -  Reputation: 119

Like
0Likes
Like

Posted 29 June 2014 - 05:02 AM

Sounds like you may have a culling problem.

 

Try turning on the depth buffer and setting cull mode to none and see what it looks like.

 

you mean glDisable(GL_CULL_FACE) ?



#7 eric_lie   Members   -  Reputation: 119

Like
0Likes
Like

Posted 29 June 2014 - 05:37 AM

The most common problem with transparency is that rendering order of faces does not match the requirements of the rendering algorithm. The simplest algorithm needs faces to be rendered in back to front order. This implies meshes to be ordered in dependence of the view, that meshes must not be concave (or else they need to be divided up if a free view is allowed), and meshes must not touch or overlap (or else z-figthing will occur).

 

As WiredCat mentioned we need more details, but also above the code level. What algorithm is used? How are the meshes organized?

 

When you have a problem with a complex scene, reducing complexity first helps to narrow down the cause. E.g. Does the problem occur even if only a single organ is rendered, ...

 

All organ models are 3DS files which generated by 3DS MAX, and be rendered into the scene from inside to outside, but the thing is, I am rendering a human body here, they can not be simply organized by inside and outside, or front and back, right? Just like you said, I need a free view, I need the whole body can be rotated so that you can see the body from any angle of view. So, at this point, organ A covers organ B (but you still can see organ B through organ A because of transparency), but if rotated around, organ B covers organ A instead. 

 

But if I disable the depth test, if organ A is rendered last, organ A is always covering organ B no matter which side you look at the model, then the whole body looks creepy and weird. It is totally not what I want. The funny part is, now meshes are gone.

 

What's more, if set all color alpha value to 1, which means no transparency at all, and enable the depth test back on, everything looks fine.

 

Like I said to WiredCat, I will paste codes up here after I review all over my solution.

 

Problem still remains even if only one organ in the scene.

 

thanks a lot!


Edited by eric_lie, 29 June 2014 - 05:40 AM.


#8 L. Spiro   Crossbones+   -  Reputation: 14027

Like
4Likes
Like

Posted 29 June 2014 - 05:50 AM

Since you appear to be in the medical industry (a colleague of jenny_wui’s?) where performance is not the main ingredient, you should research depth peeling.
 
http://developer.download.nvidia.com/SDK/10/opengl/src/dual_depth_peeling/doc/DualDepthPeeling.pdf
http://gamedevs.org/uploads/interactive-order-independent-transparency.pdf
 
 
L. Spiro

Edited by L. Spiro, 29 June 2014 - 04:36 PM.

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#9 Ohforf sake   Members   -  Reputation: 1832

Like
1Likes
Like

Posted 29 June 2014 - 07:07 AM

The following is not meant to turn you away, but since you described yourself as a "rookie in OpenGL", I think it should be pointed out to you to prevent any misconceptions:

OpenGL is a thin (most will argue still too thick) api towards the GPU, providing you with the most basic interface to render and shade triangles. You may have noticed, that it doesn't provide any means to load models or textures. The newer versions of OpenGL don't even support lighting out of the box. The idea is that you implement those things on top of OpenGL. This holds for transparency as well. Transparency is not as simple as enabling blending, you have to implement some form of algorithm for it on top of OpenGL. "Depth peeling", as suggested by L.Spiro, is on of those techniques. Splitting the model into parts, whose rendering order gets determined by the camera position (what haegarr suggested), is another one. There are quite a few more.

Using OpenGL (or, for that matter, OpenGL ES, Direct3D, Metal, Mantle, ...) means that you will have to write a lot of code around it,
as these are not intended to be full fledged rendering engines.

#10 WiredCat   Members   -  Reputation: 358

Like
1Likes
Like

Posted 29 June 2014 - 08:56 AM

so less details, but anyway try this:

divide whole model to different organs, then try to render every organ where you begin from those that are deep in the body and you end with drawing lungs

 

also glBlendFunc needs to be set properly (and sometimes glColor4f <- alpha value)

 

we also dont know if your textures have alpha channel but i guess they don't)

 

At first you need to draw parts that are not transparent and then you draw transparent organs in proper order.

 

 

if you manage to sort your faces you will get almost the same effect like disabling GL_DEPTH_TEST but you'll see properly displayed model

 

 

this also try to lower z_near value (in glFrustum) 

 

or scale in ex lungs so lungs faces wont touch other organs

 

 

 

=====================

anyway youll have to sort faces or that would be far way faster and easier -organs

 

 

this is what ahppens when you sort faces.

yu.jpg

 

 

 

 

one that i can say is i see there z fighting problem or wrong face order or wrong blending factors


Edited by WiredCat, 29 June 2014 - 09:28 AM.


#11 Stainless   Members   -  Reputation: 1042

Like
0Likes
Like

Posted 29 June 2014 - 04:32 PM

Looking at those images, I don't think sorting the meshes will help.

 

It looks like some of them actual wrap around the other sub meshes.

 

If that is the case then you have a much more complex problem.

 

I would suggest using volume rendering, but as you stated you a newb at OpenGL, that's going to be a big issue for you. You might be able to just grab an existing OpenGL volume renderer and use it without understanding it though.

 

Have a look at http://idav.ucdavis.edu/~okreylos/ResDev/VolVis/MainPage.html

 

If that seems too much for you, then see if you can split the meshes that cause problems into two, then sort them before rendering.

 

Hope this gives you some ideas.



#12 JohnnyCode   Members   -  Reputation: 272

Like
0Likes
Like

Posted 29 June 2014 - 07:13 PM

 

you mean glDisable(GL_CULL_FACE) ?

never diable cullling, instead reverse what "front face" is.

 

You have a well defined geometry (veru well :)) so:

 

gl.enable(this.m_pGL.CULL_FACE); // yes, I wish to cull
      gl.cullFace(this.m_pGL.BACK); // I want to cull back face
     gl .frontFace(this.m_pGL.CCW); // the front face is counter clock wise face

 

 

... so if after this you change fronts face difintion to

 

  gl .frontFace(this.m_pGL.CW);

 

you will establish front faces as the back faces, thus getting culled front faces "the back faces"

 

and back faces as front faces, being processed, with their vertex attributes in take



#13 JohnnyCode   Members   -  Reputation: 272

Like
0Likes
Like

Posted 29 June 2014 - 07:14 PM

was this scaned from ultra sound device, or an arbitrary artificial model being?



#14 JohnnyCode   Members   -  Reputation: 272

Like
0Likes
Like

Posted 29 June 2014 - 07:17 PM

mind yet, that if you shade back faces with general set up of lighting or other parameters, you may get stranger results, unless you realy understand the geometry with its attributes. (you cannot observe back faces through culled front faces, if you get what I mean- very metaphysical stuff)



#15 eric_lie   Members   -  Reputation: 119

Like
0Likes
Like

Posted 29 June 2014 - 09:03 PM

was this scaned from ultra sound device, or an arbitrary artificial model being?

 

It is just a 3DS model generated by 3DS MAX.



#16 WiredCat   Members   -  Reputation: 358

Like
0Likes
Like

Posted 30 June 2014 - 01:38 AM

so did you make any tests?



#17 eric_lie   Members   -  Reputation: 119

Like
0Likes
Like

Posted 30 June 2014 - 02:12 AM

so did you make any tests?

 

I am working on it. I am sorry to say that what you mentioned did not solve my problem.

 

Now it seems like not that easy to solve this issue. Some of you guys recommend me to resort all objects in a proper way, but even if only a single organ displayed in the scene, the problem still remains. And the thing is, in my case, each object is mapping to other stuff, resorting means changing everything. It does take time to solve this. Seems like a major problem to a rookie like me. 

 

I think Ohforf sake is right, Transparency is not as simple as enabling color blending, maybe this is the key point here!

 

Thanks anyway!smile.png smile.png



#18 haegarr   Crossbones+   -  Reputation: 4437

Like
1Likes
Like

Posted 30 June 2014 - 02:45 AM


Now it seems like not that easy to solve this issue. Some of you guys recommend me to resort all objects in a proper way, ...

Yep. Or else you try depth peeling as is suggested above by LS.

 


... but even if only a single organ displayed in the scene, the problem still remains. ...

Maybe this is because of the already mentioned concavity of the meshes? Question is, if you simplify the scene down to a single organ, do you have a chance to notice whether the problem occurs only if you look through a concavity. If so, then we are on the right track when suspecting the drawing order. A solution then will be to use sub-meshes.

 
But if concavity is not the cause, then we need to investigate further.
 


… And the thing is, in my case, each object is mapping to other stuff, resorting means changing everything. It does take time to solve this.  ...

This isn't a problem solely related to yours. It is common in game engines and elsewhere. And hence there is a solution :)

 

It is possible to have more than a single order on objects. Notice that it is recommended to have several organizing structures, one for each task to do. It is absolutely fine to have a logical organization of the objects, a spatial organization (if collision or proximity is an issue), a render order, and perhaps more. Don't stuck with the über scene graph approach, or you will be lost sooner or later!

 

For example, you iterate the scene description and detect all objects that need to be rendered. You insert each object into a list (which is emptied before the scene is iterated). After finishing, you sort the list by some criterion, in your case using the distance from the current camera. Object rendering then is done in the order given by the list. So rendering has no influence on other aspects of object organization, and nevertheless is done in the required way.

 


I think Ohforf sake is right, Transparency is not as simple as enabling color blending, maybe this is the key point here!

Absolutely. 



#19 WiredCat   Members   -  Reputation: 358

Like
0Likes
Like

Posted 30 June 2014 - 05:57 AM

 

Now it seems like not that easy to solve this issue. Some of you guys recommend me to resort all objects in a proper way, but even if only a single organ displayed in the scene, the problem still remains. 

 

can you upload somewhere this model i want to see it (one organ that is not properly displayed), maybe some face normals are reversed


Edited by WiredCat, 30 June 2014 - 06:01 AM.


#20 eric_lie   Members   -  Reputation: 119

Like
0Likes
Like

Posted 30 June 2014 - 09:23 AM

 

 

Now it seems like not that easy to solve this issue. Some of you guys recommend me to resort all objects in a proper way, but even if only a single organ displayed in the scene, the problem still remains. 

 

can you upload somewhere this model i want to see it (one organ that is not properly displayed), maybe some face normals are reversed

 

 

you mean the 3DS model? I am sure that all my 3DS model are accurate. 

 

Is there any possibility that when I render a 3DS model into an OpenGL scene, the normals are reversed by some inconspicuous mistakes somehow?

 

I upload more detail images, you can check it out.rolleyes.gif rolleyes.gif






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS