Home page A B C D E F G H I K L M N O P Q R S T U V W X Y Z

Light Sources

Udocheals.orgLight source in computer graphics
12.20.2017 | Jennifer Bargeman
Light source in computer graphics
Light Sources

In computer graphics, the light sources that are usually available are: directional light, point light and spot light.

So precalculating the light direction in view-space might also save some computation time. In most cases, you probably will do the lighting calculations in view-space. Because the light is infiniy far away, the light direction vector is the same for all vertices. So it only has to be calculated once. That is why you might need to invert the light direction before sending it to the shader. The light vector has to be defined as going towards the light, because it needs to have the same general direction as the surface normal (which is pointing away from the surface).

where r is the direction the spot light shines, l is the vector pointing from the point on the surface towards the light source, and p is an exponent that controls how concentrated the spot light is. The other values are the same as in the point light formula.

This is what shadow computations are for. Note: Triangles do not obstruct the light beam, triangles that are behind other triangles still get brighter, even if no light beam should reach them.

For example, think of the light as a flashlight. So the light has a preferred direction of radiation. A spot light is similar to the point light, but the light is restricted to a cone. The formula to calculate the intensity of a spotlight at one point is:.

where d the distance between the light source and the point in space and k c, k l and k q are the constant, linear and quadratic attenuation constants.

One example of directional lights is the light of the sun. A directional light is a light that has a single direction and whose source is infiniy far away, so that the light rays can be considered parallel when they reach a surface. Directional lights have no position, only direction, and the intensity of the light does not diminish over distance.

One way of calculating the intensity of light reaching a vertex or a point on the surface is by using the following attenuation formula:. A point light source has a position and sends light rays in every direction. The intensity of the light decreases with distance.

Therefore the attenuation should be calculated in the fragment shader. The calculated intensity does not vary linearly with distance, so it would not look right when done per vertex and interpolated.

Light source in computer graphics