facebook_02twitter_02RSS_02

CG Lighting 101

render_heading

What is Light?

Light that's visible to the human eye is energy in the form of an electromagnetic wave. The range of colors we see is but a small part of a much larger range of wavelengths in what is called the electromagnetic spectrum. The color of light, and position in the spectrum depends on the length/frequency, of these waves. On the one extreme we have radio waves which are long in length, low in frequency and energy, and on the other, we have gamma rays which are short in length, very high in frequency and energy. In between infrared and ultraviolet waves, we have the visible part of the spectrum starting with red, with a relatively low frequency, green in the middle, and ending with violet with a higher frequency. Seen all at once, the visible spectrum appears as white (also called broad-spectrum) light. In computer graphics we use a simplified light model called RGB, using only three specific colors of light, Red, Green, and Blue. The three colors (or channels) are then combined to achieve other spectrum colors.



Figure 1.1. The Electromagnetic Spectrum


While light has all the properties being a waveform, it also satisfies the requirements of being particles of energy, traveling in straight lines at the speed of light. These particles are called photons. This duality of light is a tease of nature, beyond any understanding of any physicist even today. For our immediate purposes, it's probably easiest to think of light in terms of 'rays' traveling in straight lines, rather than photons, or waves of different shapes and sizes.

When light hits a surface, three things can occur: Absorption, Reflection, or Transmission.


Absorption of Light

On a molecular level, all surfaces have what is called a skin-depth, where light actually penetrates into the surface material. Just under this 'skin', light-rays that share the same color as the surface's pigment are reflected. The remaining light is absorbed and transformed into lower grades of energy, primarily infrared or heat energy. A good example of this energy transfer would be the extra heat one would experience when wearing a black shirt on a hot, sunny day; Black is the total absence of reflected light, therefore any light hitting the surface is absorbed and converted to heat energy.

In general, Darker surfaces will absorb more light, while brighter surfaces will reflect more light. Colored materials will reflect light of the perceived surface color, and absorb the other colors (spectrums) of light. Simply put, a red surface will reflect red light, and absorb light of any other color. Absorbed light is invisible. If one were to shine a pure-green light at a pure-red object, with no other contributing lights, the red object would appear black. because the green light is totally absorbed.

In Figure 1.2 an incident ray of white light is directed at a blue sphere. To generalize, RGB color space is used rather than full-spectral color space. There is a pigment throughout the sphere which reflects only blue-spectrum light. The blue-spectrum light-rays penetrating into the skin depth of the sphere is scattered and reflected, while the remaining spectrums of light are trapped and absorbed as heat. Since the pigment only reflects the blue-spectrum oflight, the surface appears blue.



Figure 1.2. A perfect blue surface lit by a white light will reflect all the blue light, and absorb all the green and red light.


Reflection of Light

Diffuse, Specular, Glossy, Reflectivity, they all fall into this category, not just the mirror-like reflection usually associated with 3D graphics. How much, and in what way light is reflected from a surface depends on several things; The electrical properties of the material, pigment, and refractive index, to name a few. For now we'll concentrate on the optical roughness of a surface surface, as it's the most obvious.



Figure 1.3. Five spheres show the effect of surface roughness on reflection.
The more rough a surface is, the more diffuse the reflection. Conversely, the smoother a surface is, the more specular the reflection


To aid in distinguishing different types of reflection, consider for a moment a surface as being made up of millions of tiny mirrors.

 
Diffuse Reflection

If all the mirrors are facing in completely random directions, they will collectively appear as a very rough surface, reflecting light equally in all directions. This is called uniform diffuse reflection, characteristic of matte surfaces such as paper, brick, and unfinished woods. of reflection, consider for a moment a surface as being made up of millions of tiny mirrors.

Figure 1.4. Diffuse Reflection - A very roughness surface reflect light-rays in all directions uniformly.


It makes sense in CG, to combine the diffuse reflection with the absorption of a material in to what we call the 'color' attribute. A standard Lambert shader in Maya for example, has attributes for both color and diffuse for added control. While the diffuse attribute can be handy, it is merely a multiplier for the color attribute. That is, a diffuse value of 1.0 will render the color attribute as is, a value of 0.80 will render the color attribute at 80% of it's original RGB value, and a value of 0.0 will make the color attribute black, period.


Figure 1.5. Shaders usually combine absorption and diffuse reflection into the 'Color' attribute. The color attribute is in turn multiplied by the shader's 'Diffuse' attribute
Specular Reflection

