|[ LiB ]|
The scene is always rendered after all light has been propagated and is being reflected onto each surface. Shading is the most important element to a rendering algorithm such as ray tracing. Shading refers to the concept of light being reflected off an arbitrary surface at some particular time. In other words, shading can be called the reflected
(the energy leaving a surface). Recall from Chapter 2 that when light is incident on a material, some of the energy is absorbed into the material and some is transmitted through the object to another object or reflected off the surface to another object. If a material absorbs all colors and reflects green, the material appears green. Because you're using backward ray tracing, which is the incorrect way of simulating light, the algorithm records the
In the real world,
Backward ray tracing utilizes a mathematical model that approximates how much light
The diffuse shading method is very efficient when used with ray tracing.
Recall from Chapter 6 that the
calculates the angle between two vectors in space. This is perfect for what you need here in order to
The point normal is the surface normal if the surface is flat. This value can be easily computed because the dot product is a unit length vector method. The range of the dot product method is given as 1 to 1. If the angle is 0 between the light source and the point normal, the returned value is 1.0. If the angle between the light source and the point normal is 90 degrees (or
The values that are below 0 to 1 indicate that the surface is facing away from the light source, which means that the surface isn't receiving any energy from the light source. The values that are above 0, yet less than 1,
This is perfect for what you need because 0 to 1 or simplified 0 to 100% can represent an illumination range of brightness. By adding the object color into the equation you can shade the desired point of intersection on the object according to the intensity factor. The object color and cosine shade are not the only two coefficients needed to do diffuse shading. Materials have an internal diffuse factor of how much light it reflects across the surface. This is mostly the color of the object. You must add this coefficient too into the solution when using the cosine shading method.
Because ray tracing has indirect illumination problems (as seen in calculating the
The ambient factor isn't used in
photon mapping because photon
mapping is great at simulating shad-
Let's take a look at the steps required to shade an arbitrary point in 3D space. You first find the angle between the point-normal relative to the light source. This is done using the dot product method. If the angle of the cosine shading method is less than zero, no light is incident on the point of intersection and the point should be shaded as black (no lighting). But if the angle is above zero, you should begin shading the point using the different coefficients of the material as well as the ambient factor. After you've incorporated these different elements into one solution for the specific point of interest, you find the final solution.
Here is the process for shading a point for diffuse shading:
Shade = Find the Angle Between (Light Vector, Point Normal) If (Shade < 0 ) 1. Shade = 0 Diffuse = Surface.Color Diffuse = Diffuse x Surface.AmbientFactor Diffuse = Diffuse x Surface.DiffuseFactor Diffuse = Diffuse x Shade
As you can see, it's pretty simple. The object's color,the surface ambient factor, the diffuse factor,and the shadeare all incorporated into the final solution.
Objects such as apples, pool balls, bowling balls, and so on are smooth, thus
A mirror is a perfect specular reflection and will reflect whatever it's facing because it has few imperfections. But most smooth objects have a higher degree of imperfections. This causes the reflected light to be bounced in a somewhat imperfect fashion. If the eye is in front of the light source, the light that's reflected back into the eye directly off the smooth surface generates a bright shiny spot on the surface. This bright shiny spot on the surface is called the
and the imperfection the surface has is a coefficient called
The location of the highlight is relative to the observer. This viewing vector was originally read in as the Viewing Direction in the cScene class. The viewing direction vector is used to simulate the brightness of the light focused on the surface. The shininess of the highlight is an exponent. A large exponent will create a small sharply focused highlight and a small exponent will generate a larger highlight. This value is calculated as the angle between the reflection of the light relative to the ray and to the light source direction. The specular highlight coefficient indicates how shiny the object is; you must add this to simulate specular highlights.
Simulating specular highlights is rather simple as compared to diffuse interaction. You need only to find the angle between the reflected ray direction and the ray to light direction. If the angle between these two vectors is above zero, the specular highlight is applied to the pixel. The highlight is the Shininess of the object times the Shade to the power of the Specular Exponent . Here is the process for shading a point for specular highlights:
Shade = Find the Angle Between (Reflected Ray Direction, Ray to Light Direction) If (Shade > 0 ) Specular = pow (Shade, Surface.Shininess)* Surface.fSpecularExponent Else Specular = 0
You must now apply the specular and diffuse factors to the final pixel intensity. Finding the final pixel shade of a point on a surface for the view plane is the primary goal. Figure 9.5 shows the two
Diffuse interaction and specular highlights are collectively referred to as local illumination lighting effects .
The process of
The final color is set to black (no lighting).
The light source's color is summed into the final color.
The light source's wattage is summed into the final color.
The combination of the specular and diffuse shading is summed into the final color.
The final color is set to the pixel on the image plane.
To find the final pixel intensity, use this formula:
Returned Color = Lightsource.Color * Lightsource.Wattage * (Specular + Diffuse)
You can now upgrade the cScene class to accommodate the new changes required for ray tracing.
|[ LiB ]|