• ### Announcements

#### Archived

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

# Depth Buffer problems...

## Recommended Posts

Hi, It's been a while since I haven't post here, pretty much because I've been busy working on my project for the past month. Me and my friend are currently working on a 3D application for another software company that will generates window from 2d pictures of it. It's going pretty well so far, although we have a little problem... the objects appear transparent, I mean we render the shape of the window and then the frame ( what makes the glass stay into position ). The frame is on the inner side of the shape of the window but if you spin the window around you still see the frame appear through the shape. Here are some links to some pics so you can see for yourself... Square window front view with no lighting Square window side view with no lighting Square window wireframe mode Round window front view with no lighting Round window wireframe mode Now I'm not using any texture yet, could it be why my objects are transparent? because they have no materials? Also my frame is in a seperate vertex buffer than my shape, can it be the reason? It seems to be a problem with the zbuffer not doing its job... but its kinda weird Now I also have a problem with lights... well I don't have much experience with lighting and can't really say I succeeded to really get dx lights do their job right once hehe, I have look into the tutorial in the dx9 sdk but still my light is not doing its job properly. I'm pretty sure the problem is with my vertex normals, because I don't really know how to set them ok. Also the transparency i was talking earlier seems to ply a role as well into that lighting problem, because we see the light go through the model. Here are some shots so you can see the problem... Square window front view with lighting Square window side view with lighting Square window side view with lighting 2 Round window front view with lighting Round window side view with lighting Now the problem you need to consider if you want to help me out is this: I'm creating the vertex buffers and index buffers from scratch, entering all the coordinates by parsing a 2d image for the shape and another for the frame taking into accounts dimensions specified by the user, and I'm rendering with Draw indexed primitive with triangle lists. So I'm not using an already made mesh with texture coordinates and normals already in the mesh file... EDIT: repaired the link to squared window side view no lighting... Stéphane Ross Game Gurus Entertainment [edited by - sross on August 6, 2003 6:15:58 PM] [edited by - sross on August 7, 2003 1:20:50 AM] [edited by - sross on August 8, 2003 5:12:42 PM]

##### Share on other sites
ok, im not sure i understand the issue exactly but let me try.

you have a solid exterior mesh that surrounds a solid interior mesh, but when you rotate the model where the exterior mesh should conceal the interior mesh you can still see the interior?

if thats the case you have a couple of ways to deal with it. first, unless you have to model against a real world object and cant alter the dimensions you''ll want to offset the interior vertices so that they dont share the same space as the exterior.
If thats not an option then youll want to set-up what is called a z-bias. youll have to check in the SDK for more info.

See if that doesnt solve your lighting problem as well. If i misunderstood the question just repost with a more exact explanation and ill see if i can help.

##### Share on other sites
quote:
you have a solid exterior mesh that surrounds a solid interior mesh, but when you rotate the model where the exterior mesh should conceal the interior mesh you can still see the interior?

yea that''s the problem

quote:
first, unless you have to model against a real world object and cant alter the dimensions you''ll want to offset the interior vertices so that they dont share the same space as the exterior.

Yes I can alter the dimension as I wish of the object, the user can enter any dimension he wants and the shape will be scaled to that dimension... but I don''t really understand what you mean. Although I can''t modify the dimension of the frame ( the inner part) independantly of the shape ( the exterior part ) because the frame is fixed using the coordinates of the inner part of the shape.

I''ll check if I can find anything on z-bias on google

thanks

Stéphane Ross
Game Gurus Entertainment

##### Share on other sites
Ok I just read a bit on z-bias, the problem really seems to the depth buffer.

First I realised I made a stupid mistake by forgetting to enable the depth stencil and set the depth format in the present parameters. But then as I modified that, nothing was visible, so i put the z-bias in... at a value of less then 12.94 nothing appears, at 12.94 all appear and the problem is still not solve... well when the window is at a perfect 90 degree the closest inner and exterior part to the camera disapear, so i see only 3 side... If i put it at 12.95 or just 12.945, it is the same as when i had no depth buffer set... everything is always rendered and we see the inner part when we should not. Now I read on MSDN as well that I could change the function that performs the depth compare... that could maybe be a solution but I would really like to find something else if I can... anyone have any clue how to solve this?

Here''s the shot of the window at 90 degree with z-bias at 12.94
Square window side view with z-bias of 12.94 and a missing side...

PS: I''m using the 16-bit depth format... could other format be more accurate and solve the problem? I tried a 24-bit format but it didn''t seem to change a thing...

Stéphane Ross
Game Gurus Entertainment

##### Share on other sites
Did you check the cull mode? The way it looks to me, the faces are flipped? The picture ''Square window side view with lighting 2'' really shows where I''m coming from.

Try adding D3DDEVICE->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); and see what happens. I don''t know if thats the problem, but thats what I would try...

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

##### Share on other sites
quote:

Did you check the cull mode? The way it looks to me, the faces are flipped? The picture 'Square window side view with lighting 2' really shows where I'm coming from.

Try adding D3DDEVICE->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); and see what happens. I don't know if thats the problem, but thats what I would try...

The culling is already at none =/ ...

EDIT: I thought last night that I could maybe use a w-buffer? I don't know much about w-buffer but could they solve that kind of problem?

Stéphane Ross
Game Gurus Entertainment

[edited by - sross on August 7, 2003 11:30:54 AM]

##### Share on other sites
I forgot to mention that in the pics showed above the shape (the exterior part )is rendered BEFORE the frame (the inner part), probly why we see the frame appear over the shape since they are coplanar... although if i render the frame first now the problem is the opposite, the frame is not visible when it should... what should i do...

Stéphane Ross
Game Gurus Entertainment

##### Share on other sites
Well I still haven''t figured out how to solve this problem... Here''s the code I''m using to Init Direct3D... anything I should add or change?

public static bool Init( System.Windows.Forms.Control renderWindow )		{			try			{				Graphics.presentParams = new PresentParameters();				Graphics.presentParams.Windowed = true;				Graphics.presentParams.SwapEffect = SwapEffect.Flip;				Graphics.presentParams.EnableAutoDepthStencil = true;				Graphics.presentParams.AutoDepthStencilFormat = DepthFormat.D16;				Graphics.device = new Device( 0 , DeviceType.Hardware, renderWindow, CreateFlags.SoftwareVertexProcessing, Graphics.presentParams );				Graphics.device.RenderState.CullMode = Cull.None;				Graphics.device.RenderState.Lighting = false;				Graphics.device.RenderState.ZBufferEnable = true;				Graphics.device.RenderState.DepthBias = 12.95f;				//Graphics.device.RenderState.FillMode = FillMode.WireFrame;				return true;			}			catch (DirectXException)			{ 				return false; 			}		}

I know it''s C# and most of you use c++ but you should find your way around cuz it''s pretty much the same except that c# is structured in a more OO way, altho if you know how to solve this in c++, you can post code in c++, I know how to program with DirectX9 in both language so I''ll be able to convert it to c#.

Stéphane Ross
Game Gurus Entertainment

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978708

• 21
• 14
• 12
• 10
• 12