Sign in to follow this  

Proper Direct3D Lighting?

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

I made a simple room in 3ds max, export it to x file and rendering in my app. Everything is fine except the light. In max, it looks quite cool. Even in Directx MeshViewer, its ok. I have tried with directional as well point lights at different locations but its not so good. Sometimes, a single wall or two get too brigh while others remaining dark and the edges dont look sharp as in the max. What is the proper way to use the DirectX lights? Like if u r rendering a small room how will u properly light it? How can i move the light with camera as in the MeshViewer application? Thanks for any help...

Share this post


Link to post
Share on other sites
3DS Max has all kinds of lighting parameters enabled by default. If you want the scene in your application to look exactly like it does in 3DS Max, then you'll need to export all the lighting information as well and use that in your scene.

I don't think MeshViewer uses just one light. In MeshViewer there is a light at the position of the camera, and there is probably also some added ambient lighting as well. There may be one or two other lights in the scene.

In general, make sure you're using Gauraud (spelling) shading. If you're mesh has textures on it, make sure that you enable mipmapping as well.

neneboricua

Share this post


Link to post
Share on other sites
The lighting equations in 3DSMax are an order of magnitude more complex (e.g. better!) than those provided by Direct3D [smile]. This is also one of the reasons why D3D can render your room 10's or 100's of times faster...

To get comparable lighting, you'll need to do a lot of work - almost certainly pixel shaders with a decent BRDF/lighting equation.

You can get decent lighting that might be acceptable for you. You need a high definition mesh - D3D lighting is performed per-vertex. You can probably do this in 3DSMax by subdividing your walls/geometry into a denser grid/surface of triangles. Next, you can look into the properties of the D3DMATERIAL9 structure - the specular parameters for example, so you can try and get a bit of a better appearance.

hth
Jack

Share this post


Link to post
Share on other sites
Thanks for the useful tips guys :)

Quote:
Original post by neneboricua19
3DS Max has all kinds of lighting parameters enabled by default. If you want the scene in your application to look exactly like it does in 3DS Max, then you'll need to export all the lighting information as well and use that in your scene.

I m using the x file exporter provided by Microsoft. Does it provide support to export all the lighting information from max? If yes, how will i use that information in my scene?

Share this post


Link to post
Share on other sites
I believe the mesh file x format doesn't support lights or camera information. You'll have to manually add lights to the scene and play around with the parameters to get things just about right.

Share this post


Link to post
Share on other sites
Quote:
Original post by masd
I m using the x file exporter provided by Microsoft. Does it provide support to export all the lighting information from max? If yes, how will i use that information in my scene?

The .X exporter has, in all cases I've used it, always exported the selected geometry elements or all geometry in a scene. It doesn't include the other "cool" parts of a max scene such as lights, dummys, paths etc...

You could, if you really need it, look into writing your own export plug-in for 3DSMax that included the light entities in your output file. But, off the top of my head, there isn't an automatic/pre-existing tool for this included in the SDK or Max.

hth
Jack

Share this post


Link to post
Share on other sites
Ok, so that means one has to do all the lighting stuff manually while rendering the 3d models.

Now, one more thing, i have placed a simple directional light in the room, placed the camera in the center and rotating it continuously. I want to move/rotate the light with the camera so as it always lit the facing side of the scene. Like in DirectX MeshViewer, it looks like light moves as u rotate the model around. Any idea about it?

Share this post


Link to post
Share on other sites
Quote:
Original post by masd
i have placed a simple directional light in the room, placed the camera in the center and rotating it continuously. I want to move/rotate the light with the camera so as it always lit the facing side of the scene. Like in DirectX MeshViewer, it looks like light moves as u rotate the model around. Any idea about it?

This is simply a case of mathematics, you need to reconfigure your D3DLIGHT9 struct and SetLight(...) each time you move the camera. As a general rule of theumb with Direct3D, it won't change anything automatically - that light will stay exactly how you configured it until you next change the appropriate states/properties.

I would say the simplest option is to use your pEye and pAt vectors you feed into D3DXLookAtLH( ) to generate a direction vector. Normalize this using D3DXVec3Normalize( ) and set it as the direction for your D3DLIGHT9 struct. This way it should follow where your camera is pointing.

hth
Jack

Share this post


Link to post
Share on other sites

This topic is 4663 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.

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