Sign in to follow this  
Medo Mex

Loading Mesh with Specular Level

Recommended Posts

Medo Mex    891
I create a mesh in 3Ds Max, sometimes I apply specular level in the materials window which make the mesh appears more realistic, I export the mesh to .x file and load it using DirectX 9 and C++, the problem is that I don't see the specular level that I have applied in 3Ds Max.

How can I load .x file in DirectX 9/C++ with specular level according to the material applied in 3Ds Max?

[attachment=12651:0.png]

Share this post


Link to post
Share on other sites
kauna    2922
Well have you enabled specular highlights for your rendering? Ie. setting D3DRS_SPECULARENABLE to true?

You don't give much of information about the rendering code so this is just guessing.

Cheers! Edited by kauna

Share this post


Link to post
Share on other sites
Medo Mex    891
No, I was not setting D3DRS_SPECULARENABLE to true, now I tried to set it to true by using:
[CODE]device->SetRenderState(D3DRS_SPECULARENABLE, TRUE);[/CODE]

but still no specular. Edited by Medo3337

Share this post


Link to post
Share on other sites
kauna    2922
Another thing to check is that your Light structure has some meaningful value for the specular color.

[url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb172566(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb172566(v=vs.85).aspx[/url]

Cheers!

Share this post


Link to post
Share on other sites
Medo Mex    891
I'm not creating any light using DirectX, I'm just using 3Ds Max to set the specular level as you see in the above screenshot, then I use the following code to render the mesh after loading the mesh from .x file:

[CODE]
device->SetRenderState( D3DRS_LIGHTING, TRUE );
device->SetRenderState( D3DRS_SPECULARENABLE, TRUE );
device->SetRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL );
// Code to draw the mesh here...
[/CODE]

Share this post


Link to post
Share on other sites
kauna    2922
Well is there a light source in the scene? Does your diffuse lighting work as intended?

Can you confirm that the exported x-file contains lights and that your rendering code sets the lights?

A screenshot of your program with the model would help also.

Cheers! Edited by kauna

Share this post


Link to post
Share on other sites
Medo Mex    891
In 3Ds Max, I'm only changing Specular level value, I don't add any other light, when I load the .x file into DirectX Viewer, I don't see the specular as well, I'm trying to use Panda DirectX Exporter to export from 3Ds Max, I'm not sure if it export information about the specular level that I set in the material window. Edited by Medo3337

Share this post


Link to post
Share on other sites
Anddos    588
ive never tried adding specular in 3dsmax to a mesh, but i know how to add a specular on a model with .fx which gives off a nice effect like this

[img]http://img152.imageshack.us/img152/1400/tinyspec.jpg[/img] Edited by Anddos

Share this post


Link to post
Share on other sites
Medo Mex    891
The main question is: Does .x file export specular level from 3Ds Max? If not, then what is the solution for exporting specular information? Maybe I should use another .x file exporter or read it from effects file.

Share this post


Link to post
Share on other sites
kauna    2922
According to the .x file specification, the material data should contain the specular color and power values.

MSDN spesifications on the .x file.
[url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb147174(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb147174(v=vs.85).aspx[/url]

Other question is that if your exporter supports them, although they are rather basic for typical lighting models.

Are you able to look in to the data and see if the materials have specular values?

Cheers!

Share this post


Link to post
Share on other sites
Medo Mex    891
I think the exporter support them, I tried to calculate the MD5 hash for .x file with specular level and another .x file with the same mesh and same everything except different specular level and it's showing different MD5 hash, the attached file is a sphere that I added a specular level to it, you can check it out and let me know if it has specular level and how can I render it in DirectX with it's specular level.

Share this post


Link to post
Share on other sites
cgdev    411
Hi, My directx exporter has make a update. Now it can export the power of specular and support 3ds Max 2013 ! The following is the result from my x file exporter:

Material _01_-_Default {
0.388235;0.411765;0.576471;1.000000;;
0.780000; //specular power
0.900000;0.900000;0.900000;;
0.000000;0.000000;0.000000;;
}
Mesh Sphere001 {
482;
...
If you want to use my exporter, download the [url="http://www.cgdev.net/download.php"]axe free edition[/url] :)

Share this post


Link to post
Share on other sites
Medo Mex    891
Hi Alin,

What render state should I use before the line mesh->DrawSubset(); so I can have the mesh drawn with specular level?

I tried to export using your exporter and draw the mesh using the following code:
[CODE]m_d3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
m_d3dDevice->SetRenderState(D3DRS_SPECULARENABLE, TRUE);
m_d3dDevice->SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL);
mesh->DrawSubset(i);[/CODE]

I still don't see the specular level.

Share this post


Link to post
Share on other sites
cgdev    411
Do you extract the power from x file ahd set the material? like this:
D3DMATERIAL9 mtl;
mtl.Power = 78;
...
m_pd3dDevice->SetMaterial( &mtl );
...

Share this post


Link to post
Share on other sites
Medo Mex    891
When I set the specular level to 100 in 3Ds Max, I can see that [i]material.Power[/i] value is 1.0, I tried setting the material using m_pd3dDevice->SetMaterial( &material ); but can't see the specular level.

Also, I'm only loading the mesh, I don't use D3DLIGHT in the scene.

Share this post


Link to post
Share on other sites
kauna    2922
I'm still wondering how do you see the model if there isn't any light sources. Can you get a screen shot of your screen to show the output of your program.

Specular high lights are strongly dependent on the light source position / direction so I'm not sure what you expect to get if you don't have a light source in the scene.

Cheers!

Share this post


Link to post
Share on other sites
Medo Mex    891
I want to see the mesh exactly as I see it when I render it in 3Ds Max, I'm not adding any light in 3Ds Max, just changing the specular level, so I want it to appear exactly as I see it in 3Ds Max. Edited by Medo3337

Share this post


Link to post
Share on other sites
kauna    2922
And how do you suppose MAX is able to show the mesh with specular highlights if there isn't a light source in the scene?

The answer is : 3DS MAX has a light source in the scene (called Default Light) which will disappear when you place the first light source in the scene.

So to answer your question in a short way : you'll need a light source which has the same properties as the MAX default light in order to see the model lit as in 3DS MAX.

Best regards!

PS. I have asked a screenshot of your program 2-3 times now. I don't make such request without a reason. Looking at an image gives a lot more information than one person telling what he is doing or not doing or what he wishes that his program would do.

Share this post


Link to post
Share on other sites
Medo Mex    891
I have attached a screenshot of the mesh.

Now, do I have to create light for every mesh with specular so I can have more realistic mesh? what light settings should I supply to D3DLIGHT so I can see something similar to 3Ds Max?

Regards!

[attachment=12752:world.png]

Share this post


Link to post
Share on other sites
kauna    2922
Well the screenshot lacks also diffuse and ambient lighting on the model so that kind of confirms that the missing light is a problem.

You don't need to include a light source with your models. You may create a light source in your program.

I guess that the default light source in MAX could be a directional light. [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb172566(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb172566(v=vs.85).aspx[/url] Check here for the variables for the D3DLIGHT9 structure.

For a directional light, it's probably ok just to provide the Type, Diffuse, Specular, Ambient and Direction values.

Cheers!

Share this post


Link to post
Share on other sites
Medo Mex    891
Still couldn't adjust the light correctly in the scene to see specular highlights.

The airstrike is located at the position (X: 0.0f, Y: 0.0f, Z: 0.0f).

[CODE]
D3DLIGHT9 light;
ZeroMemory(&light, sizeof(light));
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse.r = 1.0f;
light.Diffuse.g = 1.0f;
light.Diffuse.b = 1.0f;

light.Ambient.r = 1.0f;
light.Ambient.g = 1.0f;
light.Ambient.b = 1.0f;

light.Specular.r = 1.0f;
light.Specular.g = 1.0f;
light.Specular.b = 1.0f;

light.Position.x = 0.0f;
light.Position.y = 100.0f;
light.Position.z = -100.0f;

light.Direction.x = 0.0f;
light.Direction.y = 0.0f;
light.Direction.z = 0.0f;
light.Range = 550.0f;
m_d3dDevice->SetLight(0, &light);
m_d3dDevice->LightEnable(0, TRUE);
m_d3dDevice->SetRenderState( D3DRS_LIGHTING, TRUE );
m_d3dDevice->SetRenderState( D3DRS_SPECULARENABLE, TRUE );
m_d3dDevice->SetRenderState( D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL );
m_d3dDevice->SetRenderState( D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL );
m_d3dDevice->SetRenderState( D3DRS_NORMALIZENORMALS, TRUE );

m_d3dDevice->SetMaterial(&material[i]);
[/CODE]

Share this post


Link to post
Share on other sites
kauna    2922
Directional light needs a direction. (0,0,0) doesn't point anywhere. The direction parameter is a normalized light direction. The position parameter doesn't have any effect when using a directional light.

Best regards! Edited by kauna

Share this post


Link to post
Share on other sites
Medo Mex    891
Okay, thanks! getting somewhere very close to do exactly what I want, one more important point, to make all the meshes have specular highlights in FPS game, should I create a directional light and update it's position according to the player position? maybe I should make the directional light position always over the player?

I also notice that when I don't set light.Specular it doesn't work, I have already set specular for the mesh material, do I have to set it for the light too? Edited by Medo3337

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this