CS418 Computer Graphics John C. Hart

Slides:



Advertisements
Similar presentations
2 COEN Computer Graphics I Evening’s Goals n Discuss the fundamentals of lighting in computer graphics n Analyze OpenGL’s lighting model n Show.
Advertisements

Computer Graphics I, Fall 2010 Shading II.
CS 480/680 Computer Graphics Shading 2 Dr. Frederick C Harris, Jr.
CSPC 352: Computer Graphics
Virtual Realism LIGHTING AND SHADING. Lighting & Shading Approximate physical reality Ray tracing: Follow light rays through a scene Accurate, but expensive.
1 MAE152 Computer Graphics for Scientists and Engineers Lighting in OpenGL.
Illumination and Shading
Computer Graphics - Class 10
Shading in OpenGL CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
CS 4731: Computer Graphics Lecture 16: Illumination Models Part 2 Emmanuel Agu.
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 Lecture 10 Lighting in OpenGL. 2 Sources of light GLfloat myLightPosition[] = {3.0, 6.0, 5.0, 1.0}; GLLightfv(GL_LIGHT0, GL_POSITION, myLightPosition);
1 CSC 830 Computer Graphics Lecture 5 Shading Course Note Credit: Some of slides are extracted from the course notes of prof. Mathieu Desburn (USC) and.
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
CS425 OpenGL Materials. What Color Is It? green & blue absorbed white light Looks red.
Illumination and Shading
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Computer Graphics Lighting.
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
Illumination & Reflectance Dr. Amy Zhang. Outline 2  Illumination and Reflectance  The Phong Reflectance Model  Shading in OpenGL.
Shading in OpenGL.
1 Chapter 6 Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
19/17/ :25 UML Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic.
Shading and Illumination. OpenGL Shading Without ShadingWith Shading.
Computer Graphics I, Fall 2010 Shading in OpenGL.
Programming for Virtual Reality Applications Projection in OpenGL Lighting and Shading Lecture 17.
08 |Lighting and Shading Eriq Muhammad Adams J |
CG1 Labs Wei Li. Back Face Culling // enable back-face culling glEnable( GL_CULL_FACE ); // orientation of front-facing polygons glFrontFace( GL_CCW );
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Transformational Geometry CS418 Computer Graphics John C. Hart.
Viewing CS418 Computer Graphics John C. Hart. Graphics Pipeline Homogeneous Divide Model Coords Model Xform World Coords Viewing Xform Still Clip Coords.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading Part II.
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
OpenGL Lighting Jian-Liang Lin 2002 Hidden-Surface Removal -1 Original Code: while (1) { get_viewing_point_from_mouse_position(); glClear(GL_COLOR_BUFFER_BIT);
11/04/04© University of Wisconsin, CS559 Fall 2004 Last Time Visibility –Z-Buffer and transparency –A-buffer –Area subdivision –BSP Trees –Exact Cell-Portal.
COMPUTER GRAPHICS Hochiminh city University of Technology Faculty of Computer Science and Engineering CHAPTER 6: Lighting and Shading.
3-D Transformational Geometry CS418 Computer Graphics John C. Hart.
Lighting Dave Shreiner. 2 Lighting Principles Lighting simulates how objects reflect light Lighting simulates how objects reflect light material composition.
Ta: Ryan Freedman Sushma Kini Chi Zhou.  Pipeline  Clipping  Transformation, homogeneous coordinates  Lighting  Perspective  Viewing.
Lighting and Reflection Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS559: Computer Graphics Lecture 16: Shading and OpenGL Li Zhang Spring 2008.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Illumination Models and Surface-Rendering Methods CEng 477 Introduction to Computer Graphics.
1 Dr. Scott Schaefer Lighting. 2/49 Lighting/Illumination Color is a function of how light reflects from surfaces to the eye Global illumination accounts.
Graphics Graphics Korea University kucg.korea.ac.kr 1 Lights & Material 고려대학교 컴퓨터 그래픽스 연구실.
Unit-4 Geometric Objects and Transformations- I
Implementing Phong Lighting
© University of Wisconsin, CS559 Spring 2004
Shading To determine the correct shades of color on the surface of graphical objects.
Lecture 16: Shading and OpenGL Li Zhang Spring 2008
Rendering Pipeline Aaron Bloomfield CS 445: Introduction to Graphics
A complete pipeline for 3D graphics
Illumination and Shading
@ 2017 by Jim X. Chen George Mason University
Prof. Harriet Fell Spring 2007 Lecture 26 – March 19, 2007
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2016
School of Computer Science
Shading II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive Computer.
Prof. Harriet Fell Fall 2011 Lecture 24 – November 2, 2011
Shading in OpenGL Ed Angel
Lighting Glenn G. Chappell
Lighting Phong's Lighting Model normals
Illumination and Shading
Lighting and Materials
CS5500 Computer Graphics April 10, 2006.
ייצוג בעולם 3D ייצוג מצולעים (פוליגונים) צלע קודקוד צלעe0 : {v1,v2}
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
CS G140 Graduate Computer Graphics
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
Shading II Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

CS418 Computer Graphics John C. Hart Lighting CS418 Computer Graphics John C. Hart

Perspective Distortion Graphics Pipeline Model Coords Model Xform World Coords Viewing Xform Viewing Coords Perspective Distortion Still Clip Coords. Clipping Clip Coords. Homogeneous Divide Window Coordinates Window to Viewport Viewport Coordinates

Makes viewed, projected, filled polygon meshes look more realistic by approximating how light would bounces off their surface Lighting

Local Coordinates v – view vector: v = (e – x)/||e – x|| l – light vector: l = (lp – x)/||lp – x|| n – normal vector: n = (x1-x0)(x2-x0)/||(x1-x0)(x2-x0)|| lp n l e v Li x2 Lo x x0 x1

Lambertian Reflection q Lo = Li kd cd cos q = Li kd cd nl cd = (Rd,Gd,Bd): color surface diffusely reflects kd = % of light reflected (rest is absorbed) view independent

Specular Reflection n r l q q s = (nl)n – l r = l + 2s diffuse diffuse + specular n r l q q s = (nl)n – l r = l + 2s = l + 2(nl)n – 2l = 2(nl)n – l l n r s v f Lo = Li ks cs cosn f = Li ks cs (vr) n cs = (Rs,Gs,Bs): gleem reflection color ks = % of light reflected (rest is absorbed) view dependent

The Phong Lighting Model Monochromatic Lo = ka La + Li (kd nl + ks (vr)n ) Tristimulus (RGB) color model Lo(R) = ka(R) La(R) + Li(R) (kd(R) nl + ks(R) (vr)n ) Lo(G) = ka(G) La(G) + Li(G) (kd(G) nl + ks(G) (vr)n ) Lo(B) = ka(B) La(B) + Li(B) (kd(B) nl + ks(B) (vr)n ) Multiple light sources Lo = ka La + Li(1) (kd nl(1) + ks (vr(1))n ) + Li(2) (kd nl(2) + ks (vr(2))n ) + …

OpenGL Lighting Phong: Lo = ka La + Li (kd nl + ks (vr)n ) OpenGL: Lo = ka L#a + L#d kd nl + L#s ks (vr)n GLfloat lpos[] = {1.0,10.0,-1.0,1.0}; GLfloat La[] = {1.0,1.0,1.0,1.0}; GLfloat Lid[] = {1.0,1.0,1.0,1.0}; GLfloat Lis[] = {1.0,1.0,1.0,1.0}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, lpos); glLightfv(GL_LIGHT0, GL_AMBIENT, La); glLightfv(GL_LIGHT0, GL_DIFFUSE, Lid); glLightfv(GL_LIGHT0, GL_SPECULAR, Lis); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); glLightModeli(GL_LIGHT_MODEL_TWO_SIDED, GL_TRUE); GLfloat ka[] = {1.0,0.0,0.0,1.0}; GLfloat kd[] = {1.0,0.0,0.0,1.0}; GLfloat ks[] = {1.0,1.0,1.0,1.0}; #define BOTHSIDES GL_FRONT_AND_BACK glMaterialfv(BOTHSIDES, GL_AMBIENT, ka); glMaterialfv(BOTHSIDES, GL_DIFFUSE, kd); glMaterialfv(BOTHSIDES, GL_SPECULAR, ks); glMaterialf(BOTHSIDES,GL_SHININESS,50.0);

Lighting Coordinates Lights specified in model (world) coordinates Rotating object: gluLookat(…,0,0,0,…); glLightfv(…,…,lpos); glRotatef(angle,0,1,0); glutSolidTeapot(1.0); Rotating view: glLightfv(...,...,lpos); Lights specified in model (world) coordinates OpenGL computes lighting in viewing (eye) coordinates Light position specification treated as a vertex position Light position transformed by current ModelView matrix W2V P Lookat Rotate

glEnable(GL_NORMALIZE); Surface Normals Can be defined per face or per vertex Per face normal of a ccw face n = (x1 – x0)(x2 – x0) Needs to be unitized before lighting Automatically normalized by glEnable(GL_NORMALIZE); Per vertex normal Sum of normals of adjacent faces Needs to be normalized glNormal3f(nx,ny,nz) glBegin(GL_POLYGON); glVertex3f(x0,y0,z0); glVertex3f(x1,y1,z1); glVertex3f(x2,y2,z2); glEnd(); glBegin(GL_POLYGON); glNormal3f(nx0,ny0,nz0) glVertex3f(x0,y0,z0); glNormal3f(nx1,ny1,nz1) glVertex3f(x1,y1,z1); glNormal3f(nx2,ny2,nz2) glVertex3f(x2,y2,z2); glEnd();

Transforming Normals First order neighborhood of a point on a surface described by a tangent plane Plane equation: Ax + By + Cz + D = 0 Plane normal: (A,B,C) If ||(A,B,C)|| = 1 Then D is distance from plane to origin

Transforming Normals Plane equation: n x = 0 n is a row vector x is a column vector Let M be an affine transformation Transformed geometry x’ = M x New normal n’ such that n’ x’ = 0 n’ M x = 0 n x = 0 n’ M = n n’ = n M -1 Needs to be normalized n n’

Attenuation Less light from sources far away Sphere Area = 4 p r2 Less light from sources far away Should be inverse square fall-off (1/d2) Looks better with inverse (1/d) Inverse more expensive to compute glLightf(GL_LIGHTi, GL_CONSTANT_ATTENUATION, a); glLightf(GL_LIGHTi, GL_LINEAR_ATTENUATION, b); glLightf(GL_LIGHTi, GL_QUADRATIC_ATTENUATION, c); d = ||x – lpos[i]||; att = 1.0/(a + b*d + c*d*d); (light at x) = att*(light at source)