CS Computer Graphics: Illumination and Shading I

Similar documents
CS Computer Graphics: Illumination and Shading I

Illumination & Shading I

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

Illumination and Shading

Shading and Illumination

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

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

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

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

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

Illumination and Shading

Computer Graphics. Illumination and Shading

Lighting. CSC 7443: Scientific Information Visualization

Graphics and Visualization

蔡侑庭 (Yu-Ting Tsai) National Chiao Tung University, Taiwan. Prof. Wen-Chieh Lin s CG Slides OpenGL 2.1 Specification

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

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

Illumination and Shading ECE 567

Reflection and Shading

Illumination & Shading

Why we need shading?

INF3320 Computer Graphics and Discrete Geometry

CEng 477 Introduction to Computer Graphics Fall

Comp 410/510 Computer Graphics. Spring Shading

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

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

Surface Rendering Methods

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

CS 148, Summer 2012 Introduction to Computer Graphics and Imaging

CSCI 4620/8626. Computer Graphics Illumination Models and Surface Rendering Methods (Chapter 17)

CS5620 Intro to Computer Graphics

Rendering. Illumination Model. Wireframe rendering simple, ambiguous Color filling flat without any 3D information

LIGHTING AND SHADING

CS Illumination and Shading. Slide 1

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

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

Virtual Reality for Human Computer Interaction

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. Shading. Based on slides by Dianna Xu, Bryn Mawr College

CS 4600 Fall Utah School of Computing

Introduction to Computer Graphics 7. Shading

Light Transport Baoquan Chen 2017

Illumination and Reflection in OpenGL CS 460/560. Computer Graphics. Shadows. Photo-Realism: Ray Tracing. Binghamton University.

Illumination & Shading: Part 1

Illumination and Shading

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

Shading , Fall 2004 Nancy Pollard Mark Tomczak

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

Lighting/Shading III. Week 7, Wed Mar 3

Introduction to Computer Graphics. Farhana Bandukwala, PhD Lecture 14: Light Interacting with Surfaces

Illumination in Computer Graphics

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

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 II. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Lights, Colour and Materials In OpenGL

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

Lighting Models. CS116B Chris Pollett Mar 21, 2004.

Light Sources. Spotlight model

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 I Computer Graphics I, Fall 2008

CS452/552; EE465/505. Lighting & Shading

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

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

Sung-Eui Yoon ( 윤성의 )

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

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

Lecture 15: Shading-I. CITS3003 Graphics & Animation

5.2 Shading in OpenGL

Illumination Models & Shading

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

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

Shading in OpenGL. Outline. Defining and Maintaining Normals. Normalization. Enabling Lighting and Lights. Outline

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

CS Surface Rendering

w Foley, Section16.1 Reading

Simple Lighting/Illumination Models

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

Chapter 10. Surface-Rendering Methods. Somsak Walairacht, Computer Engineering, KMITL

Graphics for VEs. Ruth Aylett

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

Computer Graphics (CS 543) Lecture 8a: Per-Vertex lighting, Shading and Per-Fragment lighting

Display Issues Week 5

Illumination and Shading

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

CS452/552; EE465/505. Intro to Lighting

Shading. Brian Curless CSE 457 Spring 2015

CS 5625 Lec 2: Shading Models

CS Computer Graphics: Ray Tracing Detail, Part 3

Computer Graphics. Illumination and Shading

Lecture 4 Advanced Computer Graphics (CS & SE )

Graphics for VEs. Ruth Aylett

Lighting/Shading II. Week 7, Mon Mar 1

Turn on the Lights: Reflectance

Shading. CSE 457 Winter 2015

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Introduction to Ray Tracing

CS Computer Graphics: Ray Tracing Detail, Part 3

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

Transcription:

CS 543 - Computer Graphics: Illumination and Shading I by Robert W. Lindeman gogo@wpi.edu (with help from Emmanuel Agu ;-) Illumination and Shading Problem: Model light/surface point interactions to determine final color and brightness Apply the lighting model at a set of points across the entire surface lighting Shading R.W. Lindeman - WPI Dept. of Computer Science 2 1

Illumination Model The governing principles for computing the illumination An illumination model usually considers Light attributes (intensity, color, position, direction, shape) Object surface attributes (color, reflectivity, transparency, etc.) Interaction among lights and objects R.W. Lindeman - WPI Dept. of Computer Science 3 Basic Light Sources Light intensity can be independent or dependent of the distance between object and the light source Point light Spot light Directional light Area light R.W. Lindeman - WPI Dept. of Computer Science 4 2

Local Illumination Only consider the light, the observer position, and the object material properties OpenGL does this θ R.W. Lindeman - WPI Dept. of Computer Science 5 Global Illumination Take into account the interaction of light from all the surfaces in the scene Example: Ray Tracing Model light rays bouncing around object 4 object 3 object 2 object 1 R.W. Lindeman - WPI Dept. of Computer Science 6 3

