Archived

This topic is now archived and is closed to further replies.

budipro

How to make transparent objects

Recommended Posts

Hi all, I want to know how to make simple transparent objects, such as a glass. I have tried using alphablending on a simple object (a cone). But if I look from the side of the cone, it seems like a flat triangle. How to make it still has the 3-D appearance? Thanks a lot.

Share this post


Link to post
Share on other sites
glDisable(GL_CULL_FACE);

ie: the back-facing triangles of your cone are being tossed as they typically would be hidden behind the front facing triangles of the cone. Disable the Back-Face culling of the API you are using.


Waramp.

"Before you insult a man, walk a mile in his shoes.
That way, when you do insult him, you''ll be a mile away, and you''ll have his shoes."

Share this post


Link to post
Share on other sites
Thanks for your answer. I guess I don''t write the alpha blending code correctly. Here''s how I do it:

device.RenderState.AlphaBlendEnable = true;
device.RenderState.SourceBlend = Blend.SourceColor;
device.RenderState.DestinationBlend = Blend.InvSourceColor;

Is this correct?

Share this post


Link to post
Share on other sites
Well, I''ve never used D3D so I can''t say, but besides from setting your alpha-blending function you also have to disable the back face culling.

in OpenGL: glDisable(GL_CULL_FACE);

From the sound of your problem it seems that the back of the cone just isn''t ever being drawn due to those triangles being discarded. You want to disable the back face culling so that the rest of the cone is drawn and blended together.





Waramp.

"Before you insult a man, walk a mile in his shoes.
That way, when you do insult him, you''ll be a mile away, and you''ll have his shoes."

Share this post


Link to post
Share on other sites
Yup, I had disabled the backface culling. But still the effect is not quite what I expected, although it''s better (it didn''t looked flat anymore). I tried to rotate the cone, and the backface appearance seems odd.

Share this post


Link to post
Share on other sites
Sounds like the depth buffer''s causing problems.

Try disabling depth writes (if you can''t figure out, try disabling depth tests first to make sure, then ask someone who''s d3d competent how to disable writes but still do tests).

Walt

Share this post


Link to post
Share on other sites
I just found a tutorial about this on Drunken Hyena. I should render two cones, the inner and outer ones, with the inner''s normals pointing inside. This way I could see the inner side of the cone from outside.

Thanks for your answers, guys.

Share this post


Link to post
Share on other sites
Group Transparent objects.
Depth write disabled.
Depth test enabled.
Cull Front faces
Draw Object
Cull back faces
Draw Object.

Here''s the ''good'' way to do it.
Fast and simple.

-* So many things to do, so little time to spend. *-

Share this post


Link to post
Share on other sites
Thanks for your replies, guys.

Finally I can render my transparent cone, using Drunken Hyena tutorial technique. Now my problem is, I got dark shade on the side of the cone which is not facing the light. (I use directional light).
How to eliminate this dark shade, so that the cone is really transparent?

Share this post


Link to post
Share on other sites
Is enabling depth test means enabling the z-buffer? If I enable z-buffer, I just noticed that my transparent cone will have some weird artifacts if the viewer is far away from the object. If I disable the z-buffer, this artifact will not appear, but the cone will always appear in front of other objects. I had also tried to disable depth write (z-buffer write), but still have the same artifact.

How to render the cone correctly?

Share this post


Link to post
Share on other sites