Computer Graphics. Illumination and Shading

Similar documents
Illumination & Shading: Part 1

Illumination and Shading

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

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

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

Sung-Eui Yoon ( 윤성의 )

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

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

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

Shading and Illumination

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

Illumination & Shading I

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

Light Transport Baoquan Chen 2017

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

Illumination & Shading

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

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

Why we need shading?

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

CEng 477 Introduction to Computer Graphics Fall

CPSC 314 LIGHTING AND SHADING

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

Illumination and Shading ECE 567

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

Illumination and Shading

w Foley, Section16.1 Reading

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

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

Shading I Computer Graphics I, Fall 2008

CMSC427 Shading Intro. Credit: slides from Dr. Zwicker

CSE 681 Illumination and Phong Shading

Illumination and Shading

Lighting/Shading II. Week 7, Mon Mar 1

Lighting/Shading III. Week 7, Wed Mar 3

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

INF3320 Computer Graphics and Discrete Geometry

Shading. Brian Curless CSE 557 Autumn 2017

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

Illumination in Computer Graphics

Comp 410/510 Computer Graphics. Spring Shading

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

CS5620 Intro to Computer Graphics

Introduction to Computer Graphics 7. Shading

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

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

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

Simple Lighting/Illumination Models

CS 4600 Fall Utah School of Computing

Illumination & Shading

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

LIGHTING AND SHADING

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

CS Surface Rendering

Color and Light CSCI 4229/5229 Computer Graphics Fall 2016

Shading 1: basics Christian Miller CS Fall 2011

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

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

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Shading. Brian Curless CSE 457 Spring 2015

Lighting. CSC 7443: Scientific Information Visualization

Shading. Brian Curless CSE 457 Spring 2017

Lessons Learned from HW4. Shading. Objectives. Why we need shading. Shading. Scattering

Illumination Models & Shading

Virtual Reality for Human Computer Interaction

Color and Light. CSCI 4229/5229 Computer Graphics Summer 2008

Shading. CSE 457 Winter 2015

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

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

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

Graphics and Visualization

Reflection and Shading

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

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

CS230 : Computer Graphics Lighting and Shading. Tamar Shinar Computer Science & Engineering UC Riverside

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

Lighting and Shading. Slides: Tamar Shinar, Victor Zordon

CS452/552; EE465/505. Intro to Lighting

Visualisatie BMT. Rendering. Arjan Kok

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

Illumination and Shading

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

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

Lighting Models. CS116B Chris Pollett Mar 21, 2004.

Objectives. Introduce the OpenGL shading Methods 1) Light and material functions on MV.js 2) per vertex vs per fragment shading 3) Where to carry out

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

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

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?

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

Computer Graphics. Illumination and Shading

Pipeline Operations. CS 4620 Lecture 10

Shading , Fall 2004 Nancy Pollard Mark Tomczak

Computer Graphics: 3-Local Illumination Models

Shading & Material Appearance

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

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Illumination. Michael Kazhdan ( /657) HB Ch. 14.1, 14.2 FvDFH 16.1, 16.2

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Raytracing CS148 AS3. Due :59pm PDT

Transcription:

() Illumination and Shading Dr. Ayman Eldeib

Lighting So given a 3-D triangle and a 3-D viewpoint, we can set the right pixels But what color should those pixels be? If we re attempting to create a realistic image, we need to simulate the lighting of the surfaces in the scene Fundamentally simulation of physics and optics As you ll see, we use a lot of approximations (a.k.a hacks) to do this simulation fast enough

Light source Illumination and Shading Shadowing object Surface outside shadow volume (illuminated) Shadow volume (infinite extent) Eye position (note that shadows are independent of the eye position) Partially shadowed object Surface inside shadow volume (shadowed)

What is the problem? Illumination and Shading Mesh Surfaces Must determine the color of each vertex.

Definitions Illumination: the transport of energy (in particular, the luminous flux of visible light) from light sources to surfaces & points Note: includes direct and indirect illumination Lighting: the process of computing the luminous intensity (i.e., outgoing light) at a particular 3-D point, usually on a surface Shading: the process of assigning colors to pixels

Definitions Cont. Illumination models fall into two categories: Empirical: simple formulations that approximate observed phenomenon Physically-based: models based on the actual physics of light interacting with matter We mostly use empirical models in interactive graphics for simplicity Increasingly, realistic graphics are using physically-based models

Components of Illumination Two components of illumination: light sources and surface properties Light sources (or emitters) Spectrum of emittance (i.e, color of the light) Geometric attributes o Position o Direction o Shape Directional attenuation

