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

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

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

Shading. Brian Curless CSE 457 Spring 2015

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

Shading. Brian Curless CSE 557 Autumn 2017

Shading. CSE 457 Winter 2015

w Foley, Section16.1 Reading

Shading. Brian Curless CSE 457 Spring 2017

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

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

CEng 477 Introduction to Computer Graphics Fall

Computer Graphics. Illumination and Shading

Shading and Illumination

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

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

Illumination & Shading: Part 1

Why we need shading?

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

Illumination & Shading

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

Light Sources. Spotlight model

Comp 410/510 Computer Graphics. Spring Shading

CPSC 314 LIGHTING AND SHADING

Shading I Computer Graphics I, Fall 2008

Illumination and Shading ECE 567

Sung-Eui Yoon ( 윤성의 )

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

CS5620 Intro to Computer Graphics

Illumination and Shading

INF3320 Computer Graphics and Discrete Geometry

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

Lighting. CSC 7443: Scientific Information Visualization

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

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Illumination and Shading

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

Illumination Models & Shading

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

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

Shading , Fall 2004 Nancy Pollard Mark Tomczak

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

CMSC427 Shading Intro. Credit: slides from Dr. Zwicker

Virtual Reality for Human Computer Interaction

Light Transport Baoquan Chen 2017

Simple Lighting/Illumination Models

CS Surface Rendering

Introduction to Computer Graphics 7. Shading

Virtual Reality for Human Computer Interaction

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

Illumination. Illumination CMSC 435/634

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

CS 5625 Lec 2: Shading Models

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

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

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

Graphics and Visualization

Illumination & Shading I

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?

Illumination in Computer Graphics

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

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

Computer Graphics. Illumination and Shading

Illumination and Shading

Illumination and Shading

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Lighting/Shading III. Week 7, Wed Mar 3

OpenGL Lighting Computer Graphics Spring Frank Palermo

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

CPSC / Illumination and Shading

Shading. Reading. Pinhole camera. Basic 3D graphics. Brian Curless CSE 457 Spring Required: Angel chapter 5.

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

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

CS Illumination and Shading. Slide 1

Shading 1: basics Christian Miller CS Fall 2011

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

Illumination & Shading

Display Issues Week 5

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

Visualisatie BMT. Rendering. Arjan Kok

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

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

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

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

CSE 681 Illumination and Phong Shading

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

Lights, Colour and Materials In OpenGL

University of Victoria CSC 305 Shading. Brian Wyvill 2016

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

CS 4600 Fall Utah School of Computing

Today we will start to look at illumination models in computer graphics

Lighting affects appearance

Lecture 4 Advanced Computer Graphics (CS & SE )

CS770/870 Spring 2017 Color and Shading

Lecture 4: Reflection Models

Computer Graphics. Illumination Models and Surface-Rendering Methods. Somsak Walairacht, Computer Engineering, KMITL

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

Transcription:

Reading Required: Angel 6.1-6.5, 6.7-6.8 Optional: Shading OpenGL red book, chapter 5. 1 2 Introduction So far, we ve talked exclusively about geometry. What is the shape of an obect? 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? 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 ob of the shading model. Other names: Lighting model Light reflection model Local illumination model Reflectance model BRDF An abundance of photons Properly determining the right color is really hard. Look around the room. Each light source has different characteristics. Trillions of photons are pouring out every second. These photons can: 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 In addition, we will assume local illumination, i.e., light goes: light source -> surface -> viewer. No interreflections, no shadows. Given: 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: where I=k e I is the resulting intensity k e is the emissivity or intrinsic shade associated with the obect This has some special-purpose uses, but not really good for drawing a scene. [Note: k e is omitted in Angel.] Let s make the color at least dependent on the overall quantity of light available in the scene: I = ke + kala 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. Physically, what is ambient light? 7 8