Global Illumination (cont.) Example: Radiosity Model energy moving from emitters (e.g., lights) into the scene View independent R.W. Lindeman - WPI Dept. of Computer Science 7 Simple Local Illumination The model used by OpenGL Reduce the complex workings of light to three components Ambient Diffuse Specular Final illumination at a point (vertex) = ambient + diffuse + specular Materials reflect each component differently Use different material reflection coefficients K a, K d, K s R.W. Lindeman - WPI Dept. of Computer Science 8 4

Ambient Light Contribution Ambient light = background light Light that is scattered by the environment It's just there Frequently assumed to be constant Very simple approximation of global illumination No direction: independent of light position, object orientation, observer s position/orientation object 3 object 4 object 2 constant object 1 Ambient = I x K a R.W. Lindeman - WPI Dept. of Computer Science 9 Diffuse Light Contribution Diffuse light: The illumination that a surface receives from a light source that reflects equally in all direction Eye point does not matter R.W. Lindeman - WPI Dept. of Computer Science 10 5

Diffuse Light Calculation Need to decide how much light the object point receives from the light source Based on Lambert s Law Receive more light Receive less light R.W. Lindeman - WPI Dept. of Computer Science 11 Diffuse Light Calculation (cont.) Lambert s law: the radiant energy D that a small surface patch receives from a light source is: Diffuse = K d x I x cos(θ) K d : diffuse reflection coefficient I: light intensity θ: angle between the light vector and the surface normal light vector (vector from object to light) θ N : surface normal R.W. Lindeman - WPI Dept. of Computer Science 12 6

Diffuse Light Examples I = 1.0 K d = 0.0 0.2 0.4 0.6 0.8 1.0 R.W. Lindeman - WPI Dept. of Computer Science 13 Specular Light Contribution The bright spot on the object The result of total reflection of the incident light in a concentrate region Sees no specular Sees lots of specular R.W. Lindeman - WPI Dept. of Computer Science 14 7

Specular Light Calculation How much reflection you can see depends on where you are But for non-perfect surface you will still see specular highlight when you move a little bit away from the ideal reflection direction Φ is deviation of view angle from mirror direction When φ is small, you see more specular highlight R.W. Lindeman - WPI Dept. of Computer Science 15 Specular Light Calculation (cont.) Phong lighting model Not Phong shading model The effect of 'f' in the Phong model Specular = K s x I x cos f (φ) f = 10 f = 90 f = 30 f = 270 R.W. Lindeman - WPI Dept. of Computer Science 16 8

Specular Light Examples K s = 0.25 K s = 0.5 K s = 0.75 f = 3 f = 6 f = 9 f = 25 f = 200 R.W. Lindeman - WPI Dept. of Computer Science 17 Putting It All Together Illumination from a light Illum = ambient + diffuse + specular = K a x I + K d x I x cos(θ) + K s x I x cos f (φ) If there are N lights Total illumination for a point P = Σ (Illum) Some more terms to be added (in OpenGL) Self emission Global ambient Light distance attenuation and spot light effect R.W. Lindeman - WPI Dept. of Computer Science 18 9

Putting It All Together (cont.) Illum = ambient + diffuse + specular R.W. Lindeman - WPI Dept. of Computer Science 19 Ambient Lighting Example R.W. Lindeman - WPI Dept. of Computer Science 20 10

Diffuse Lighting Example R.W. Lindeman - WPI Dept. of Computer Science 21 Specular Lighting Example R.W. Lindeman - WPI Dept. of Computer Science 22 11

Adding Color Sometimes light or surfaces are colored Treat R,G and B components separately i.e., can specify different RGB values for either light or material Illumination equation goes from Illum = ambient + diffuse + specular To: = K a x I + K d x I x cos(θ) + K s x I x cos f (φ) Illum r = K ar x I r + K dr x I r x cos(θ) + K sr x I r x cos f (φ) Illum g = K ag x I g + K dg x I g x cos(θ) + K sg x I g x cos f (φ) Illum b = K ab x I b + K db x I b x cos(θ) + K sb x I b x cos f (φ) R.W. Lindeman - WPI Dept. of Computer Science 23 Adding Color (cont.) Material Ambient Diffuse Specular Exponent f K ar, K ag, K ab K dr, K dg, K db K sr, K sg, K sb Black plastic Brass Polished Silver 0.0 0.0 0.0 0.329412 0.223529 0.027451 0.23125 0.23125 0.23125 0.01 0.01 0.01 0.780392 0.568627 0.113725 0.2775 0.2775 0.2775 0.5 0.5 0.5 0.992157 0.941176 0.807843 0.773911 0.773911 0.773911 (excerpt from Hill, Fig. 8.17) 32 27.8974 89.6 R.W. Lindeman - WPI Dept. of Computer Science 24 12

