Replace the positional light in Program 7.2 with a spot light, as described in Section 7.2. Experiment

Question:

Replace the positional light in Program 7.2 with a “spot” light, as described in Section 7.2. Experiment with the settings for cutoff angle and falloff exponent, and observe the effects.

Program 7.2Vertex Shader #version 430 layout (location=0) in vec3 vertPos; layout (location=1) in vec3 vertNormal; outFragment Shader #version 430 in vec3 varying Normal; in vec3 varyingLightDir; in vec3 varyingVertPos; outvoid main(void) { // normalize the light, normal, and view vectors: vec3 L = normalize(varying LightDir);

Section 7.2

There are many types of lights, each with different characteristics and requiring different steps to simulate their effects. Some types include:

•Global (usually called “global ambient” because it includes only an ambient component)

•Directional (or “distant”)

•Positional (or “point source”)

•Spotlight

Global ambient light is the simplest type of light to model. Global ambient light has no source position—the light is equal everywhere, at each pixel on every object in the scene, regardless of where the objects are. Global ambient lighting simulates the real-world phenomenon of light that has bounced around so many times that its source and direction are undeterminable. Global ambient light has only an ambient component, specified as an RGBA value; it has no diffuse or specular components. For example, global ambient light can be defined as follows:float[] globalAmbient = new float[] {0.6f, 0.6f, 0.6f, 1.0f};

RGBA values range from 0 to 1, so global ambient light is usually modeled as dim white light, where each of the RGB values is set to the same fractional value between 0 and 1, with the alpha set to 1.

Directional, or distant light also doesn’t have a source location, but it does have a direction. It is useful for situations where the source of the light is so far away that the light rays are effectively parallel, such as light coming from the sun. In many such situations we may only be interested in modeling the light, and not the object that produces the light. The effect of directional light on an object depends on the light’s angle of impact; objects are brighter on the side facing a directional light than on a tangential or opposite side. Modeling directional light requires specifying its direction (as a vector) and its ambient, diffuse, and specular characteristics (as RGBA values). A red directional light pointing down the negative Z axis might be specified as follows:float[] dirLightAmbient = new float[] { 0.1f, 0.0f, 0.0f, 1.0f}; float[] dirLightDiffuse = new float[] {

It might seem redundant to include an ambient contribution for a light when we already have global ambient light. The separation of the two, however, is intentional and noticeable when the light is “on” or “off.” When “on,” the total ambient contribution would be increased, as expected. In the above example, we have included only a small ambient contribution for the light. It is important to balance the two contributions, depending on the needs of your scene.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Computer Graphics Programming In OpenGL With JAVA

ISBN: 9781683922193

2nd Edition

Authors: V. Scott Gordon PhD, John L. Clevenger PhD

Question Posted: