why the last element of light position means

As I starting OpenGL, I found an interesting question that is , in OpenGL, when setting GL_POSITION propertity of a glLight, use 0.0f as the last element means the light is a directional light, and the direction of the light is the propertity value, and use 1.0f means the light is a point light, with the position being the propertity value.

It’s strange. When I modify the last element of light position propertity from 1.0f down to 0.0f, from the shadow of the light , it seems the light is moving from the specified position to infinite far. Perhaps it’s the effect of projection. I conducted the ShadowMatrix by myself, but when I tried to conduct how the light effect is computed, I failed. I don’t know how to get an uniform formula independent of the light.

So, I need some help on how light is computed in OpenGL. If anyone want my conduction of ShadowMatrix, email me, I will send you the doc file. It is very amazing that the computation of shadow matrix is independent of the last element of the light position.

Every position in OpenGL has four coordinates (x, y, z, w). It’s called homogenous coordinates.

Basically, you have to divide the other three coordinates by the fourth to get normal 3D coordinates. This makes it possible to represent translation and projection by a matrix, with normal coordinates these operations would be non-linear.

This is also consistent with the behavior of the light position. If you take a point light, and let the w coordinate of the position approach 0, the position is approaching infinity, so you get a directional light.