Lighting in OpenGL Adopt Phong lighting model Ambient + Specular + Diffuse lights Lighting is computed at vertices Interpolate across surface (Gouraud/smooth shading) Setting up OpenGL lighting Light properties Enable/disable lighting Surface material properties Provide correct surface normals Set light model properties R.W. Lindeman - WPI Dept. of Computer Science 25 Light Properties Properties Colors / Position and type / attenuation gllightfv( light, property, value ) 1 2 3 (1) Constant: specify which light you want to set the property for e.g., GL_LIGHT0, GL_LIGHT1, GL_LIGHT2... you can create multiple lights (OpenGL allows at least 8 lights) (2) Constant: specify which light property you want to set e.g., GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_POSITION (check the red book, or the Web, for more) (3) The value you want to set to the property R.W. Lindeman - WPI Dept. of Computer Science 26 13

Property Example Define colors and position a light GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat light_position[] = { 0.0, 0.0, 1.0, 1.0 }; Colors Position gllightfv( GL_LIGHT0, GL_AMBIENT, light_ambient ); gllightfv( GL_LIGHT0, GL_DIFFUSE, light_diffuse ); gllightfv( GL_LIGHT0, GL_SPECULAR, light_specular ); gllightfv( GL_LIGHT0, GL_POSITION, light_position ); What if I set Position to (0, 0, 1, 0)? R.W. Lindeman - WPI Dept. of Computer Science 27 Types of Lights OpenGL supports two types of lights Local light (point light) Infinite light (directional light) Determined by the light positions you provide w = 0: Infinite light source w!= 0:Point light Position = (x/w, y/w, z/w) GLfloat light_position[] = { x, y, z, w }; gllightfv( GL_LIGHT0, GL_POSITION, light_position ); R.W. Lindeman - WPI Dept. of Computer Science 28 14

Turning on the Lights Turn on/off the power (for all the lights) glenable( GL_LIGHTING ); gldisable( GL_LIGHTING ); Turn on each light switch glenable( GL_LIGHTn ) (n = 0, 1, 2,...) R.W. Lindeman - WPI Dept. of Computer Science 29 Controlling Light Position Modelview matrix affects a light s position Two options Option a: Treat light like vertex Do pushmatrix, translate, rotate,... gllightfv POSITION, popmatrix Then call glulookat Light moves independently of camera Option b: Load identity matrix in modelview matrix Call gllightfv then call glulookat Light appears at the eye (like a miner s lamp) R.W. Lindeman - WPI Dept. of Computer Science 30 15

Material Properties The color and surface properties of a material (dull, shiny, etc.) How much the surface reflects the incident lights ambient/diffuse/specular reflection coefficients glmaterialfv( face, property, value ); face: Material property for which side of the polygon (e.g., GL_FRONT, GL_BACK, GL_FRONT_AND_BACK) property: What material property you want to set (e.g., GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_SHININESS, GL_EMISSION, etc.) value: The value to assign to the property R.W. Lindeman - WPI Dept. of Computer Science 31 Material Example Define ambient/diffuse/specular reflection and shininess GLfloat mat_amb_diff[] = { 1.0, 0.5, 0.8, 1.0 }; GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat shininess[] = { 5.0 }; 128 Range: dull 0 very shiny glmaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff ); glmaterialfv( GL_FRONT, GL_SPECULAR, mat_specular ); glmaterialfv( GL_FRONT, GL_SHININESS, shininess ); Refl. coeff. R.W. Lindeman - WPI Dept. of Computer Science 32 16

Surface Normals Correct normals are essential for correct lighting Associate a normal with each vertex glbegin( ); glnormal3f( u, v, n ); glvertex3f( x, y, z );... glend( ); All normals must be specified in unit length More on why in the next slide set! R.W. Lindeman - WPI Dept. of Computer Science 33 Colored Wireframe R.W. Lindeman - WPI Dept. of Computer Science 34 17

Colored Hidden-Line Removal R.W. Lindeman - WPI Dept. of Computer Science 35 Ambient Term Only R.W. Lindeman - WPI Dept. of Computer Science 36 18

Flat Shading R.W. Lindeman - WPI Dept. of Computer Science 37 Diffuse Shading + Interp. Normals R.W. Lindeman - WPI Dept. of Computer Science 38 19

Gouraud Shading R.W. Lindeman - WPI Dept. of Computer Science 39 Ambient + Diffuse + Specular R.W. Lindeman - WPI Dept. of Computer Science 40 20

Ambient + Diffuse + Specular + Interpolated Normals R.W. Lindeman - WPI Dept. of Computer Science 41 Radiosity R.W. Lindeman - WPI Dept. of Computer Science 42 21

Texture Mapping R.W. Lindeman - WPI Dept. of Computer Science 43 Texture Mapping + Ray Tracing R.W. Lindeman - WPI Dept. of Computer Science 44 22