• Create Account

#ActualAshaman73

Posted 16 July 2012 - 11:05 PM

I realize the final coordinate, the w-coordinate, should be 0.

This is the case, because you don't want to affect the vector by a translation, when multiplying with a transformation matrix. The transformation should only rotate the vector.

First define your two points.

upper-west

(1,0,1)
Then you should define a source point, I think you want to have (0,0,0), right ?

The direction is (target-source):
(1,0,1) - (0,0,0) = (1,0,1)

After that you need to normalize it, directions are often needed in unit length:
(1,0,1) * (1/length(1,0,1))

Also, are there any gotcha's with lighting when it comes to directional lighting? I saw something about having to apply the light's position AFTER pushing in all of your geometry, otherwise it doesn't translate/move correctly.

When you transform a vertex or vector you move it from one space (i.e. world space) into an other space (i.e. camera space aka eye view). Lighting is often done in camera space, therefore you need to transform all vectors/vertices into the same space. When transforming a model this is done automatically by the transformation matrix, when you set a direction vector for lightning you need to transform it before uploading it to the GPU, that is transform * (lx,ly,lz,0) .

Edit: correction due to the comment of dpadam450.

#2Ashaman73

Posted 16 July 2012 - 09:40 PM

I realize the final coordinate, the w-coordinate, should be 0.

This is the case, because you don't want to affect the vector by a translation, when multiplying with a transformation matrix. The transformation should only rotate the vector.

First define your two points.

upper-west

(1,0,1)
Then you should define a target point, I think you want to have (0,0,0), right ?

The direction is (target-source):
(0,0,0) - (1,0,1) = (-1,0,-1)

After that you need to normalize it, directions are often needed in unit length:
(-1,0,-1) * (1/length(-1,0,-1))

Also, are there any gotcha's with lighting when it comes to directional lighting? I saw something about having to apply the light's position AFTER pushing in all of your geometry, otherwise it doesn't translate/move correctly.

When you transform a vertex or vector you move it from one space (i.e. world space) into an other space (i.e. camera space aka eye view). Lighting is often done in camera space, therefore you need to transform all vectors/vertices into the same space. When transforming a model this is done automatically by the transformation matrix, when you set a direction vector for lightning you need to transform it before uploading it to the GPU, that is transform * (lx,ly,lz,0) .

#1Ashaman73

Posted 16 July 2012 - 09:39 PM

I realize the final coordinate, the w-coordinate, should be 0.

This is the case, because you don't want to affect the vector by a translation, when multiplying with a transformation matrix. The transformation should only rotate the vector.

First define your two points.

upper-west

(1,0,1)
Then you should define a target point, I think you want to have (0,0,0), right ?

The direction is (target-source):
(0,0,0) - (1,0,1) = (-1,0,-1)

After that you need to normalize it, direction are often needed in unit length.

Also, are there any gotcha's with lighting when it comes to directional lighting? I saw something about having to apply the light's position AFTER pushing in all of your geometry, otherwise it doesn't translate/move correctly.

When you transform a vertex or vector you move it from one space (i.e. world space) into an other space (i.e. camera space aka eye view). Lighting is often done in camera space, therefore you need to transform all vectors/vertices into the same space. When transforming a model this is done automatically by the transformation matrix, when you set a direction vector for lightning you need to transform it before uploading it to the GPU, that is transform * (lx,ly,lz,0) .

PARTNERS