Reading. Shading. An abundance of photons. Introduction. Required: Angel , 6.5, Optional: Angel 6.4 OpenGL red book, chapter 5.

Similar documents
Reading. Shading. Introduction. An abundance of photons. Required: Angel , Optional: OpenGL red book, chapter 5.

Introduction. Lighting model Light reflection model Local illumination model Reflectance model BRDF

w Foley, Section16.1 Reading

Shading. Reading. Pinhole camera. Basic 3D graphics. Brian Curless CSE 557 Fall Required: Shirley, Chapter 10

Shading. Brian Curless CSE 557 Autumn 2017

Shading. Brian Curless CSE 457 Spring 2015

Shading. CSE 457 Winter 2015

Shading. Brian Curless CSE 457 Spring 2017

Computer Graphics. Illumination and Shading

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

Illumination & Shading: Part 1

CEng 477 Introduction to Computer Graphics Fall

Computer Graphics (CS 4731) Lecture 16: Lighting, Shading and Materials (Part 1)

Illumination & Shading

Shading and Illumination

Overview. Shading. Shading. Why we need shading. Shading Light-material interactions Phong model Shading polygons Shading in OpenGL

CPSC 314 LIGHTING AND SHADING

Shading I Computer Graphics I, Fall 2008

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

Computer Graphics (CS 543) Lecture 7b: Intro to lighting, Shading and Materials + Phong Lighting Model

Today. Global illumination. Shading. Interactive applications. Rendering pipeline. Computergrafik. Shading Introduction Local shading models

CS5620 Intro to Computer Graphics

Comp 410/510 Computer Graphics. Spring Shading

Sung-Eui Yoon ( 윤성의 )

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

Illumination and Shading

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

Illumination and Shading

Illumination Models & Shading

Topic 9: Lighting & Reflection models 9/10/2016. Spot the differences. Terminology. Two Components of Illumination. Ambient Light Source

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

Ambient reflection. Jacobs University Visualization and Computer Graphics Lab : Graphics and Visualization 407

Why we need shading?

CMSC427 Shading Intro. Credit: slides from Dr. Zwicker

Topic 9: Lighting & Reflection models. Lighting & reflection The Phong reflection model diffuse component ambient component specular component

INF3320 Computer Graphics and Discrete Geometry

Light Sources. Spotlight model

CSE 167: Introduction to Computer Graphics Lecture #6: Lights. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2016

Today s class. Simple shadows Shading Lighting in OpenGL. Informationsteknologi. Wednesday, November 21, 2007 Computer Graphics - Class 10 1

CS 5625 Lec 2: Shading Models

Illumination. Illumination CMSC 435/634

Simple Lighting/Illumination Models

Light Transport Baoquan Chen 2017

Illumination & Shading I

Illumination and Shading ECE 567

Shading , Fall 2004 Nancy Pollard Mark Tomczak

Illumination Model. The governing principles for computing the. Apply the lighting model at a set of points across the entire surface.

Introduction to Computer Graphics 7. Shading

Illumination and Shading

WHY WE NEED SHADING. Suppose we build a model of a sphere using many polygons and color it with glcolor. We get something like.

Computer Graphics. Illumination and Shading

Illumination in Computer Graphics

C O M P U T E R G R A P H I C S. Computer Graphics. Three-Dimensional Graphics V. Guoying Zhao 1 / 65

Shading. Why we need shading. Scattering. Shading. Objectives

Computer Graphics. Shading. Based on slides by Dianna Xu, Bryn Mawr College

Illumination and Shading

OpenGL Lighting Computer Graphics Spring Frank Palermo

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

