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

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

Illumination and Shading

Illumination and Shading

CS Computer Graphics: Illumination and Shading I

CS Computer Graphics: Illumination and Shading I

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

Shading and Illumination

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

Illumination & Shading I

5.2 Shading in OpenGL

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

Shading , Fall 2004 Nancy Pollard Mark Tomczak

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

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

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

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

CS Illumination and Shading. Slide 1

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 and Shading

OpenGL Lighting Computer Graphics Spring Frank Palermo

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

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

Lighting. CSC 7443: Scientific Information Visualization

Lighting/Shading III. Week 7, Wed Mar 3

CS5620 Intro to Computer Graphics

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

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

CS Surface Rendering

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

Illumination & Shading: Part 1

CEng 477 Introduction to Computer Graphics Fall

Projections and Hardware Rendering. Brian Curless CSE 557 Fall 2014

Computer Graphics. Illumination and Shading

Illumination and Shading ECE 567

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

Shading. CSE 457 Winter 2015

INF3320 Computer Graphics and Discrete Geometry

Shading. Brian Curless CSE 457 Spring 2015

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

Light Sources. Spotlight model

How do we draw a picture?

Light Transport Baoquan Chen 2017

Pipeline Operations. CS 4620 Lecture 10

Illumination Models & Shading

CPSC 314 LIGHTING AND SHADING

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

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

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

Illumination and Shading

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

Illumination and Shading

CPSC / Illumination and Shading

Lighting/Shading II. Week 7, Mon Mar 1

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

LIGHTING AND SHADING

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

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

w Foley, Section16.1 Reading

Reflection and Shading

Visualisatie BMT. Rendering. Arjan Kok

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

Computer Graphics. Illumination and Shading

Three-Dimensional Graphics V. Guoying Zhao 1 / 55

Shading. Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller/Fuhrmann

Why we need shading?

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

CS 325 Computer Graphics

Sung-Eui Yoon ( 윤성의 )

9. Illumination and Shading

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

Illumination Models and Surface-Rendering Methods. Chapter 10

Pipeline Operations. CS 4620 Lecture 14

Lecture 4 Advanced Computer Graphics (CS & SE )

Painter s HSR Algorithm

CS 130 Final. Fall 2015

Illumination & Shading

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

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

Surface Rendering Methods

Virtual Reality for Human Computer Interaction

Illumination and Shading with GLSL/WebGL

Shading Algorithms. Ron Goldman Department of Computer Science Rice University

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

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

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

Mach band effect. The Mach band effect increases the visual unpleasant representation of curved surface using flat shading.

CS770/870 Spring 2017 Color and Shading

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

Chapter 7 - Light, Materials, Appearance

7: Rendering (1) COMP Computer Graphics and Image Processing. Local illumination model. Global illumination model. Direct Direct.

Shading/Texturing. Dr. Scott Schaefer


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

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

Outline. Other Graphics Technology. OpenGL Background and History. Platform Specifics. The Drawing Process

Graphics and Computation Introduction to OpenGL

Illumination and Shading

Transcription:

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

Recall: Setting Light Property 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}; 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); Position colors What if I set Position to (0,0,1,0)?

Recall: Setting 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}; refl. coeff. GLfloat shininess[] = {5.0}; (range: dull 0 very shiny 128) 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);

Recall: Calculating Color at Vertices Illumination from a light: Illum = ambient + diffuse + specular = Ka x I + Kd x I x (cos θ) + Ks x I x cos(φ) If there are N lights Total illumination for a point P = Σ (Illum) 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 To: n Illum_r = Kar x Ir + Kdr x Ir x (cos θ) + Ksr x Ir x cos(φ) n Illum_g = Kag x Ig + Kdg x Ig x (cos θ) + Ksg x Ig x cos(φ) n Illum_b = Kab x Ib + Kdb x Ib x (cos θ) + Ksb x Ib x cos(φ) n

Recall: Calculating Color at Vertices Illum = ambient + diffuse + specular n = Ka x I + Kd x I x (cos θ) + Ks x I x cos(φ) (cos θ) and cos(φ) are calculated as dot products of Light vector L, Normal N, and Mirror direction vector R L θ N V φ R p To give Illum = Ka x I + Kd x I x (N.L) + Ks x I x (R.V) n

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

Lighting revisit Light calculation so far is at vertices Pixel may not fall right on vertex Shading: calculates color to set interior pixel to Where are lighting/shading performed in the pipeline? v1, m1 modeling and viewing per vertex lighting projection v2, m2 v3, m3 Rasterization texturing shading viewport mapping interpolate vertex colors clipping Display

Example Shading Function (Pg. 432 of Hill) for(int y = y bott ; y < y top ; y++) { } find x left and x right for(int x = x left ; x < x right ; x++) { find the color c for this pixel put c into the pixel at (x, y) } ytop color4 y4 color3 Scans pixels, row by row, calculating color for each pixel ys ybott xleft color1 color2 xright

Polygon shading model Flat shading - compute lighting once and assign the color to the whole (mesh) polygon

Flat shading Only use one vertex normaland material property to compute the color for the polygon Benefit: fast to compute Used when: Polygon is small enough Light source is far away (why?) 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

Smooth shading Fix the mach band effect remove edge discontinuity Compute lighting for more points on each face Flat shading Smooth shading

Smooth shading Two popular methods: Gouraud shading (used by OpenGL) Phong shading (better specular highlight, not in OpenGL)

Gouraud Shading 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

Gouraud Shading Per-vertex lighting calculation Normal is needed for each vertex Per-vertex normal can be computed by averaging the adjust face normals n1 n n2 n3 n4 n = (n1 + n2 + n3 + n4) / 4.0

Gouraud Shading Compute vertex illumination (color) before the projection transformation Shade interior pixels: color interpolation (normals are not needed) C1 Ca = lerp(c1, C2) Cb = lerp(c1, C3) for all scanlines C2 C3 Lerp(Ca, Cb) * lerp: linear interpolation

Gouraud Shading Linear interpolation v1 a x b v2 x = b / (a+b) * v1 + a/(a+b) * v2 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 Function (Pg. 433 of Hill) for(int y = y bott ; y < y top ; y++) // for each scan line { find x left and x right } find color left and color right color inc = (color right color left )/ (x right x left ) for(int x = x left, c = color left ; x < x right ; x++, c+ = color inc ) { put c into the pixel at (x, y) }

Gouraud Shading Problem Lighting in the polygon interior can be inaccurate

Phong Shading Instead of interpolation, we calculate lighting for each pixel inside the polygon (per pixel lighting) Need normals for all the pixels not provided by user Phong shading algorithm interpolates the normals and compute lighting during rasterization (need to map the normal back to world or eye space though)

Phong Shading Normal interpolation n1 na = lerp(n1, n2) nb = lerp(n1, n3) n2 lerp(na, nb) Slow not supported by OpenGL and most graphics hardware n3

References Hill, chapter 8