Wavelength dependence Diffuse reflection Really, k e, k a, and L 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: obects 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, obects 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 L +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 obects. 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 The next update to the Phong shading model is then: 0.9 0.8 0.7 0.6 ns = 1 s I=k +k L +k L( NL ) +k BL( VR ) n e a a d + s + 0.5 0.4 0.3 0.2 0.1 ns = 128 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, the dropoff becomes {more,less} gradual gives a {larger,smaller} highlight simulates a {more,less} mirror-like surface φ where: 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) H prevents contribution of light from below the surface: 1 if NL > 0 B= 0 if NL 0 [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 Lights OpenGL supports three different kinds of lights: ambient, directional, and point. Spot lights are also supported as a special form of point light. We ve seen ambient light sources, which are not really geometric. Directional light sources have a single direction and intensity associated with them. Point lights The direction of a point light sources is determined by the vector from the light position to the surface point. E-P L= E-P d = E-P Physics tells us the intensity must drop off inversely with the square of the distance: Sometimes, this distance-squared dropoff is considered too harsh. A common alternative is: f atten f atten 1 = d 2 1 = 2 a+bd+cd with user-supplied constants for a, b, and c. 19 20

Spotlights OpenGL also allows one to apply a directional attenuation of a point light source, giving a spotlight effect. 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 + e a a ( L S) e β ( NL ) B ( VR ) L k +k ns 2 d + s + a+bd+cd The spotlight intensity factor is computed in OpenGL as: where f = spot e ( L S) β L is the direction to the point light. S is the center direction of the spotlight. β is the cutoff angle for the spotlight e is the angular falloff coefficient e e ( x) = { ( ) β β max acos x, 0} This is the Phong illumination model. Which quantities are spatial vectors? Which are RGB triples? Which are scalars? 21 22 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. 23 24

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: I=k +k L + becomes: I=k +k L + e a a e a a e ( L ) S ( L S) β 2 a+bd+cd e β ( NL ) B ( VR ) L k +k ns 2 d + s + a+bd+cd kl +kl ( NL ) +k B L ( VR ) ns a a d d + s s + where you can have a global ambient light with intensity L a in addition to having an ambient light intensity L a associated with each individual light. Shading in OpenGL, cont d In OpenGL this equation, for one light source (the 0 th ) 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 a0[] = { 1.0 }; GLfloat b0[] = { 0.5 }; GLfloat c0[] = { 0.25 }; GLfloat S0[] = { -1.0, -1.0, 0.0 }; GLfloat beta0[] = { 45 }; GLfloat e0[] = { 2 }; 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, a0); gllightfv(gl_light0, GL_LINEAR_ATTENUATION, b0); gllightfv(gl_light0, GL_QUADRATIC_ATTENUATION, c0); gllightfv(gl_light0, GL_SPOT_DIRECTION, S0); gllightf(gl_light0, GL_SPOT_CUTOFF, beta0); gllightf(gl_light0, GL_SPOT_EXPONENT, e0); 25 26 Shading in OpenGL, cont d Notes: You can have as many as GL_MAX_LIGHTS lights in a scene. This number is system-dependent. For directional lights, you specify a light direction, not position, and the attenuation and spotlight terms are ignored. The directions of directional lights and spotlights are specified in the coordinate systems of the lights, not the surface points as we ve been doing in lecture. BRDF The Phong illumination model is really a function that maps light from incoming (light) directions ω in to outgoing (viewing) directions ω out : This function is called the Bi-directional Reflectance Distribution Function (BRDF). Here s a plot with ω in held constant: ω in f ( ω, ω ) r in out f ( ω, ω ) r in out BRDF s can be quite sophisticated 27 28

More sophisticated BRDF s Gouraud vs. Phong interpolation Now we know how to compute the color at a point on a surface using the Phong lighting model. Cook and Torrance, 1982 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? Westin, Arvo, Torrance 1992 29 Faceted shading 30 Faceted shading (cont d) Assume each face has a constant normal: For a distant viewer and a distant light source and constant material properties over the surface, how will the color of each triangle vary? Result: faceted, not smooth, appearance. 31 32

Gouraud interpolation Facted shading vs. 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. 33 34 Gouraud interpolation artifacts Phong interpolation Gouraud interpolation has significant limitations. To get an even smoother result with fewer artifacts, we can perform Phong interpolation. 1. If the polygonal approximation is too coarse, we can miss specular highlights. Here s how it works: 1. Compute normals at the vertices. 2. Interpolate normals and normalize. 3. Shade using the interpolated normals. 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 35 36

Gouraud vs. Phong interpolation Summary The most important thing to take away from this lecture is the equation for the Phong lighting 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. 37 38