Jump to content
  • Advertisement
Sign in to follow this  

Seeing throught objects

This topic is 2790 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi ,

In my scene , I need a mesh which has many objects itself.
Unfortunately I can see thru objects , so I can see even objects behind other objects
which is something I dont want :

-DX SDK s mesh viewer is able to render it properly so I dont see thru objects in the mesh

- There is no textures applied , so I am sure it has nothing to do with texture stages

-For my rendering parameters :
backface culling has turned off ( for debugging )
z buffering has been turned on

So what do you suggest me to check ?

Share this post

Link to post
Share on other sites
Sounds like you have alpha blending enabled.

Have you checked your Pixel Shader Code if the Alpha-Value gets calculated correctly?

Things you could try:

- just before the return command in your pixel shader, set your Out-Color Alpha value to 1.0f
- Turn the Alpha Blend state off for that Pixel shader

Share this post

Link to post
Share on other sites
Sorry , i forgot to mention it ,
no i turned alphablending off before rendering and it is not being turned on anywhere:

myDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );

Just in case all `alpha` values in my lights and materials are zero even i turned alpha blending off...

And also I dont have any shaders at the moment

Share this post

Link to post
Share on other sites
For both cases (1 and 0) it does not change anything

( I have just 1 directional lgiht and 1 material )

Share this post

Link to post
Share on other sites
Wait a minute... By "Seeing Through an Object", what exactly do you mean?

Is the object infront blended with the object in the Back? Like looking through a colored Glas window?

Or is it drawing the object in the back on top of the object infront?

Share this post

Link to post
Share on other sites
The first one :

"the object infront blended with the object in the Back"

For example there is a house in my scene , its door is open , DX SDK mesh viewer
just shows the interior of the house , whereas my code shows interior blendded with things in the back of that house.

Alphablending is turned off , Zbuffering is used properly, there is no textures so nothing todo with texture stages or texture blending

Share this post

Link to post
Share on other sites
Post your code for setting the device state ( SetRenderState(...), etc. ) and the code for rendering the mesh. Please use [code][/code] or [source][/source] tags.

Share this post

Link to post
Share on other sites
the repro code is as below.
The problem is as I said , i can backs of objects...

As I play with lighting it does not change it.( if i just set ambient light something like 255-255-255-1 this time I dont see back of objects but I cant see details in the objects since intensity of light is too much )

But please note that if I fill vertex buffers customly with the vertex type
with appropriate surface normals, then i have no problem...

I have found some 3dsmax models , converted them to X by using Panda and the problem occurs for them...

Also would there be any workaround by texturing and setting texture stages properly ?


// Create the D3D object.
if (NULL == (g_pD3D = Direct3DCreate9(D3D_SDK_VERSION)))
return E_FAIL;

// Set up the structure used to create the D3DDevice
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

// Create the D3DDevice
&d3dpp, &g_pd3dDevice)))
return E_FAIL;

// Enable the Z buffer, since we're dealing with 3D geometry.
g_pd3dDevice -> SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);

return S_OK;

2. Load a mesh , setup view and projection matrix

3. Lighting :

VOID SetupLights()
// Define a light - possesses only a diffuse colour.
D3DLIGHT9 Light1;
ZeroMemory(&Light1, sizeof(D3DLIGHT9));
Light1.Type = D3DLIGHT_POINT;

Light1.Diffuse.r = 1.0f;
Light1.Diffuse.g = 1.0f;
Light1.Diffuse.b = 1.0f;

Light1.Position.x = 25.0f;
Light1.Position.y = 30.0f;
Light1.Position.z = -50.0f;

Light1.Attenuation0 = 1.0f;
Light1.Attenuation1 = 0.0f;
Light1.Attenuation2 = 0.0f;

Light1.Range = 500.0f;

// Select and enable the light.
g_pd3dDevice -> SetLight(0, &Light1);
g_pd3dDevice -> LightEnable(0, TRUE);
g_pd3dDevice ->SetRenderState(D3DRS_LIGHTING,TRUE);


4. Render

void Render()
g_pd3dDevice -> Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

// Begin the scene
if (SUCCEEDED(g_pd3dDevice -> BeginScene()))


for (DWORD i = 0; i < dwNumMaterials; i++)

g_pd3dDevice -> SetMaterial(&(MeshMaterials));
g_pd3dDevice -> SetTexture(i, MeshTextures);
Mesh -> DrawSubset(i);
g_pd3dDevice -> EndScene();

g_pd3dDevice -> Present(NULL, NULL, NULL, NULL);

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!