encounter weird problem when turn on the color blending.

Started by
23 comments, last by L. Spiro 9 years, 9 months ago

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:[attachment=22381:QQ??20140629143801.png]

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

[attachment=22382: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:

[attachment=22411:1.png]

This is the back side of the lung:

[attachment=22412:2.png]

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

The front side:

[attachment=22413:3.png]

The back side:

[attachment=22414: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:

[attachment=22415:333333.png]

[attachment=22416:QQ??20140630224309.png]

[attachment=22417:QQ??20140630224328.png]

Advertisement

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)

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.

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, ...

 

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.

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) ?

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!

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

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

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.

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

This topic is closed to new replies.

Advertisement