A defect in rendering

Started by
5 comments, last by homo 11 years, 1 month ago

hello

I have found a defect in rendering a model in directx9,the defect is illustrated by the following attach files.when I rotate the model,the defect disappeared.I enabled the depth testing and lighting.here is my code.

[attachment=13974:???.jpg],

D3DLIGHT9 light; // create the light struct
D3DMATERIAL9 material; // create the material struct
DefaultMaterial::getMaterial(material,JADE);
ZeroMemory(&light, sizeof(light)); // clear out the light struct for use
light.Type = D3DLIGHT_DIRECTIONAL; // make the light type 'directional light'
light.Diffuse =material.Diffuse ;
light.Ambient=material.Ambient ;
light.Specular=material.Specular ;
light.Direction = D3DXVECTOR3(-1.0f, -0.3f, -1.0f);

m_pDevice->SetLight(0, &light); // send the light struct properties to light #0
m_pDevice->LightEnable(0, TRUE); // turn on light #0

m_pDevice->SetMaterial(&material); // set the globably-used material to &material

r=m_pDevice->SetRenderState(D3DRS_LIGHTING, TRUE); // turn on the 3D lighting
r=m_pDevice->SetRenderState(D3DRS_ZENABLE, TRUE); // turn on the z-buffer
r=m_pDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(250, 250, 250)); // ambient light
m_pDevice->SetRenderState(D3DRS_ZFUNC,D3DCMP_LESS);
m_pDevice->SetRenderState(D3DRS_ZWRITEENABLE,true);

Does that mean I'm doing something wrong?Thanks for the help!

Advertisement

Yes, you're not using the programmable pipeline.

This might be ZFighting. If you set up your projection matrix with very high far plane distance or a near plane distance very close to zero, depth buffer precision goes kaput.

----------
Gonna try that "Indie" stuff I keep hearing about. Let's start with Splatter.

Yes, you're not using the programmable pipeline.

Please try to be constructive in your comments - this isn't helpful to his current problem, and you don't even provide any background to your statement.

I agree with Schrompf that it might be Z-fighting and could be corrected with modification of your projection parameters.

Yes, you're not using the programmable pipeline.

Please try to be constructive in your comments - this isn't helpful to his current problem, and you don't even provide any background to your statement.

I agree with Schrompf that it might be Z-fighting and could be corrected with modification of your projection parameters.

Agreed - and also to note: if it is z-fighting then using the programmable versus the fixed pipeline will make damn-all difference. You'll still get z-fighting.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Yup, looks like Z-Fighting to me. Here's an article which helps explain how to fix it using various methods and render states: http://software.intel.com/en-us/articles/alternatives-to-using-z-bias-to-fix-z-fighting-issues

I'm going to assume you're using D3DFMT_D24S8 as your depth buffer format. If you're using D3DFMT_D16, then you're more likely to get Z-Fighting artifacts.

Shogun.

Thanks for the tip.I changed D3DFMT_D16 to D3DFMT_D24X8; it works very well.

thanks!

This topic is closed to new replies.

Advertisement