Skip to main content
GameDev.net gamedev.net
🔒 Locked

Lighting issue

Started by JGP Aug 7, 2002 at 5:05 PM 6 replies 500+ views
Original Post
JGP
JGP
I''m a newbie in Direct Graphics and I have a little troubble dealing with lights. I apply my transformations to my geometry and I render it with lighting enabled, but the light is also transformed with my geometry. The question is: how can I render with a STATIC (means not moving) light????
NotTaxes
NotTaxes
Is it possible that you''re setting up the light in the middle of your transform stage? What you should do is

1: Setup the view matrix

2: Transform the view
3: Render the models/geometry
4: Untransform the view

5: Place your lights

with steps 2-4 being done for as many models as you''re trying to render.

'Doing the impossible is kind of fun' - Walt Disney
don
don
Perhaps you can elaborate on what you mean by "the light is transformed with your geometry?"

Light positions are specified in world space. Your meshes normally are specified in model space. Lighting is calculated in camera space.

The world transformation matrix is used for positioning your geometry within the world.

The view matrix is for positioning the world in front of the camera.

If you are setting the world matrix to identity and then using the view matrix to position individual objects instead of the world matrix, then yes, the light position will be affected.

JGP
JGP
NotTaxes: if I render the objects before placing the lights... then the geometry will not be affected by the lights at all. Isn''t it?

Don: I mean, when I apply a rotation and a translation to my model, this transformations ar also applies to the light.

So I have to use the world matrix to:
- Set up the camera (lookat)
- Translate the model
- rotate the model

without using the view matrix at all to achieve the effect of a static light. I understood right?
Mark Duffill
Mark Duffill
I I understood you correctly, you are only using the world matrix to position your model into camera space?

If so this is where your problem might be,

Use the D3DTS_WORLD to postion you model from local->World space
use the D3DTS_VIEW to position you camera, this moves everything (geom that is) from world to view (camera) space.

So basically
0) Projection matrix setup, I guess you are doing this once on startup.

1) Get the lights that are affecting the model in world space.
2) Set/Enable these lights positions in world space
3) Set your world matrix
4) Set your view matrix
5) Draw your object.
6) goto 1 for next object

Point 1 is quite important if you have many lights ( more than the hw supports ), so you only enable lights in range of the object, and disable all others. You usually just do a bounding world sphere test to see what lights can affect the model. If there are *still* to many lights affecting the object, sort them into order of most influence and just use the first 4 or whatever.

Hope this is of some help.

Mark Duffill[The Jackal]
Eurocom Entertainment Software

[edit: damn my english Tut!]


[edited by - mark duffill on August 8, 2002 4:24:46 AM]
JGP
JGP
Thanx Mark, I understand. But I have a little question yet:

I need to set the orientation of every one of my models. In my engine every model has its rotation matrix, so this matrix reflects the individual rotation of the object.

Where is this done?
I understand for now:

Setting world matrix:
- Translate object
- Multiply my rotation matrix by the world matrix

Setting view matrix:
- Position my camera (lookat)

Question: how world matrix and view matrix are concatenated? (are they concatenated internally?) I say, what transforms will affect first in my scheme? positioning camera? or translating the object?

I am porting my engine from OpenGL to Direct3D and seems like every think is different

Mark Duffill
Mark Duffill
Well in Opengl you have a ModelView matrix where you have to concatinate the model->World, World->View matrices yourself.

Using DX you would usually do the following for a scene:

1) Calc your "lookat" matrix, using DXDevice->SetTransform( D3DTS_VIEW, &LokkAtMat ) will set your world->View matrix.

For each object in the scene

2a) Set your lights for the object.

2b) Using DXDevice->SetTransform( D3DTS_WORLD, &Obj2WorldMat ) will set your model->World matrix.

2c) Draw the object.



AFAIK internally DX just concatinates these matrices, along with the projection matrix so it has only one matrix to do the transforms.



Hope this helps.



Mark Duffill[The Jackal]
Eurocom Entertainment Software
JGP
JGP
Got it! This works fine.

I follow those steps and now it works. Although I had a problem and doing those steps didn''t work. The solution was using D3DXMatrixPerspectiveFovRH and D3DXMatrixLookAtRH instead of their equivalents for left-handed, because since I am porting an OpenGL engine, all the matrix operations were right-handed.

Thanx to you all guys!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.