• Create Account

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

36 replies to this topic

#21Medo3337  Members

891
Like
0Likes
Like

Posted 12 December 2012 - 08:05 AM

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!

#22kauna  Members

2918
Like
1Likes
Like

Posted 12 December 2012 - 08:18 AM

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. http://msdn.microsoft.com/en-us/library/windows/desktop/bb172566(v=vs.85).aspx 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!

#23Medo3337  Members

891
Like
0Likes
Like

Posted 12 December 2012 - 09:09 AM

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).

	 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]);


#24kauna  Members

2918
Like
1Likes
Like

Posted 12 December 2012 - 09:12 AM

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, 12 December 2012 - 09:12 AM.

#25Medo3337  Members

891
Like
0Likes
Like

Posted 12 December 2012 - 09:35 AM

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, 12 December 2012 - 09:49 AM.

#26kauna  Members

2918
Like
1Likes
Like

Posted 12 December 2012 - 10:00 AM

In the D3D9 lighting equation, the materials specular value is multiplied with the lights specular value so if either of them is black, you don't get any specular effect.

The lighting is up to you to decide. Typically, a directional light is used to give lighting effect of a distant light source such as sun or moon.

Since it is a directional light, the position doesn't have any effect on the lighting. So practically you don't need to touch the lights position when the player is moving.

Otherwise, a directional light source isn't the best way to light indoor environments, it works the best at outdoors.

Best regards!

#27Medo3337  Members

891
Like
0Likes
Like

Posted 12 December 2012 - 12:14 PM

Very good info! I thought that the sun light is a point light.

I'm trying to make each mesh specular level same as in 3Ds Max, so I tried putting some values, but couldn't get it to work, I have the mesh specular level set to 20 in 3Ds Max, I thought I could give light.Specular (1.0f, 1.0f, 1.0f) so when it get multiplied the result become the same as the specular level in the mesh.

As you can see in the screenshot, the specular level is too high even I'm setting it's value in 3Ds Max to 20 only.

I would appreciate if you could tell me how can I change this code to get a result at least close to the value that I put in 3Ds Max to the specular level.

D3DLIGHT9 light;
ZeroMemory(&amp;light, sizeof(light));
light.Type = D3DLIGHT_DIRECTIONAL;
light.Diffuse.r  = 0.1f;
light.Diffuse.g  = 0.1f;
light.Diffuse.b  = 0.1f;

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

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

// Set the direction that this light will generate light from
D3DXVECTOR3 vDir( 100.0f, -100.0f, 100.0f );

// Normalize the light direction
D3DXVec3Normalize ((D3DXVECTOR3*) &amp;light.Direction, &amp;vDir);


Attached Thumbnails

Edited by Medo3337, 12 December 2012 - 12:14 PM.

#28kauna  Members

2918
Like
0Likes
Like

Posted 12 December 2012 - 01:19 PM

Can you provide a screenshot of 3DS MAX to give some reference about the image?

There is a possibility that 3DS MAX is using per-pixel lighting for the preview screen which gives more accurate specular high lights.

I think that you should also increase the lights diffuse value. Typically most of lighting comes from the diffuse part of the lighting equation.

Yes, sun could be modeled with point light, but then it's relative position to the scene needs to be quite far (which is true in the real world too).
As the point light source gets further and further away, the light direction starts to get uniform. For that reason, a directional light is used often to model sun light. It could be considered as optimization, since directional lights can skip attenuation calculations and the light direction vector is same for all position on screen. The attenuation difference between the closest and the farthest point of earth to the sun is quite small.

A point light needs to calculate the light direction vector and attenuation for each fragment / vertex.

Best regards!

#29Medo3337  Members

891
Like
0Likes
Like

Posted 12 December 2012 - 01:33 PM

Here is the same mesh rendered in 3Ds Max with the same specular level (20).

#30kauna  Members

2918
Like
0Likes
Like

Posted 12 December 2012 - 02:00 PM

Your light source definetely lacks diffuse lighting component. Otherwise, you'll need to get exactly the same point of view to compare the specular component, since it is view point relative.

To achieve the quality of a rendered 3DS MAX image may not be possible with D3D9 fixed function pipeline.

Best regards!

#31Alin  Members

411
Like
0Likes
Like

Posted 12 December 2012 - 02:45 PM

I have update my exporter today because I found glossiness in 3ds max is the power, not the specular level... so if you want to ajust power, please redownload the plugin.
Now the power/glossiness you get is beteen 0 to 100, just what you see in 3ds max.

#32Medo3337  Members

891
Like
0Likes
Like

Posted 12 December 2012 - 03:35 PM

@Alin: I don't see the update, I downloaded v1.8.2 few days ago and on the website I still see the same version http://www.cgdev.net/download.php

- I would suggest you to make "Add animation" open a new window to add animation instead of editing from the animation list, when I double click on the animation item to edit it, it's not showing edit mode easily.

- When you change the settings in the export window, it doesn't save which waste alot of time later when you try to export again since you have to add the same settings again including animations, etc...

- A progress bar while writing the .x file would be great.

- Hitting 'Enter' button to start exporting would be better.

Edited by Medo3337, 12 December 2012 - 04:04 PM.

#33Alin  Members

411
Like
0Likes
Like

Posted 12 December 2012 - 10:29 PM

I dont change the version v1.8.2 to v1.8.3 because this version simply change back to export glossiness as specular power... so your download 3 days ago is a special build for you. The next version I will add support for saving the settings of animations.

#34Medo3337  Members

891
Like
0Likes
Like

Posted 13 December 2012 - 05:22 AM

@Alin: It looks like there is a bug with your exporter, I tried Panda Exporter and it's working perfectly with the specular effect, but had troubles with your exporter, when I set the specular level to 10 (As you see in the attached screenshot) I see a very high specular level when I use your exporter while when I use Panda exporter it's working perfectly.

Also, when I don't use specular in 3Ds Max and export the mesh with your exporter, I still see specular effect in the program even I didn't set it in Max, while when I use Panda Exporter it's not showing specular effect which is the accurate result.

The attached pictures show the same mesh with the same specular level and same everything, the only difference is the exporter.

#35Alin  Members

411
Like
0Likes
Like

Posted 14 December 2012 - 03:43 AM

Thanks for your feedback, I have just released v1.8.3 for this bug. The new version also support saving settings of animation list.

#36Medo3337  Members

891
Like
0Likes
Like

Posted 14 December 2012 - 08:10 AM

One thing you might need to correct: Hitting 'Enter' on the keyboard doesn't start exporting.

I also would like to thank kauna for helping me to resolve this issue.

#37GeniusPooh  Members

161
Like
0Likes
Like

Posted 18 December 2012 - 12:59 AM

Wow

what a long repies...

Max's spec level is just a float 100% is 1 ..

You must multiply it to specular value..

I tested it with my own software renderer 15years ago ^^

I can't help about X file's structure but I hope my knowledge help to writing shader

happy days

Edited by GeniusPooh, 18 December 2012 - 01:04 AM.

Beauty is only skin deep , ugly goes to bones

World's only 3D engine tunner and 3D engine guru.

and real genius inventor but very kind warm heart .. and having serious depression for suffering in Korea

www.polygonart.co.kr ( currently out dated and only Korean will change to English and new stuff when I get better condition sorry for that)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.