Lighting and Shading Computer Graphics I Lecture 7. Light Sources Phong Illumination Model Normal Vectors [Angel, Ch

CPSC / Illumination and Shading

CS130 : Computer Graphics Lecture 8: Lighting and Shading. Tamar Shinar Computer Science & Engineering UC Riverside

Lighting/Shading III. Week 7, Wed Mar 3

Virtual Reality for Human Computer Interaction

Virtual Reality for Human Computer Interaction

Local Illumination. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

University of British Columbia CPSC 314 Computer Graphics Sep-Dec Tamara Munzner (guest lecturing) Lighting/Shading

CS 4731: Computer Graphics Lecture 16: Phong Illumination and Shading. Emmanuel Agu

CS Illumination and Shading. Slide 1

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Lighting. CSC 7443: Scientific Information Visualization

CSE 167: Lecture #7: Color and Shading. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Illumination & Shading

surface: reflectance transparency, opacity, translucency orientation illumination: location intensity wavelength point-source, diffuse source

CSE 167: Lecture #8: Lighting. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Ligh%ng and Shading. Ligh%ng and Shading. q Is this a plate or a ball? q What color should I set for each pixel?

Visualisatie BMT. Rendering. Arjan Kok

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

Lighting affects appearance

Graphics and Visualization

Lecture 4: Reflection Models

Shading 1: basics Christian Miller CS Fall 2011

CS6670: Computer Vision

University of Victoria CSC 305 Shading. Brian Wyvill 2016

Shading Intro. Shading & Lighting. Light and Matter. Light and Matter

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

CS6670: Computer Vision

Lights, Surfaces, and Cameras. Light sources emit photons Surfaces reflect & absorb photons Cameras measure photons

Interactive Real-Time Raycasting

CSE 681 Illumination and Phong Shading

CS770/870 Spring 2017 Color and Shading

Objectives. Introduce Phong model Introduce modified Phong model Consider computation of required vectors Discuss polygonal shading.

LIGHTING AND SHADING

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Lighting affects appearance

Lighting. To do. Course Outline. This Lecture. Continue to work on ray programming assignment Start thinking about final project

Homework #2. Shading, Ray Tracing, and Texture Mapping

Rendering: Reality. Eye acts as pinhole camera. Photons from light hit objects

Lighting. Figure 10.1

Transcription:

Reading Required: Angel 6.1-6.3, 6.5, 6.7-6.8 Optional: Shading Angel 6.4 OpenGL red book, chapter 5. 1 2 Introduction An abundance of photons So far, we ve talked exclusively about geometry. Properly determining the right color is really hard. What is the shape of an object? How do I place it in a virtual 3D space? How do I know which pixels it covers? How do I know which of the pixels I should actually draw? Look around the room. Each light source has different characteristics. Trillions of photons are pouring out every second. These photons can: Once we ve answered all those, we have to ask one more important question: To what value do I set each pixel? Answering this question is the job of the shading model. Other names: Lighting model Light reflection model Local illumination model Reflectance model BRDF interact with the atmosphere, or with things in the atmosphere strike a surface and be absorbed be reflected (scattered) cause fluorescence or phosphorescence. interact in a wavelength-dependent manner generally bounce around and around 3 4

Our problem Setup We re going to build up to an approximation of reality called the Phong illumination model. It has the following characteristics: not physically based gives a first-order approximation to physical light reflection very fast widely used Given: In addition, we will assume local illumination, i.e., light goes: light source -> surface -> viewer. No interreflections, no shadows. a point P on a surface visible through pixel p The normal N at P The lighting direction, L, and intensity, L,at P The viewing direction, V, at P The shading coefficients at P Compute the color, I, of pixel p. Assume that the direction vectors are normalized: N = L = V = 1 5 6 Iteration zero Iteration one The simplest thing you can do is Assign each polygon a single color: I=k e Let s make the color at least dependent on the overall quantity of light available in the scene: I = ke + kala where I is the resulting intensity k e is the emissivity or intrinsic shade associated with the object k a is the ambient reflection coefficient. really the reflectance of ambient light ambient light is assumed to be equal in all directions L a is the ambient light intensity. This has some special-purpose uses, but not really good for drawing a scene. [Note: k e is omitted in Angel.] Physically, what is ambient light? 7 8

Wavelength dependence Diffuse reflection Really, k e, k a, and I a are functions over all wavelengths λ. Ideally, we would do the calculation on these functions. For the ambient shading equation, we would start with: I ( λ) =k ( λ) L ( λ) a a Let s examine the ambient shading model: objects have different colors we can control the overall light intensity what happens when we turn off the lights? what happens as the light intensity increases? what happens if we change the color of the lights? then we would find good RGB values to represent the spectrum I(λ). Traditionally, though, k a and I a are represented as RGB triples, and the computation is performed on each color channel separately: I =k L I =k L I =k L R a,r a,r G a,g a,g B a,b a,b So far, objects are uniformly lit. not the way things really appear in reality, light sources are localized in position or direction Diffuse, or Lambertian reflection will allow reflected intensity to vary with the direction of the light. 9 10 Diffuse reflectors Diffuse reflectors Diffuse reflection occurs from dull, matte surfaces, like latex paint, or chalk. These diffuse or Lambertian reflectors reradiate light equally in all directions. or picture a surface with little pigment particles embedded beneath the surface (neglect reflection at the surface for the moment): Picture a rough surface with lots of tiny microfacets. The microfacets and pigments distribute light rays in all directions. Embedded pigments are responsible for the coloration of diffusely reflected light in plastics and paints. Note: the figures above are intuitive, but not strictly (physically) correct. 11 12

Diffuse reflectors, cont. Iteration two The reflected intensity from a diffuse surface does not depend on the direction of the viewer. The incoming light, though, does depend on the direction of the light source: The incoming energy is proportional to the diffuse reflection equations: I=k +k L +k L e a a d, giving =k +k I +k L( ) e a a d where: k d is the diffuse reflection coefficient L is the intensity of the light source N is the normal to the surface (unit vector) L is the direction to the light source (unit vector) (x) + means max {0,x} [Note: Angel uses L d instead of L.] 13 14 Specular reflection Specular reflection derivation Specular reflection accounts for the highlight that you see on some objects. It is particularly important for smooth, shiny surfaces, such as: metal polished stone plastics apples skin For a perfect mirror reflector, light is reflected about N, so L if V= R I = 0 otherwise Properties: Specular reflection depends on the viewing direction V. For non-metals, the color is determined solely by the color of the light. For metals, the color may be altered (e.g., brass) For a near-perfect reflector, you might expect the highlight to fall off quickly with increasing angle φ. Also known as: rough specular reflection directional diffuse reflection glossy reflection 15 16

Derivation, cont. Iteration three cos ns φ 1 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0 100 80 60 40 20 0 20 40 60 80 100 One way to get this effect is to take (R V), raised to a power n s. As n s gets larger, ns = 128 ns = 1 φ the dropoff becomes {more,less} gradual gives a {larger,smaller} highlight simulates a {more,less} mirror-like surface 210 150 L 240 120 1.0 0.8 0.6 0.4 N 0.2 180 0 90 R 60 V 300 30 330 The next update to the Phong shading model is then: where: s I=k +k I +k L( NL ) +k L( VR ) n e a a d + s + k s is the specular reflection coefficient n s is the specular exponent or shininess R is the reflection of the light about the normal (unit vector) V is viewing direction (unit vector) [Note: Angel uses α instead of n s, and maintains a separate L d and L s, instead of a single L. This choice reflects the flexibility available in OpenGL.] 17 18 Intensity drop-off with distance OpenGL supports different kinds of lights: point, directional, and spot. For point light sources, the laws of physics state that the intensity of a point light source must drop off inversely with the square of the distance. We can incorporate this effect by multiplying I l by 1/d 2. Sometimes, this distance-squared dropoff is considered too harsh. A common alternative is: Iteration four Since light is additive, we can handle multiple lights by taking the sum over every light. Our equation is now: I=k +k L + f atten( d ) L k ( NL ) +k ( VR ) ns e a a j j d j + s j + j This is the Phong illumination model. Which quantities are spatial vectors? f atten 1 (d)= a+bd+cd 2 Which are RGB triples? with user-supplied constants for a, b, and c. Which are scalars? 19 20

Choosing the parameters Experiment with different parameter settings. To get you started, here are a few suggestions: Materials in OpenGL The OpenGL code to specify the surface shading properties is fairly straightforward. For example: Try n s in the range [0,100] Try k a + k d + k s < 1 Use a small k a (~0.1) Metal Plastic Planet n s large medium 0 k d Small, color of metal Medium, color of plastic varying k s Large, color of metal Medium, white 0 GLfloat ke[] = { 0.1, 0.15, 0.05, 1.0 }; GLfloat ka[] = { 0.1, 0.15, 0.1, 1.0 }; GLfloat kd[] = { 0.3, 0.3, 0.2, 1.0 }; GLfloat ks[] = { 0.2, 0.2, 0.2, 1.0 }; GLfloat ns[] = { 50.0 }; glmaterialfv(gl_front, GL_EMISSION, ke); glmaterialfv(gl_front, GL_AMBIENT, ka); glmaterialfv(gl_front, GL_DIFFUSE, kd); glmaterialfv(gl_front, GL_SPECULAR, ks); glmaterialfv(gl_front, GL_SHININESS, ns); Notes: The GL_FRONT parameter tells OpenGL that we are specifiying the materials for the front of the surface. Only the alpha value of the diffuse color is used for blending. It s usually set to 1. 21 22 Shading in OpenGL Shading in OpenGL The OpenGL lighting model allows you to associate different lighting colors according to material properites they will influence. Thus, our original shading equation becomes: I=k +k L + f atten( d ) k L +k L ( NL ) +k L ( VR ) ns e a a j a a j d d j j + s s j j + j where you can have a global ambient light with intensity L a in addition to have an ambient light intensity L a j associated with each individual light. Repeating from the previous slide I=k +k L + f atten( d ) k L +k L ( NL ) +k L ( VR ) ns e a a j a a j d d j j + s s j j + j In OpenGL this equation is specified something like: GLfloat La[] = { 0.2, 0.2, 0.2, 1.0 }; GLfloat La0[] = { 0.1, 0.1, 0.1, 1.0 }; GLfloat Ld0[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat Ls0[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat pos0[] = { 1.0, 1.0, 1.0, 0.0 }; GLfloat a[] = { 1.0 }; GLfloat b[] = { 0.5 }; GLfloat c[] = { 0.25 }; gllightmodelfv(gl_light_model_ambient, La); gllightfv(gl_light0, GL_AMBIENT, La0); gllightfv(gl_light0, GL_DIFFUSE, Ld0); gllightfv(gl_light0, GL_SPECULAR, Ls0); gllightfv(gl_light0, GL_POSITION, pos0); gllightfv(gl_light0, GL_CONSTANT_ATTENUATION, a); gllightfv(gl_light0, GL_LINEAR_ATTENUATION, b); gllightfv(gl_light0, GL_QUADRATIC_ATTENUATION, c); You can have as many as GL_MAX_LIGHTS lights in a scene. This number is system-dependent. 23 24

BRDF More sophisticated BRDF s The Phong illumination model is really a function that maps light from incoming (light) directions ω in to outgoing (viewing) directions ω out : f ( ω, ω ) r in out Cook and Torrance, 1982 This function is called the Bi-directional Reflectance Distribution Function (BRDF). Here s a plot with ω in held constant: ω in f ( ω, ω ) r in out Westin, Arvo, Torrance 1992 BRDF s can be quite sophisticated 25 26 Gouraud vs. Phong interpolation Faceted shading Now we know how to compute the color at a point on a surface using the Phong lighting model. Assume each face has a constant normal: Does graphics hardware do this calculation at every point? Typically not (although this is changing) Smooth surfaces are often approximated by polygonal facets, because: Graphics hardware generally wants polygons (esp. triangles). Sometimes it easier to write ray-surface intersection algorithms for polygonal models. How do we compute the shading for such a surface? For a distant viewer and a distant light source, how will the color of each triangle vary? Result: faceted, not smooth, appearance. 27 28

Faceted shading (cont d) Gouraud interpolation To get a smoother result that is easily performed in hardware, we can do Gouraud interpolation. Here s how it works: 1. Compute normals at the vertices. 2. Shade only the vertices. 3. Interpolate the resulting vertex colors. 29 30 Facted shading vs. Gouraud interpolation Gouraud interpolation artifacts Gouraud interpolation has significant limitations. 1. If the polygonal approximation is too coarse, we can miss specular highlights. 2. We will encounter Mach banding (derivative discontinuity enhanced by human eye). Alas, this is usually what graphics hardware supports. Maybe someday soon all graphics hardware will do 31 32

Phong interpolation Gouraud vs. Phong interpolation To get an even smoother result with fewer artifacts, we can perform Phong interpolation. Here s how it works: 1. Compute normals at the vertices. 2. Interpolate normals and normalize. 3. Shade using the interpolated normals. 33 34 Summary The most important thing to take away from this lecture is the equation for the Phong model described in the Iteration Four slide. What is the physical meaning of each variable? How are the terms computed? What effect does each term contribute to the image? What does varying the parameters do? You should also understand the differences between faceted, Gouraud, and Phong interpolated shading. 35