Jump to content
  • Advertisement


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


Gouraud Shading

This topic is 5741 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 all, I have a shading problem. In my application I am rendering a sphere, and I have a point light rotating around it. It works as expected except for one thing... the sphere mesh I am using does not have a sufficient enough poly count as to hide the unsightly shading as the light rotates around. It performs semi-smooth / jumpy shading as the light moves around the sphere. I've read up about this, and from what I understand, my mesh has vertex normals which the D3D lighting engine uses to determine the rendered color of the mesh faces (I have not set up any SHADEMODE render states, so it uses the default of D3DSHADE_GOURAUD). It seems to me that this is where my problem lies. I've read up about Gouraud shading, which appears to use these vertex normals to calculate shading. If I understand correctly, my mesh does not have those normals defined in such a way to create a smooth shading across face-edges... each triangle seems to have each vertex normal the same as the face normal vector. Anyway, the point of my post is this: If my assumptions above are correct (I'd sincerely appreciate correction if not), is there an accepted/well-understood method to generate the vertex normals I need? I'd appreciate any help which would put me on the right track. Thanks. [edited by - Lythic on September 30, 2002 7:03:23 PM] [edited by - Lythic on September 30, 2002 7:05:00 PM]

Share this post

Link to post
Share on other sites
Hi Jim,

Thanks for your response. I was sure that your suggestions would drive this issue home. It made perfect sense, but I encountered some unexpected results that I was hoping someone might be able to clear up. I'll summarise the events:

"Try using D3DXComputeNormals if your mesh is stored in an ID3DXMesh object" - I was sure this would fix the problem, as I felt from the visuals that the vertex normals in my mesh were not averaged with the adjacent faces.

Reading up about D3DXComputeNormals, it takes 2 params, and seems to solve specifically the problem I thought I had. Unfortunately, my mesh was not a ID3DXMesh object. I converted it in a few minutes, and implemented the call to D3DXComputeNormals. Here is my code:

LPD3DXBUFFER pAdjacencyBuffer = NULL;

hr = D3DXLoadMeshFromX( "sphere.x", D3DXMESH_SYSTEMMEM, m_pd3dDevice, &pAdjacencyBuffer, NULL, NULL, &m_pMesh );
return hr;

hr = D3DXComputeNormals( m_pMesh, (DWORD*)pAdjacencyBuffer->GetBufferPointer() )
return hr;

This executed without any (perceived) problems or exceptions, and rendered the mesh... but in exactly the same way as before. There seemed to be no difference at all to the shading of te rendered sphere. Still not smooothly shaded.

Viewing this sphere mesh in "Mesh Viewer" I see a smooth-shaded rendered sphere... so I know it's possible with this specific mesh, but I don't understand why computing the vertex normals didn't work. Everything I have read indicates that this is the cause. In fact, I still think it is the cause, and my opinion now is that somehow D3DXComputeNormals is not successfully computing the vertex normals (Insanity is creeping up on me).

When I tried this initially, I had the second parameter of D3DXComputeNormals as NULL, which also resulted in a rendered non-smooth shaded sphere. I guessed that the second parameter was needed (a buffer indicating adjacent vertices/faces), and the SDK documentation seemed to say the same thing. I googled the D3DXComputeNormals, and could not find any more information other than what the SDK had already stated.

I played with the lighting attenuation0 but any value betwee 0.0 and 1.0 has no effect. attenuation1 seems to have an effect on the shading, but nothing to fix the issue.

I am convinced that a smoothly shaded sphere can be rendered without incurring insane poly counts, but it just is not happening.

I would be grateful if someone could point me in the right direction.

Once again, thanks for the help.

[edited by - Lythic on October 1, 2002 3:21:00 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!