Components of Illumination Cont. Surface properties Reflectance spectrum (i.e., color of the surface) Geometric attributes o Position o Orientation o Micro-structure Common simplifications in interactive graphics Only direct illumination from emitters to surfaces Simplify geometry of emitters to trivial cases

Ambient Light Source Objects not directly lit are typically still visible E.g., the ceiling in this room, undersides of desks This is the result of indirect illumination from emitters, bouncing off intermediate surfaces Images without ambient light have too much contrast Very rough approximation of global illumination Too expensive to calculate (in real time), so we use a hack called an ambient light source No directional characteristics; illuminates all surfaces equally Amount reflected depends on surface properties Independent of object, light and viewer position

Directional Light Source For a directional light source we make the simplifying assumption that all rays of light from the source are parallel As if the source is infinitely far away from the surfaces in the scene A good approximation to sunlight The direction from a surface to the light source is important in lighting the surface With a directional light source, this direction is constant for all surfaces in the scene

Point Light Source A point light source emits light equally in all directions from a single point The direction to the light from a point on a surface thus differs for different points: So we need to calculate a normalized vector to the light source for every point we light.

Other Light Sources Spotlights are point sources whose intensity falls off directionally. Supported by OpenGL Area light sources define a 2-D emissive surface (usually a disc or polygon) Good example: fluorescent light panels

Physics of Reflection Ideal diffuse reflection An ideal diffuse reflector, at the microscopic level, is a very rough surface (real-world example: chalk) Because of these microscopic variations, an incoming ray of light is equally likely to be reflected in any direction over the hemisphere What does the reflected intensity depend on?

Lambert s Cosine Law Ideal diffuse surfaces reflect according to Lambert s cosine law: The energy reflected by a small portion of a surface from a light source in a given direction is proportional to the cosine of the angle between that direction and the surface normal These are often called Lambertian surfaces Note that the reflected intensity is independent of the viewing direction, but does depend on the surface orientation with regard to the light source

The amount of light falling on a surface is proportional to the angle between the surface normal and the light source direction n=surface normal s=direction of illumination Ө= angle between s and n Computing Diffuse Reflection n s I I = = ρ cosθ ρ ( n s) The amount of light that is reflected I = I cosθ max(cosθ,0) Can not have negative light A Lambertian sphere. NOTE: independent of location of camera

Specular Reflection Shiny surfaces exhibit specular reflection Polished metal Glossy car finish A light shining on a specular surface causes a bright spot known as a specular highlight Where these highlights appear is a function of the viewer s position, so specular reflectance is view-dependent

Physics of Reflection At the microscopic level a specular reflecting surface is very smooth Thus rays of light are likely to bounce off the microgeometry in a mirror-like fashion The smoother the surface, the closer it becomes to a perfect mirror

Optics of Reflection Reflection follows Snell s Laws: The incoming ray and reflected ray lie in a plane with the surface normal The angle that the reflected ray forms with the surface normal equals the angle formed by the incoming ray and the surface normal: θ l = θ r

Non-Ideal Specular Reflection An Empirical Approximation In general, we expect most reflected light to travel in direction predicted by Snell s Law But because of microscopic surface variations, some light may be reflected in a direction slightly off the ideal reflected ray As the angle from the ideal reflected ray increases, we expect less light to be reflected

Illumination and Shading Models How do we model light sources? Point Area How do we model the reflectance of light off a surface? Direct illumination Global illumination How do we model of the material properties of a surface? Plastic, metallic, shiny, etc

Light Sources Distant light source Local light source Distant light source No attenuation Described by a direction Local light source Attenuation with distance Point light sourced described by a position (x,y,z) Area light sources more complicated

Local Light Source Attenuation Radial intensity attenuation function for a point light source for distance d 1 d 2 Radial intensity attenuation function used in practice 1 a + a d + 0 1 a 2 d 2

OpenGL Lighting gllight* (name, property, value) Name specifies which light multiple lights, starting with GL_LIGHT0 glgetintegerv( GL_MAX_LIGHTS, &n ); Properties Position and type Ambient (GL_AMBIENT), diffuse, (GL_DIFFUSE) and specular (GL_SPECULAR) colors Attenuation coefficients

Types of Lights OpenGL Lighting Cont. OpenGL supports two types of Lights Local (Point) light sources Infinite (Directional) light sources Type of light controlled by w coordinate w = 0 Infinite Light directed along (x y z) w 0 Local Light positioned at (x/w y/w z/w)

