Welcome! Log In Create A New Profile


Transparent 3D objects

Posted by csanii 
Transparent 3D objects
February 24, 2009 02:18AM
I am trying to get some very basic code working. I have 2 solid cubes on screen however what I want is for them to appear transparent so it looks like 2 glass cubes which ultimately I want to overlap(hence the need for transparency). The problem I am having is finding some sample code for transparency as my code hangs my Wii, although it compiles without issue.

Can someone extract a few lines that specify how to setup transparency from one of their existing projects and help me out?
I am using "vanilla" DevKitPro with the GX_* functions.

Is there a simple way to make the edges of an object visible? The reason I ask is that if a simple cube is all 1 color then if you just rotate it about its vertical axis, with no visible edges it just looks like a growing and shrinking rectangle.....Basically is there a way to make the edges of an object 1 color while the faces are a different color without using textures ?

Thanks in advance.
Re: Transparent 3D objects
February 24, 2009 01:10PM
Answer one:

Could you post the code you have written for transparency? You could take a look at revloution engine 0.3's source. It uses transparency for objects (Thought with some little bugs)

By the way, I can tell you what I'm doing in revolution engine 0.4 for transparency:
There are two types of transparency: Object transparency (applies to the wole object) or texture transparency (using the alpha channel of the texture) I suppose you're interested in the first type.
The basic steps are:
-Set the tev stage: Zcompare, blending mode, number of channels, etc...
-Order your transparent objects depending on their distance to camera
-Render them form far to near

Tell me where you have problems and I'll try to help you.

And about your second question:
Yes, there is one: you can render lines (GX_Begin(GX_LINES, GX_VTXFMT0))
Or you could use lighting in order for each face to look diferent form others, but this is much more difficult

Hope that helps
Re: Transparent 3D objects
February 24, 2009 04:59PM
technik's advice is probably what you should look in to with GX.

With "normal" OpenGL there are some very simple ways of doing both of your questions:
1) glDepthMask(GL_FALSE); would disable writing to the Z buffer, leaving Z reading turned on...this would allow you to draw transparent objects in any order (no z-sorting required), that's providing you select the correct blend function.
2) glPolygonMode(GL_FRONT_AND_BACK, GL_LINES); with a "line width" of say 2 or 3. Or if you want lines of 1 pix width, then glPolygonOffset(-1, -1); would shift your rendered "lines" away from your rendered box...but saying all that, as your box in the above example is translucent then in that case you would not need to do anything as the Z-buffer would have been disabled when you rendered the box. (edit) actually, you would want to draw the lines first so that the front faces blend over the rear lines, plus you would want to increase the line width or z-shift to prevent the front faces from blending over the lines!

Of course, GX works slightly differently. You will need someone with more GX experience to advise you if these features are present and in what form.

Edited 1 time(s). Last edit at 02/24/2009 05:02PM by blitter.
Re: Transparent 3D objects
February 25, 2009 11:36AM
Ops, I didn't remember that. Using GX you can dissable writting to the Z buffer just using
I know there is some way to keep reading from it while not writting but I don't use it because it fakes transparency. In real life seen transparent object A behind B looks different from seeing B behind A. So writting independently from the Z order produces an uggly effect, so I don't recomend it. Actually it doesn't look uggly, but it can look better.
Re: Transparent 3D objects
February 27, 2009 02:37AM
I must be missing something. I am using the example code from NeheGx (Lesson5)
I have managed to figure out what is hanging my code but as to why I am not sure....

I am using this to do my setup....
GX_SetTevOp(GX_TEVSTAGE0, GX_BLEND); -> I changed this to BLEND from PASSCLR

I have some other lines of code in between.....
u8 r=1,g=0,b=0,a=0.5; // declares some variables

I am using this to start drawing my cube
GX_Begin(GX_QUADS, GX_VTXFMT0, 24); // Draw a Cube
GX_Position3f32( 0.75f, 1.0f,-1.0f); // Top Left of the quad (top)
GX_Color4u8(r,g,b,a); // ***This causes the Wii to HANG ????
GX_Color3f32(0.0f,1.0f,0.0f); // Set The Color To Green - THIS LINE WORKS!!

If I use GX_PASSCLR and GX_Color3f32 I get shapes that appear solid (but I want transparent so I use GX_BLEND
If I use the GX_BLEND and GX_Color3f32 I get shapes that are drawn but the colors are striped even though they should be solid.
If I use GX_BLEND and GX_Color4u8 the Wii hangs

Any idea what I might be doing wrong?
I am assuming I can just set the blend and set the alpha to 0.5 and thus have the object be semitransparent.

Is there some additional code I need to be adding to enable this?
Are there some tutorials you can point me to for further info?
Re: Transparent 3D objects
February 27, 2009 04:22AM
It is hanging due to expecting RGB8, and you are supplying RGBA8 (I had a similar overlook recently ;))

Change: GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGB8, 0);
Now you can supply the alpha component too: GX_Color4u8(colour.r, colour.g, colour.b, colour.a); (I wonder why something like GX_Color1f32(&colour.r); doesn't exist?)

*However*, the alpha will now have an effect on textures - but I haven't used alpha on just a 'solid' colour in GX, and it doesn't appear to have any effect! I'm sure there's a way, but my knowledge is OGL and it's taking a minute to adapt...

...tutorials seem few and far between, I haven't really seen any! Nehe has all original lessons (40+) which you could learn concepts from, and gamedev.net have great forums and resources...but GX, well here's the thing...Wii homebrew is unlicensed and some developers might not be interested in helping unofficially!
Re: Transparent 3D objects
February 28, 2009 05:58PM
Thx Blitter, I never would have figured out the RGBA8 issue.
Now the code compiles with GX_Color4u8(r,g,b,a); and it runs without hanging.

Trouble is I still have the colors showing up as striped. Perhaps I need to create a solid color texture and then apply that with blending to get this to work as planned....I will have to give that a try and see if it solved the strange flashing stripes I get now.
Re: Transparent 3D objects
March 02, 2009 01:29AM
Just a thought mate, try adding these lines of code to your init:
Sorry, only registered users may post in this forum.

Click here to login