Advertisement

Problem with D3D semi-transparent cube. HELP!

Started by June 11, 2002 06:35 PM
7 comments, last by RageMatrix 22 years, 6 months ago
Hey all, I have yet another problem with D3D cubes. I'm trying to make my cube class have a function to turn on and off semi-transparency. It sort of works. I enable the alpha-channel and turn off backface culling so that you can see the faces of the cube that are not facing the camera. However, some faces seem to be missing as shown below. This is correct, you can see all the other faces through the translucent front face. This is wrong. The bottom and left faces do not show through the front face. Any idea what the problem might be here? Drunken Hyena's tutorials use two cubes one inside the other, the inside normals facing inwards. However, I'm not using any lighting in my code. Any help? Rage_Matrix Tron Software -=Kicking Butt and Writing Code=- [edited by - RageMatrix on June 11, 2002 7:37:13 PM]
First render with front-face culling (usually clockwise), then render again with back-face culling (usually anti-clockwise).
I think you can turn off the z-buffer while rendering the back faces, but it''s not neccessary.
This will also work for other concave shapes such as spheres etc.
Advertisement
So you''re saying to render it twice, once with front-face culling and then again with backface culling? If so, wouldn''t you be rendering twice as much for translucent cubes as for solid cubes. Wouldn''t that be a drain on performace?

I''m not doubting you, I''m just asking.

Rage_Matrix


Tron Software

-=Kicking Butt and Writing Code=-
To get the semi-transparency, you have to render both front and back sides of the cube. If you have depth testing (aka z-buffering) enabled, once you draw the front side of the cube you can''t draw the back side, because pixels closer to the viewer than the back side are already on the screen. If you render your cube so that the back side always gets rendered before the front side, everything is fine. In the opposite case, the backside will never be drawn. So you render your cube twice: first the sides facing away from the camera, then the sides that are facing toward it.
---visit #directxdev on afternet <- not just for directx, despite the name
Thanks very much! That works a treat.



Rage_Matrix


Tron Software

-=Kicking Butt and Writing Code=-
Bleh... This ain''t the DirectX help, this is BEGINNER forum.

(I feel initimated )

I can barely do DirectDraw...

______________________________________________
You know your game is in trouble when your AI says, in a calm, soothing voice, "I''m afraid I can''t let you do that, Dave"
Advertisement
Well, I wasn''t sure how hard it was. Besides, nobody answers me in the DirectX help. Thus I assumed it was a beginners problem.

Rage_Matrix


Tron Software

-=Kicking Butt and Writing Code=-
You''re not really rendering it twice - just rendering the back half then the front haLf. half + half = 1. So it''s not really that slow.
Thanks, I see what you mean. This way only works without lighting right now. If I were to reverse the normals for front and backface culling, so when for example, drawing the back faces with front face culling I reversed the normals it should still work, right?

Rage_Matrix

Tron Software

-=Kicking Butt and Writing Code=-

This topic is closed to new replies.

Advertisement