• Advertisement
Sign in to follow this  

A defect in rendering

This topic is 1781 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

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!

Edited by homo

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

thanks!

Share this post


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

  • Advertisement