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

Similar documents
Illumination and Shading

Illumination and Shading

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

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

Illumination & Shading I

Shading and Illumination

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

Lighting. CSC 7443: Scientific Information Visualization

INF3320 Computer Graphics and Discrete Geometry

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

Computer Graphics. Illumination and Shading

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

Illumination and Shading ECE 567

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

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

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

5.2 Shading in OpenGL

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

Shading , Fall 2004 Nancy Pollard Mark Tomczak

CS 148, Summer 2012 Introduction to Computer Graphics and Imaging

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

CEng 477 Introduction to Computer Graphics Fall

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?

Why we need shading?

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

CS Surface Rendering

Illumination and Shading

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

Surface Rendering Methods

Lecture 4 Advanced Computer Graphics (CS & SE )

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

Illumination & Shading: Part 1

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

Light Transport Baoquan Chen 2017

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

Virtual Reality for Human Computer Interaction

LIGHTING AND SHADING

CS5620 Intro to Computer Graphics

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

Computer Graphics (CS 4731) Lecture 18: Lighting, Shading and Materials (Part 3)

Illumination and Shading

Lighting/Shading III. Week 7, Wed Mar 3

Illumination Models & Shading

Reflection and Shading

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

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

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

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

Graphics and Visualization

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

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

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

Sung-Eui Yoon ( 윤성의 )

CS Illumination and Shading. Slide 1

CPSC / Illumination and Shading

Light Sources. Spotlight model

Display Issues Week 5

Computer Graphics. Illumination and Shading

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

OpenGL Lighting Computer Graphics Spring Frank Palermo

Lights, Colour and Materials In OpenGL

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

Visualisatie BMT. Rendering. Arjan Kok

Shading. Brian Curless CSE 457 Spring 2015

CPSC 314 LIGHTING AND SHADING

Shading. CSE 457 Winter 2015

Comp 410/510 Computer Graphics. Spring Shading

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

Illumination Models and Surface-Rendering Methods. Chapter 10

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

Shading I Computer Graphics I, Fall 2008

w Foley, Section16.1 Reading

Lighting Models. CS116B Chris Pollett Mar 21, 2004.

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

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

Local Illumination physics. Law of reflection and Snell s law of refraction

Illumination & Shading

Given: scene specification (object positions, optical properties p of the surface, viewer position, viewing direction, )

Illumination & Shading

Lighting/Shading II. Week 7, Mon Mar 1

Lecture 15: Shading-I. CITS3003 Graphics & Animation

Realtime 3D Computer Graphics & Virtual Reality. Shading and Color. Introduction to Lighting and Shading

Virtual Reality for Human Computer Interaction

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

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

How do we draw a picture?

Models and Architectures

CS 4600 Fall Utah School of Computing

Phong Lighting & Materials. Some slides modified from: David Kabala Others from: Andries Van Damm, Brown Univ.

Introduction Rasterization Z-buffering Shading. Graphics 2012/2013, 4th quarter. Lecture 09: graphics pipeline (rasterization and shading)

Understand how real-world lighting conditions are approximated by OpenGL

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

Lighting and Shading II. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

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

Illumination and Shading

CSE 681 Illumination and Phong Shading

University of Victoria CSC 305 Shading. Brian Wyvill 2016

Transcription:

Illumination and Shading Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL computes illumination at vertices illumination Shading Apply the lighting model at a set of points across the entire surface Shading Illumination Model The governing principles for computing the illumination A illumination model usually considers: Light attributes (light intensity, color, position, direction, shape) Object surface attributes (color, reflectivity, transparency, etc) Interaction among lights and objects (object orientation) Interaction between objects and eye (viewing dir.) 1

