When the angle between both vectors is 90 degrees, the dot product becomes 0. You may remember from the transformations chapter that, the lower the angle between two unit vectors, the more the dot product is inclined towards a value of 1. The angle between the two vectors can then easily be calculated with the dot product. To measure the angle between the light ray and the fragment we use something called a normal vector, that is a vector perpendicular to the fragment's surface (here depicted as a yellow arrow) we'll get to that later. If the light ray is perpendicular to the object's surface the light has the greatest impact. We need to measure at what angle the light ray touches the fragment. To the left we find a light source with a light ray targeted at a single fragment of our object. To give you a better understanding of diffuse lighting take a look at the following image: Diffuse lighting gives the object more brightness the closer its fragments are aligned to the light rays from a light source. It should look something like this:Īmbient lighting by itself doesn't produce the most interesting results, but diffuse lighting however will start to give a significant visual impact on the object. The object is quite dark, but not completely since ambient lighting is applied (note that the light cube is unaffected because we use a different shader). If you'd now run the program, you'll notice that the first stage of lighting is now successfully applied to the object. Vec3 ambient = ambientStrength * lightColor We take the light's color, multiply it with a small constant ambient factor, multiply this with the object's color, and use that as the fragment's color in the cube object's shader: As you've seen in the previous section we use a small constant (light) color that we add to the final resulting color of the object's fragments, thus making it look like there is always some scattered light even when there's not a direct light source.Īdding ambient lighting to the scene is really easy. Since we're not big fans of complicated and expensive algorithms we'll start by using a very simplistic model of global illumination, namely ambient lighting. Algorithms that take this into consideration are called global illumination algorithms, but these are complicated and expensive to calculate. One of the properties of light is that it can scatter and bounce in many directions, reaching spots that aren't directly visible light can thus reflect on other surfaces and have an indirect impact on the lighting of an object. Light usually does not come from a single light source, but from many light sources scattered all around us, even when they're not immediately visible. We'll start with the simplest one: ambient lighting. To create visually interesting scenes we want to at least simulate these 3 lighting components. Specular highlights are more inclined to the color of the light than the color of the object. Specular lighting: simulates the bright spot of a light that appears on shiny objects.The more a part of an object faces the light source, the brighter it becomes. This is the most visually significant component of the lighting model.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |