360 likes | 534 Vues
Lighting. What is Light?. A very complex process Find a dark area – how is it being lit? Light bounces (mirrors, shiny objects) Light refracts through other media (water, heat) Light comes from everywhere (Global Illumination) Light bounces off of lakes in weird ways (Fresnel effect)
E N D
Lighting Jeff Chastine
What is Light? • A very complex process • Find a dark area – how is it being lit? • Light bounces (mirrors, shiny objects) • Light refracts through other media (water, heat) • Light comes from everywhere (Global Illumination) • Light bounces off of lakes in weird ways (Fresnel effect) • THUS • We’re forced to make approximations • Tradeoff between time and realism • “If it looks good, it is good” – Michael Abrash http://en.wikipedia.org/wiki/File:Global_illumination.JPG http://darrentakenaga.com/3d.html Jeff Chastine
A Basic Lighting Concept • How can we determine how much light should be cast onto a triangle from a directional light? Directional light - position doesn’t matter - triangle is almost fully lit P0 P1 P2 Jeff Chastine
A Basic Lighting Concept • How can we determine how much light should be cast onto a triangle from a directional light? P0 (Triangle less lit) P1 P2 Jeff Chastine
A Basic Lighting Concept • How can we determine how much light should be cast onto a triangle from a directional light? P0 P1 P2 (Little to no light hits the surface) Jeff Chastine
A Basic Lighting Concept • How can we determine how much light should be cast onto a triangle from a directional light? P0 (Directional light) P1 P2 Jeff Chastine
A Basic Lighting Concept • How can we determine how much light should be cast onto a triangle from a directional light? P0 (Directional light) P1 P2 Jeff Chastine
A Basic Lighting Concept • How can we determine how much light should be cast onto a triangle from a directional light? Lesson learned: Lighting depends on angles between vectors! P0 (Directional light) P1 P2 Jeff Chastine
A Basic Lighting Concept • How can we determine how much light should be cast onto a triangle from a directional light? P0 (Directional light) P1 P2 Assuming N and L are normalized, and N∙L isn’t negative Jeff Chastine
Basic Lighting • Four independent components: • Diffuse – the way light “falls off” of an object • Specular – the “shininess” of the object • Ambient – a minimum amount of light used to simulate “global illumination” • Emit – a “glowing” effect Only diffuse Jeff Chastine
Basic Lighting • Four independent components: • Diffuse – the way light “falls off” of an object • Specular – the “shininess” of the object • Ambient – a minimum amount of light used to simulate “global illumination” • Emit – a “glowing” effect Diffuse+Specular Jeff Chastine
Basic Lighting • Four independent components: • Diffuse – the way light “falls off” of an object • Specular – the “shininess” of the object • Ambient – a minimum amount of light used to simulate “global illumination” • Emit – a “glowing” effect Diffuse+Specular+Ambient Ambient Jeff Chastine
Basic Lighting • Four independent components: • Diffuse – the way light “falls off” of an object • Specular – the “shininess” of the object • Ambient – a minimum amount of light used to simulate “global illumination” • Emit – a “glowing” effect D+S+A+Emit Note: emit does not produce light! Jeff Chastine
Interaction between Material and Lights • Final color of an object is comprised of many things: • The base object color (called a “material”) • The light color • Example: a purple light on a white surface • Any textures we apply (later) • Materials and lights have four individual components • Diffuse color (cdand ld) • Specular color (csand ls) • Ambient color (caand la) • Emit color (ceand le) • cd* ld = [cd.r*ld.r, cd.g*ld.g, cd.b*ld.b] // R, G, B Jeff Chastine
General Lighting • Primary vectors • l – the incoming light vector • n – the normal of the plane/vertex • r – the reflection vector • v – the viewpoint (camera) v n l r θ θ Jeff Chastine
LambertianReFlectance(diffuse Component) • Light falling on an object is the same regardless of the observer’s viewpoint • Good for rough surfaces without specular highlights • where and are normalized n l θ Jeff Chastine
LambertianReFlectance(diffuse Component) • Light falling on an object is the same regardless of the observer’s viewpoint • Good for rough surfaces without specular highlights • where and are normalized 3 parts (R, G, B) scalar n l θ Note: final_colordiffusehas R, G, B Jeff Chastine
LambertianReFlectance(diffuse Component) • Technically, it should be: n l θ Jeff Chastine
BLINN-PHONG Reflection(Specular Component) • Describes the specular highlight and is dependent on viewpoint v • Also describes a “half-vector” h that is halfway between v and l h v n r l θ θ Jeff Chastine
BLINN-PHONG Reflection(Specular Component) • - which is really Blinn’s contribution to the original Phong model h v n r l θ θ Note: vectors should be normalized Jeff Chastine
BLINN-PHONG Reflection(Specular Component) • Our final specular equation is: h v n r l θ θ Jeff Chastine
Determining • Realize that will always be < 1.0, so raising it to a power will make it smaller • is the “shininess” factor • It relates to the size of the specular highlight s = ~1 s = ~30 s = ~255 Jeff Chastine
Ambient and Emit Components • Ambient: • Used to simulate light bouncing around the environment (global illumination) • Real world is far too complex for real time, so just add a little light! • Emit: • Used to make the object “glow” • Does not emit light!!! • Both: • Independent of viewpoint • Super easy to calculate Jeff Chastine
Final Color • To determine the final color (excluding textures) we sum up all components: final_colordiffuse final_colorspecular final_colorambient final_coloremit final_color + http://en.wikipedia.org/wiki/Phong_reflection_model Jeff Chastine
What about Multiple lights? • Calculate final colors and sum them all together • Assuming results are in f [ ] and there are count number of lights Jeff Chastine
Common Kinds of Lights • Point light • Directional Light • Spot Light • Area Light • Interesting fact: • Lights cannot be seen! • Only their effects • We can light per vertex (fast) or per fragment (slower) Jeff Chastine
Point Lights • These lights have a position in 3D space • Sometimes called a “Lamp” • Light emanates from the light in all directions • Distance d determines brightness (“attenuation”): Here, per fragment lighting used Jeff Chastine
Point Lights • These lights have a position in 3D space • Sometimes called a “Lamp” • Light emanates from the light in all directions • Distance d determines brightness (“attenuation”): Here, per vertex lighting used Jeff Chastine
Directional Lights • Are infinitely far away • position in NO WAY matters • Have only direction • All objects are lit evenly • Sometimes called a “Sun” Jeff Chastine
Spotlights • Point light source • Conical in shape Jeff Chastine
Spotlights • Point light source • Conical in shape • Have: • An inner and outer cone angle • Umbra – areas that are fully in shadow • Penumbra – areas that are in partial shadow • Note: There’s an ambient light Jeff Chastine
Area Lights • A “surface” lights objects • Has a position and direction • Provides for a smoother drop off than point • Larger surface == smoother shadows • Expensive to calculate Jeff Chastine