OpenGL Lighting void InitLights (void) { glenable(gl_lighting); glenable(gl_light0); glenable(gl_light1); Cont. // Turn on the power // Flip each light s switch GLfloat lightpos0[] = {.5, 1,.5, 0}; gllightfv(gl_light0, GL_POSITION, lightpos0); } GLfloat lightpos1[] = {4,4,4,0}; gllightfv(gl_light1, GL_POSITION, lightpos1);

OpenGL Moving Light Source Light sources transform like geometry Only modelview transform is applied Stationary light Set transform to identity before specifying location Moving light push matrix, move light, pop matrix to uniquely control a light s position Light source attached to camera

Lambertian (diffuse) Simple Models in CG Irradiance from any direction is equally scattered in all directions Specular (Perfect) reflection Irradiance from a direction is reflected in only a single direction A Lambertian surface scatters light equally in all directions Diffuse surface Phong Combines Lambertian with specular n Glossy surface Perfect reflector

Find a simple way to create highlights that are viewdependent and happen at about the right place Not physically based Use dot product (cosine) of eye and reflection of light direction about surface normal (n) Raise cosine lobe to some power (n) to control roughness Note: vectors should be normalized to unit length r : direction of specula reflection Phong Reflectance Model s I θ n θ α r = s + 2( s n- )n- = a cos θ + b cos diffuse specular r n e ( ) α Roughness

Phong Reflectance Model Cont. I = a cos θ + bcos n ( ) α a=0.3, b=0.7, n=2 a=0.7, b=0.3, n=0.5 diffuse specular A Lambertian sphere.

Light sources have color Color Objects have color Typically each color component (R,G,B) is treated separately For plastics the color of the specular highlight is the color of the light. For metals the color of the highlight is the color of the metal. Typically a separate color is assigned for the diffuse and specular components

Applying Illumination We now have an illumination model for a point on a surface Assuming that our surface is defined as a mesh of polygonal facets, which points should we use? Keep in mind: It s a fairly expensive calculation Several possible answers, each with different implications for the visual quality of the result

Flat Shading The simplest approach, flat shading, calculates illumination at a single point for each polygon: If an object really is faceted, is this accurate? No: o For point sources, the direction to light varies across the facet o For specular reflectance, direction to eye varies across the facet

Flat Shading Cont. We can refine it a bit by evaluating the Phong lighting model at each pixel of each polygon, but the result is still clearly faceted: To get smoother-looking surfaces we introduce vertex normals at each vertex Usually different from facet normal

Vertex Normal Vertex normal may be Provided with the model Computed from first principles Approximated by averaging the normals of the facets that share the vertex

Goaraud Shading This is the most common approach Perform Phong lighting at the vertices Linearly interpolate the resulting colors over faces This is what OpenGL does Does this eliminate the facets? No

Goaraud Shading Cont. glshademodel(gl_flat) glshademodel(gl_smooth)

Phong Shading Phong shading is not the same as Phong lighting, though they are sometimes mixed up Phong lighting: the empirical model we ve been discussing to calculate illumination at a point on a surface Phong shading: linearly interpolating the surface normal across the facet, applying the Phong lighting model at every pixel o Same input as Gouraud shading o Usually very smooth-looking results o But, considerably more expensive

Transforming Normals Irritatingly, the matrix for transforming a normal vector is not the same as the matrix for the corresponding transformation on points In other words, don t just treat normals as points: Some not-too-complicated affine analysis shows: If A is a matrix for transforming points, then (A T ) -1 is the matrix for transforming normals When is this the same matrix?

Shading Polygons Flat shading Use one surface normal for each polygon Calculate one color for each polygon glshademodel(gl_flat) Gouraud shading Calculate a surface normal at each vertex Calculate color at each vertex Interpolate color inside polygon glshademodel(gl_smooth) Phong normal interpolation Calculate a surface normal at each vertex Interpolate surface normals across polygon Use interpolated normals to calculate color at each pixel OpenGL doesn t do this, but you can with programmable shaders

OpenGL Specifying Material Properties glmaterialfv (face, property, value) Separate materials for front and back Properties

OpenGL Specifying Normal Use the function glnormal3f( x, y, z) Normals define how a surface reflects light Specifying a normal sets the current normal Remains unchanged until user alters it Usual sequence: glnormal, glvertex., glnormal, glvertex.., glnormal, glvertex Usually, we want unit normals for shading glenable( GL_NORMALIZE ) This is slow either normalize them yourself or don t use glscale scaling affects a normal s length You should generate normals for curved surfaces GLUT does it automatically for teapot, cylinder,

Questions?