If all the mirrors are oriented facing the same direction, they will collectively appear as a smooth surface, reflecting light-rays in a unified direction. This is called regular or specular reflection, the perfect mirror-like reflection that we're all used to in computer graphics.
The law of reflection states that the angle of the incoming light-ray to the surface-normal equals the angle of the reflected light-ray. The surface-normal is defined as hypothetical line perpendicular to the surface.


Figure 1.6. Specular Reflection (also called regular reflection) - occurs when the surface imperfections are smaller than the wavelength of light.


Another major difference between diffuse and specular reflection, is that specular reflection is view-dependent, while diffuse reflection is view independent. This means that for specular reflections, as the position of the camera moves relative to the surface (and visa versa), the reflected image (a specular highlight for example) will move also. Diffuse reflection, because it's scattering light in all possible directions, it looks like it remains constant at any viewing angle.


Figure 1.7. Three different views of a shiny sphere, rendered under exactly the same lighting conditions.
The Specular highlight changes it's position on the sphere's surface for each view.

 

View dependence becomes important when 'baking' any illumination into textures or geometry. It can be very economical to bake diffuse lighting, including shadows and Ray-traced lighting solutions, into textures. This can be done because the surface illumination looks the same from all views. Global Illumination, Caustics, and Final Gathering are usually very expensive to calculate for every fame of animation. However, if they are baked into the texture (which is a one time process), the ray-traced lighting can be turned off, making renders much faster. As long as any geometry contributing to the lighting solution is not moving in the scene, baking any form of diffuse lighting into textures (or vertex colors etc.) should work.

Baking Specular light into textures is another story entirely. Because it has so many restrictions, it's generally a lost cause. As we said earlier, unlike uniform diffuse reflection, specular reflection is view-dependent. If the camera, the light source, or the illuminated object move in anyway, the specular highlight/reflection will be expected exhibit some sort of change also. If the specular highlight/reflection doesn't change, the viewer sense that something's 'not quite right' with the scene.

 

Glossy Reflection

Any reflection between a completely diffuse reflection, and a perfect specular reflection can be considered a glossy reflection. Think of those millions of mirrors facing in the same general direction. You can recognize the reflection, buts it's broken up, and spread out to a degree.


Figure 1.8. Glossy Reflection - is any reflection in between diffuse and specular reflection.


Figure 1.9. The concept of glossy reflections illustrated by a light bulb reflected in a surface made of of thousands mirrors.
The mirror directions are randomized, the more they deviate from a uniform direction, the more 'blurred' the reflected image.


Glossy reflections are much more expensive to calculate than Diffuse, and Specular reflections. The introduction of a non-uniform surface greatly complicates the mathematics of the shading model.


Transmission of Light

A material that exhibits transparent or translucent qualities will have light is pass into and/or through it. The transmitted light-rays continue to travel until their energy is depleted or absorbed.



Figure 1.10. Transmission - If a light-ray is transmitted it is passed into and/or through a material
 
Transparency

In the case of a transparent material, light-rays pass completely through the material with very little reflection and/or absorption taking place. A flat sheet of common glass when viewed face on, will reflect 8% of incoming light (4% x 2-sides) and transmit the remaining 92%.



Figure 1.11. Transparency - A light-ray will pass through a transparent material, without being reflected or absorbed.


To aid in distinguishing different types of reflection, consider for a moment a surface as being made up of millions of tiny mirrors.

 
Translucency

Figure 1.12. Translucency - A translucent material allows a ray of light to pass into it while it's energy is absorbed. If the object is thin the light ray can pass through to the other side of the object

Light that passes into a translucent material gradually loses it's energy though absorption by the pigment. If the object is thin enough, the unabsorbed light can travel through the object and continue on.

Leaves are generally very translucent. Under low lighting conditions, such as an overcast day, leaves and other plants appear a somewhat dark green. On a clear sunny day they are a bright, sometimes radiant, green color. This happens because:

a) light penetrates into the leaves, saturating them with illumination.

b) leaves are thin enough that light passes through them. In fact, because more light passes through the leaves, than is reflected, they can actually appear brighter on the opposite side to the incoming illumination.


Refraction

When a ray of light passes from a less-dense material (called a fast-medium) to a higher density material (called slow-medium), it slows down. This causes the rays to bend towards the normal of the two materials. The degree to which the ray bends depends on the refractive indecies of the who materials. Materials with higher indecies of refraction bend light more than materials with lower indecies of refraction.


Figure 1.13. Refraction - When a ray of light passes from a less-dense material (called a fast-medium) to a higher density material (called slow-medium), it slows down, causing the rays to bend towards the normal of the surface.