Illumination Calculation Illumination Models Local illumination: only consider the light, the observer position, and the object material properties Global illumination: take into account the interaction of light from all the surfaces in the scene object 4 θ object 3 object 2 object 1 Example: OpenGL Example: Ray Tracing (CIS681) Basic Light Sources Simple local illumination Point light Spot light sun Directional light Light intensity can be independent or dependent of the distance between object and the light source The model used by OpenGL consider three types of light contribution to compute the final illumination of an object Ambient Diffuse Specular Final illumination of a point (vertex) = ambient + diffuse + specular 2

Ambient light contribution Ambient lighting example Ambient light (background light): the light that is scattered by the environment A very simple approximation of global illumination object 4 object 3 object 2 object 1 Independent of the light position,object orientation, observer s position or orientation ambient light has no direction (Radiosity is the calculation of ambient light) Ambient light calculation Diffuse light contribution Each light source has an ambient light contribution (I a ) Different objects can reflect different amounts of ambient (different ambient reflection coefficient Ka, 0 <= K a <= 1) So the amount of ambient light that can be seen from an object is: Ambient = I a * K a Diffuse light: The illumination that a surface receives from a light source and reflects equally in all direction It does not matter where the eye is 3

Diffuse lighting example Diffuse light calculation Need to decide how much light the object point receive from the light source based on Lambert s Law Receive more light Receive less light Diffuse light calculation (2) Diffuse light calculation (3) Lambert s law: the radiant energy D that a small surface patch receives from a light source is: D = I * cos (θ) I: light intensity θ: angle between the light vector and the surface normal Like the ambient light case, different objects can reflect different amount of diffuse light (different diffuse reflection coefficient K d, 0 <= K d <= 1)) So, the amount of diffuse light that can be seen is: light vector (vector from object to light) θ N : surface normal θ Diffuse = K d * I * cos (θ) N L θ cos(θ) = N.L 4

Specular light contribution Specular light example The bright spot on the object The result of total reflection of the incident light in a concentrate region See nothing! Specular light calculation Specular light calculation (2) How much reflection you can see depends on where you are Phong lighting model specular = K s * I * cos n (φ) θ? p φ The only position the eye can see specular from P if the object has an ideal reflection surface But for a non-perfect surface you will still see specular highlight when you move a little bit away from the idea reflection direction When φ is small, you see more specular highlight K s : specular reflection coefficient N: surface normal at P I: light intensity φ: angle between V and R cos(φ): the larger is n, the smaller n is the cos value cos(θ) = R.V L N θ θ p φ R V 5

Specular light calculation (3) The effect of n in the phong model n = 10 n = 90 Put it all together Illumination from a light: Illum = ambient + diffuse + specular n = K a * I + K d * I * (N.L) + K s * I * (R.V) n If there are N lights or n = 30 n = 270 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 (N.H) Lighting in OpenGL Adopt Phong lighting model (specular) plus diffuse and ambient lights Lighting is computed at vertices Interpolate t across surface (Gouraud/smooth shading) OR Use a constant illumination (get it from one of the vertices) Setting up OpenGL Lighting: Light Properties Enable/Disable lighting Surface material properties Provide correct surface normals Light model properties Light Properties Properties: Colors / Position and type / attenuation gllightfv(light, g g property, p value) 1 2 3 (1) constant: specify which light you want to set the property example: 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 the value example: GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_POSITION (check the red book for more) (3) The value you want to set to the property 6

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}; colors GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat light_position[] = {0.0, 0.0, 1.0, 1.0}; 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 the Position to (0,0,1,0)? 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 (faster) 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); Turning on the lights Turn on the power (for all the lights) glenable(gl_lighting); gldisable(gl_lighting); Flip each light s switch glenable(gl_lightn) (n = 0,1,2, ) Controlling light position Modelview matrix affects a light s position You can specify the position relative to: Eye space: the highlight g remains in the same position relative to the eye call gllightfv() before glulookat() World space: a light s position/direction appears fixed in the scene Call gllightfv() after glulookat() See Nat Robin s Demo http://www.xmission.com/~nate/tutors.html 7

