View Full Version : Eye Coordinates?

Why are things like lighting normally done in eye coordinates? In my engine, I make sure to seperate the modelview matrix into a viewing matrix and a modelling matrix, and I do all my lighting calculations are done in world space, that is by applying only the modelling matrix.

plasmonster

05-25-2004, 06:53 PM

This is a good question. It really depends on

the space that's convenient for you. The

important thing is to be very consistent in

whatever space you choose.

For example, say you want to do your lighting in

eye space. A typical calculation in any light

model is the diffuse dot product

T

LdotN = (Le - Ve) Ne

where Le is the light position, Ve is the vertex

position, and Ne is the vertex normal, all in

eye space. I've left out the normalization of

Le - Ve for simplicity.

It is helpful to look at the transforms that put

these vectors in eye space to begin with, then

it will become clear why this works.

To transform any vertex into eye space, we

multiply it by the MV (Model and View matrix).

To transform a normal, we multiply it by the

inverse transpose of the same matrix. So our

equation above would expand to

T T -1T

LdotN = (Le - Ve) Ne = (CLw - CMVo) (CM) No

where C is the view matrix (camera C to avoid

confusion with vertex V), M is the model matrix,

Lw is the light position in world space, Vo is

the vertex position in object space, and No is

the vertex normal in object space.

Now, it really helps to know something about

matrices at this point.

T

LdotN = (Le - Ve) Ne eye space

T -1T

= (CLw - CMVo) (CM) No with transforms

T -1T T -1T

= (CLw)((CM) No) - (CMVo)((CM) No) transpose over sum

T T -1T -1T T T T -1T -1T

= Lw C C M No - Vo M C C M No reverse order law

T -1T T

= Lw M No - Vo No simplify

-1 T

= (M Lw - Vo) No simplify

(It's interesting to repeat this with everything

in world space, you'll end up with the same

result.)

This means that evaluating this equation

is eye space is equivalent to moving the light

into object space and evaluating it there. This

is intuitive really, you can move the object

into world space with the light, or move the

light into object space with the model, it's

arbitrary. The important thing is to keep

everything in the same space, or be very

careful when mixing spaces.

Hope this helps.edit:

made a correction in a simplification

Yeah, I like keeping everything in "world space", that is where (0, 0, 0) is the center of the "universe," as opposed to "object space" where (0, 0, 0) is the "center of mass" or "eye space" where (0, 0, 0) is the center of the screen...

I'm well aware of the importance of keeping things consistent, though. If it works... why argue, right?

plasmonster

05-25-2004, 07:59 PM

Right. I like world space too ... it just smells better. :)

Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.