The index of refraction is defined as the speed of light in vacuum divided by the speed of light in the medium. Thus the Ior for a vacuum is 1.0. The Ior for air is 1.000277, close enough to a vacuum for most situations which makes calculations a bit more friendly.

Refraction doesn't apply only to transparent surfaces. Most materials refract at least some light, which can significantly vary the reflectivity of a surface for different angles. We'll look at how and why in section 1.3 Fresnel Reflection.

Since we know that light will be either be absorbed, reflected, transmitted, or a combination of these, we can conclude that:

Absorption + Reflection + Transmission = 100% of incident light energy

Applied to a simple shader, Diffuse, Specular, and Transparency/Translucency values should add up to less than 1.0 in order to be physically plausible.

For example, if an opaque Blinn shader has a Diffuse value of 0.80, the Specular value should be equal to or less than 0.20 (The appearance of the specular highlight should also be adjusted to reinforce this, but we'll get the that).

Remember, this equation, (Diffuse + Specular - Transparency = Total Reflected Light), is merely a guide for creating realistic shaders, and not intended as a restriction. The final look of the surface is paramount. The goal here is to have all your surfaces react predictably in any lighting environment. If several surfaces in the same scene have significant discrepancies in the total amounts of light they are reflecting / transmitting, it's not uncommon for certain objects to look 'out of place'. Some objects may appear too dark, and others may 'burn' under the same lighting conditions.

View dependence becomes important when 'baking' any illumination into textures or geometry. It can be very economical to bake diffuse lighting, including shadows and Ray-traced lighting solutions, into textures. This can be done because the surface illumination looks the same from all views. Global Illumination, Caustics, and Final Gathering are usually very expensive to calculate for every fame of animation. However, if they are baked into the texture (which is a one time process), the ray-traced lighting can be turned off, making renders much faster. As long as any geometry contributing to the lighting solution is not moving in the scene, baking any form of diffuse lighting into textures (or vertex colors etc.) should work.

Baking Specular light into textures is another story entirely. Because it has so many restrictions, it's generally a lost cause. As we said earlier, unlike uniform diffuse reflection, specular reflection is view-dependent. If the camera, the light source, or the illuminated object move in anyway, the specular highlight/reflection will be expected exhibit some sort of change also. If the specular highlight/reflection doesn't change, the viewer sense that something's 'not quite right' with the scene.

 

Specular Highlights and Reflection
 


A common misconception among CG artists, is that specular-highlights and reflections are mutually exclusive, when in fact, they are the same thing in the real world. A specular highlight in CG is merely a simulated reflection of a primary light source.
Why then are specular highlights and reflections separated in almost all shaders? The reasons are many, the most poignant being control and render cost.

Specular highlights are calculated very quickly. More importantly, attenuated, or blurred specular highlights are calculated very quickly, able to simulate reflection of a light source over a rough surfaces without using expensive ray tracing algorithms. This is because no 'real' reflections are taking place which require ray-tracing. Instead, a faked highlight is built into the shader that draws a highlight according to a light source's position, color, and intensity.


Highlights and Surface Roughness

A typical light source in 3D, is an infinitesimally small point casting rays in one direction (directional light), several directions (spot light), or every direction (point light). A light source this size couldn't possibly show up in a reflection; thus, the specular highlight is introduced to generate a tangible reflection of the light source. In a typical shading model, adjustments to attributes associated with the surface's roughness on a microscopic level control the look of the highlight. Increasing the simulated roughness of the surface diffuses the highlight, making it larger and softer.
blinn_eccentricity

Figure 2.1. The eccentricity attribute of a Blinn Shader controls both the size and softness of the specular highlight.
 


These improvised highlights are sufficient for most cases, but they'll never provide the richness of a highlight from a physical light source. Windows, lamps, even televisions have specific profiles that can't be satisfied by a standard shader highlight. Excluding the Sun, there aren't many conventional light sources which are of uniform color, intensity, and in a disk shape fixed to the surface normal.
Some 3D applications give you the option of a square specular highlight which is fast to calculate, and more appropriate for light sources such as windows.

For a non-mirror-like surface to receive a true specular highlight through reflections alone, two things are needed:

1. A 3D light source - a 3D representation of the light source is required to illuminate and reflect it physical shape accurately (because, as we discussed earlier, standard lights in 3D are infinitely small).

2. Glossy (blurred) reflections - Without glossy reflections, the light will appear as a specular image despite the roughness of the surface.


highlight_shape

Figure 2.2 A lantern will create an irregular shaped, physically correct specular highlight
 


Until recently, blurred reflections have been largely unavailable in 3D packages. The absence of a 'Glossy' attribute has contributed to the incorrect notion that all highlights and reflections are 'Specular' attributes. Even now, glossy reflections are very expensive to calculate, and in most cases, the time and hardware requirements make them impractical for production . While this bottleneck exists, we still have our trusty 'built-in' specular highlights.



Highlight Size

Since a specular-highlight is a reflection of a light source, it only makes sense that the scale of the highlight visually matches the scale of the light source. Unless you are using a physical light source, (which would naturally give you a correctly sized highlight), you should be mindful about adjusting specular values in your shader to reinforce the size and distance of the light source.


highlight_size
Figure 2.3. The size of your highlight should reflect the size of your light source.. Literally.
 


The standard Blinn and Phong shaders have roughness attributes that drive both the shininess of the surface, and the size of the highlight. This can make things a bit more difficult because adjusting the highlight will be more of an intuitive process. The standard PhongE shader however, separates the roughness and highlight size into their own respective attributes, giving the artist more control.
Figure 2.4 The PhongE Shader - has an adjustable specular highlight size, giving the ability to create large 'shiny' highlights, (unlike the Blinn shader which has a highlight size proportionate to it's 'roughness').

phongE_hl_size

Figure 2.4 The PhongE Shader - has an adjustable specular highlight size, giving the ability to create large 'shiny' highlights, (unlike the Blinn shader which has a highlight size proportionate to it's 'roughness').
 



Specular Colour

Another commonly misunderstood shading attribute is the Specular Color. Ideas about it's purpose and how it's used range from 'that's how shiny it is', to 'it's just a lighter version of the color map'.

The truth is, it's a multiplier for the specular highlight and reflection values. If it's set to 50% Grey (0.5), it will cut the intensity of your highlights and reflections in half. If it's set to black (0,0,0), well zero times any number is still zero, so your highlights and reflections will disappear. If you add color to the value, you're highlights and reflections will be tinted that color.
Editing the specular color is probably the most practical (and in some shaders such as blinn, the only) way to have control over the intensity of specular highlights and reflections. Sometimes the Specular Roll Off attribute of a Blinn shader is used to control the highlight intensity; The next chapter on Fresnel Reflection will explain why this practice is incorrect.

Many artist's are in the habit of unintentionally driving the intensity of the light source using the specular color. Using super-white (higher than 1.0) values for specular color can give you nice bright highlights, make your shader's rendered icon look very pretty. This can be okay, but you should consider that:



1. The key light used in the shader icon probably has an intensity of 1.0. This usually isn't considered very bright; If the key light in your scene is brighter than 1.0 the specular highlight will be even brighter than expected.

2. If using Global Illumination, Final Gathering, or Caustics, the shader might behave unpredictably. Take for instance, a shader with a specular color value of 2.0, and diffuse component of 0.7. With diffuse and specular reflection coefficients adding up to 2.7, the object will effectively be reflecting 270% of incoming light. Suffice to say the shader is out of the physically plausible range for total reflected light. If you recall, we concluded that Absorption + Reflection + Transmission should equal 1.0.



Dielectric (non-conducting, non-metallic) Material Highlights

For the most part, specular reflections don't inherit any color from a surface like diffuse reflections do. While Diffusely reflected rays penetrate into the surface, allowing certain wavelengths to be absorbed, specular-rays skip off the surface, like a stone on a pond. Therefore, no absorption occurs and the specularly reflected-rays keep their original colors. Metals are an important exception to this rule.


Non-Dielectric (conducting, metallic) Materials

Metals are conducting materials (called non-dielectrics) with electrical properties that set them apart from other non-conducting materials. They are unique to dielectrics because they are selective about which wavelengths are absorbed, causing reflected rays to adopt perceived color of the material. For example, a gold object will exhibit quasi-monochromatic yellow reflections.

ref_gold_02ref_gold_01
Figure 2.5. Gold objects with quasi-monochromatic yellow reflections.
 


Nearly all incoming light that isn't absorbed by metals is repelled because they have an inappreciable skin-depth. This makes them them almost equally reflective from all angles. Whether the reflection is diffuse, specular, or glossy depends on the surface roughness.

 


Hits: 2295

Comments (0)add comment


Write comment
You must be logged in to post a comment. Please register if you do not have an account yet.

busy
facebook_02twitter_02RSS_02