Material Properties The color and surface properties of a material (dull, shiny, etc) How much the surface reflects the incident lights (ambient/diffuse/specular reflecetion coefficients) glmaterialfv(face, property, value) Face: material property for which face (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 you can to assign to the property Material Example Define ambient/diffuse/specular reflection and shininess GLfloat mat_amb_diff[] = {1.0, 0.5, 0.8, 1.0}; refl. coefficient GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat shininess[] = {5.0}; (range: dull 0 very shiny128) glmaterialfv(gl_front_and_back, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff); glmaterialfv(gl_front, GL_SPECULAR, mat_speacular); glmaterialfv(gl_front, GL_SHININESS, shininess); Global light properties gllightmodelfv(property, value) Enable two sided lighting property = GL_LIGHT_MODEL_TWO_SIDE value = GL_TRUE (GL_FALSE if you don t want two sided lighting) Global ambient color Property = GL_LIGHT_MODEL_AMBIENT Value = (red, green, blue, 1.0); Check the red book for others Surface Normals Correct normals are essential for correct lighting Associate a normal to each vertex glbegin( ) glnormal3f(x,y,z) glvertex3f(x,y,z) glend() The normals you provide need to have a unit length You can use glenable(gl_normalize) to have OpenGL normalize all the normals 8

Lighting revisit Where is lighting performed in the graphics pipeline? Polygon shading model Flat shading compute lighting once and assign the color to the whole polygon v1, m1 v2, m2 v3, m3 modeling and viewing per vertex lighting projection Rasterization texturing shading viewport mapping interpolate vertex colors clipping Display Flat shading Only use one vertex (usually the first one) normal and material property to compute the color for the polygon Benefit: fast to compute It is used when: The polygon is small enough The light source is far away (why?) The eye is very far away (why?) OpenGL command: glshademodel(gl_flat) Mach Band Effect Flat shading suffers from mach band effect Mach band effect human eyes accentuate the discontinuity at the boundary perceived intensity Side view of a polygonal surface 9

Smooth shading Reduce the mach band effect remove value discontinuity Compute lighting for more points on each face Smooth shading Two popular methods: Gouraud shading (used by OpenGL) Phong shading (better specular highlight, not supported by OpenGL) Flat shading smooth shading Gouraud Shading (1) Gouraud Shading (2) The smooth shading algorithm used in OpenGL glshademodel(gl_smooth) Lighting is calculated for each of the polygon vertices Colors are interpolated for interior pixels Per-vertex lighting calculation Normal is needed for each vertex Per-vertex normal can be computed by averaging the adjust face normals n1 n3 n n4 n2 n = (n1 + n2 + n3 + n4) / 4.0 10

Gouraud Shading (3) Gouraud Shading (4) Compute vertex illumination (color) before the projection transformation Shade interior pixels: color interpolation (normals are not needed) C2 C1 Ca = lerp(c1, C2) Cb = lerp(c1, C3) C3 Lerp(Ca, Cb) for all scanlines * lerp: linear interpolation Linear interpolation v1 a x b v2 x = a/(a+b)*v2+b/(a+b)*v1 + b/(a+b) * v1 Interpolate triangle color: use y distance to interpolate the two end points in the scanline, and use x distance to interpolate interior pixel colors Gouraud Shading Problem Lighting in the polygon interior can be inaccurate Gouraud Shading Problem Lighting in the polygon interior can be inaccurate 11

Phong Shading Instead of color interpolation, we calculate lighting for each pixel inside the polygon (per pixel lighting) We need to have normals for all the pixels not provided by the user Phong shading algorithm interpolates the normals and compute lighting during rasterization (need to map the normal back to world or eye space though - WHY?) Phong Shading (2) Normal interpolation na = lerp(n1, n2) n2 lerp(na, nb) n1 nb = lerp(n1, n3) Slow not supported by OpenGL and most of the graphics hardware n3 12