C Senthil Kumar

I have written a program in VC++ and DX9 to achieve specular lighting. I am using the models provided with the DX SDK for testing purpose. Specular lighting is working for some models (dolphin) and it is not working for other models (like teapot).

Is there something that we should specify in the .X file for specular lighting or is everything related to the code alone

Also, I don't have access to any 3D modelling software right now. So please don't ask me to create my own model for solving this problem. I will do so when I get one, along with an exporter. Please tell me what's wrong/missing with the other models in the SDK or is it something I should include in the code.

I would greatly appreciate if someone could help me with this problem.

Thanks!




Re: Game Technologies: Graphics teaport

Bad Habit

It¡¯s more than likely that the teapot¡¯s material doesn¡¯t have a specular value set. Before setting it¡¯s material for render try changing the specular colour and the power, have a look at the dolphin material or even use that material.





Re: Game Technologies: Graphics teaport

C Senthil Kumar

I don't think that the material is the problem because, in my code, I am ignoring the material from the .X file and setting my own material through code.

//------------------------------------------------------------------------------------------

D3DMATERIAL9 mtrl;

ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) );

mtrl.Diffuse.r = 0.25f;

mtrl.Diffuse.g = 0.25f;

mtrl.Diffuse.b = 0.25f;

mtrl.Specular.r = 1.0f;

mtrl.Specular.g = 1.0f;

mtrl.Specular.b = 1.0f;

mtrl.Emissive.r = 0.15f;

mtrl.Emissive.g = 0.15f;

mtrl.Emissive.b = 0.15f;

 

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

{

//pd3dDevice->SetMaterial( &g_pMeshMaterials [ i ] );

pd3dDevice->SetTexture( 0, g_pMeshTextures [ i ] );

g_pMesh->DrawSubset( i );

}

//------------------------------------------------------------------------------------------

 

I used the above material for both the dolphin model and the teapot model, AND I ignored the material contained within the file.

Even then, I get specular lighting for the dolphin and not for the teapot!

 

Is there something wrong with the material code or am I missing something here...






Re: Game Technologies: Graphics teaport

Bad Habit

The only thing I see missing is a value for the materials power, which is directly related to specular highlighting. Also, specular lighting is off by default and you need to enable it by setting the D3DRS_SPECULARENABLE render state to TRUE. Also check that the mesh has normals, you can check this like:

if((teapotMesh->GetFVF() & D3DFVF_NORMAL) == 0)
{
// No normals, clone the mesh to use normals and
// use D3DXComputeNormals to calculate normals
}

Launch the DX documentation and type ¡®specular¡¯ in the search tab, it¡¯ll throw up loads of information for you, well worth a read.





Re: Game Technologies: Graphics teaport

C Senthil Kumar

I am sorry, I always forget to say something when posting here.

I posted a part of the code just to show you that I am using my own material.

In my actual code I have...

1. Computed the normals
2. Set the specular power and
3. Enabled specular lighting

... the three things you said were missing. Even after all this, I don't get the specular lighting for some models. If you need it, I could post my entire code...

Thanks






Re: Game Technologies: Graphics teaport

Bad Habit

The only two other things that I can think of at the moment are if the object¡¯s vertex normals are becoming non-normal because of transformations, you can set the render state D3DRS_NORMALIZENORMALS to TRUE so D3D renormalises them. The other thing is the angle between the light source, reflection and viewer, so it could be a good idea to set a few lights up in different positions and test them individually. The thing is with one model you¡¯re getting the highlight but with the other, which you¡¯re using the same material and you¡¯ve calculated the normals, you¡¯re not getting the highlight, it sounds like a positional thing.





Re: Game Technologies: Graphics teaport

C Senthil Kumar

It worked! Your suggestion on setting D3DRS_NORMALIZENORMALS to true worked!

Now I am getting specular lighting for all models!

Thanks a lot!

Also (this problem is not related to specular stuff), I am getting some artifacts in various models... especially those in which several basic shapes have been put together... for example, in the teapot model, I get these artifacts where the nose (or whatever it is, through which something is poured out) and the main teapot body meet. The meeting place is like a saw tooth... jagged without any smoothness.

How can I solve this problem

Thanks.





Re: Game Technologies: Graphics teaport

Bad Habit

The problem there would more than likely be because the teapot is actually composed of more than one mesh. If you load it up in the DX viewer and switch to wire frame mode you can see the three parts, body, handle and spout. The spout has just been shoved in the body more than likely crossing the triangle faces which the lighting engine uses to calculate lighting effects. If you have an editor then you could use that to weld the spout vertices to the body vertices and turning the thing into a single mesh so the triangles run from the body and onto the spout so the lighting engine would take that into account.





Re: Game Technologies: Graphics teaport

C Senthil Kumar

Thanks for telling me where the problem is.

But, when I weld the vertices using the SDK Mesh Viewer, the artifacts are still present. In the Weld Meshes dialog, there are some options. Which one(s) should I choose

Will it work if I welded the vertices using some other editor and then export it to .X

Thanks.






Re: Game Technologies: Graphics teaport

Bad Habit

I did a bit of an experiment with the teapot. I tried the face welding but that too showed the artefacts that you mention, so no good there. Then I subdivided the mesh once, taking the number of vertices from 1178 to 6866, which produced a nice finish. Subdivided again to 27266 vertices which slightly improved the output. Then again to 43138 vertices which marginally improved the finish.

Just subdividing the once really improved the quality of the output, especially the spout which was all jagged. So sorry, my mistake on the previous post, it seems like the face count wasn¡¯t up to scratch to produce the required finish.

Since you don¡¯t have an editor at the moment I could send you a couple of subdivided teapots. Text files are quite large, 6866 = 2.13 MB and 27266 = 8.25 MB, while binary files are smaller, 6866 = 992 KB and 27266 = 3.72 MB. Just let me know.





Re: Game Technologies: Graphics teaport

C Senthil Kumar

Thanks for your effort! With the SDK's mesh viewer, I increased vertex count to around 18000 but I still get artefacts. If you think that having high vertex count (43000 as you said) really makes a difference, then send the file to senthil.uac@gmail.com. But, it is taking too much memory, around 4 MB and takes a few seconds to load!

I would rather stick the different components of a model correctly when I make my own models rather than have polygon counts in the tens of thousands and vertex counts in hundreds of thousands!

Anyway, thanks for taking your time to help me out.






Re: Game Technologies: Graphics teaport

mbongeni

hi there,

could someone please explain what the teapot program is all about in Direct X9 I am new to this and I just need some background info before I can get started.

Thanks