Shading To determine the correct shades of color on the surface of graphical objects.

Slides:



Advertisements
Similar presentations
CS 480/680 Computer Graphics Shading 2 Dr. Frederick C Harris, Jr.
Advertisements

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.
Illumination and Shading
Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Shading I.
University of New Mexico
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.
Objectives Learn to shade objects so their images appear three- dimensional Learn to shade objects so their images appear three- dimensional Introduce.
CS5500 Computer Graphics March 26, Shading Reference: Ed Angel’s book.
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.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Chapter 6: Shading Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Illumination & Reflectance Dr. Amy Zhang. Outline 2  Illumination and Reflectance  The Phong Reflectance Model  Shading in OpenGL.
Shading in OpenGL.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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 03/19/2003. Lighting Principles Lighting based on how objects reflect light –Surface characteristics –Light color and direction –Global lighting.
Shading and Illumination. OpenGL Shading Without ShadingWith Shading.
Computer Graphics I, Fall 2010 Shading in OpenGL.
Lecture 9: Lighting and Shading 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271
Lecture 14 Shading models 1.Shading Constant Shading (to be implemented) Gouraud Shading Phong Shading 2.Light and shading with OpenGL 1.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
CG Summary: OpenGL Shading andTextures Angel, Chapters 5, 7; “Red Book” slides from AW, red book, etc. CSCI 6360/4360.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
COMPUTER GRAPHICS Hochiminh city University of Technology Faculty of Computer Science and Engineering CHAPTER 6: Lighting and Shading.
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program.
Lecture Fall 2001 Illumination and Shading in OpenGL Light Sources Empirical Illumination Shading Transforming Normals Tong-Yee Lee.
Where We Stand So far we know how to: –Transform between spaces –Rasterize –Decide what’s in front Next –Deciding its intensity and color.
Lighting and Shading Part 2. Global Ambient Light There are at least 8 OpenGL lights and 1 Global Ambient Setting the Global Ambient globalAmbient[] =
OpenGL Shading. 2 Objectives Learn to shade objects so their images appear three-dimensional Introduce the types of light-material interactions Build.
Lighting and Reflection Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Computer Graphics Lecture 25 Fasih ur Rehman. Last Class Shading.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 55 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 55 Computer Graphics Three-Dimensional Graphics V.
Implementing Phong Lighting
© University of Wisconsin, CS559 Spring 2004
Illumination and Shading
Unit-7 Lighting and Shading
Shading II Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive Computer.
Vectors, Normals, & Shading
Shading in OpenGL Ed Angel
CSC461: Lecture 24 Lighting and Shading in OpenGL
Lighting Phong's Lighting Model normals
CSE 470 Introduction to Computer Graphics Arizona State University
Illumination and Shading
Fundamentals of Computer Graphics Part 6 Shading
Lighting and Materials
Lighting – Light Sources
Introduction to Computer Graphics with WebGL
CS5500 Computer Graphics April 10, 2006.
Isaac Gang University of Mary Hardin-Baylor
Introduction to Computer Graphics with WebGL
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
Illumination Model 고려대학교 컴퓨터 그래픽스 연구실.
CS 480/680 Computer Graphics Shading.
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Shading II Ed Angel Professor Emeritus of Computer Science
Computer Graphics Shading 紀明德
Presentation transcript:

Shading To determine the correct shades of color on the surface of graphical objects.

Why Shading ?

Light and surfaces The color we see is determined by interactions among light sources and surfaces.

Lights, Surfaces, and Imaging Proj. Plane COP Light Source Objects

Modes of Interaction of Light with Materials Specular reflection Diffuse reflection Ambient reflection Note: Any given surface can have some of all three properties.

Phong Model

Phong Model Diffuse Specular Ambient To source To viewer Normal A simple model that can be computed rapidly Has three components Diffuse Specular Ambient Uses four vectors To source To viewer Normal Perfect reflector

The Phong Model

The Combined Effect

Adding up the Components For each light source and each color component, the Phong model can be written (without the distance terms) as I =kd Id l · n + ks Is (v · r )a + ka Ia For each color component we add contributions from all sources

Elements of the Phong Lighting Model: Ambient Reflection The intensity of ambient light is the same at every point on the surface. The percentage of light reflected is given by: Note that the ambient reflection terms can be different for red, green and blue.

Elements of the Phong Lighting Model: Diffuse Reflection Intensity of illumination is dependent upon the incidence angle of light from the source (Lambert’s law): n l q Adding a term for attenuation with distance from source:

Elements of the Phong Lighting Model: Specular Reflection For a shiny surface, most light is reflected around vector r, corresponding to a reflected angle equal to the angle of incidence. If f is the angle between v and r, The exponent is a shininess coefficient Large Small

Light Sources In the Phong Model, we add the results from each light source Each light source has separate diffuse, specular, and ambient terms to allow for maximum flexibility even though this form does not have a physical justification Separate red, green and blue components Hence, 9 coefficients for each point source Idr, Idg, Idb, Isr, Isg, Isb, Iar, Iag, Iab Example: ambient light Ia ,

Material Properties kdr, kdg, kdb, ksr, ksg, ksb, kar, kag, kab Material properties match light source properties Nine absorbtion coefficients kdr, kdg, kdb, ksr, ksg, ksb, kar, kag, kab Shininess coefficient a

Steps in OpenGL shading

Steps in OpenGL shading Enable shading and select model Specify normals Specify material properties Specify lights

Normals Length can be affected by transformations In OpenGL the normal vector is part of the state Set by glNormal*() glNormal3f(x, y, z); glNormal3fv(p); Usually we want to set the normal to have unit length so cosine calculations are correct Length can be affected by transformations Note that scaling does not preserved length glEnable(GL_NORMALIZE) allows for autonormalization at a performance penalty

Enabling Shading Once lighting is enabled, glColor() ignored Shading calculations are enabled by glEnable(GL_LIGHTING) Once lighting is enabled, glColor() ignored Must enable each light source individually glEnable(GL_LIGHTi) i=0,1…..

The Complete Phong Model Distance term Ambient term Diffuse term Specular term

Defining a Point Light Source For each light source, we can set an RGB for the diffuse, specular, and ambient parts, and the position GLfloat diffuse0[]={1.0, 0.0, 0.0, 1.0}; GLfloat ambient0[]={1.0, 0.0, 0.0, 1.0}; GLfloat specular0[]={1.0, 0.0, 0.0, 1.0}; Glfloat light0_pos[]={1.0, 2.0, 3,0, 1.0}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightv(GL_LIGHT0, GL_POSITION, light0_pos); glLightv(GL_LIGHT0, GL_AMBIENT, ambient0); glLightv(GL_LIGHT0, GL_DIFFUSE, diffuse0); glLightv(GL_LIGHT0, GL_SPECULAR, specular0);

Distance and Direction The source colors are specified in RGBA The position is given in homogeneous coordinates If w =1.0, we are specifying a finite location If w =0.0, we are specifying a parallel source with the given direction vector The coefficients in the distance terms are by default a=1.0 (constant terms), b=c=0.0 (linear and quadratic terms). Change by a= 0.80; glLightf(GL_LIGHT0, GLCONSTANT_ATTENUATION, a);

Global Ambient Light Ambient light depends on color of light sources A red light in a white room will cause a red ambient term that disappears when the light is turned off OpenGL allows a global ambient term that is often helpful glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient)

Moving Light Sources Light sources are geometric objects whose positions or directions are affected by the model-view matrix Depending on where we place the position (direction) setting function, we can Move the light source(s) with the object(s) Fix the object(s) and move the light source(s) Fix the light source(s) and move the object(s) Move the light source(s) and object(s) independently

Material Properties GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; Material properties are also part of the OpenGL state and match the terms in the Phong model Set by glMaterialv() GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; GLfloat diffuse[] = {1.0, 0.8, 0.0, 1.0}; GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat shine = 100.0 glMaterialf(GL_FRONT, GL_AMBIENT, ambient); glMaterialf(GL_FRONT, GL_DIFFUSE, diffuse); glMaterialf(GL_FRONT, GL_SPECULAR, specular); glMaterialf(GL_FRONT, GL_SHININESS, shine);

Front and Back Faces back faces not visible back faces visible The default is shade only front faces which works correctly for convex objects If we set two sided lighting, OpenGL will shade both sides of a surface Each side can have its own properties which are set by using GL_FRONT, GL_BACK, or GL_FRONT_AND_BACK in glMaterialf back faces not visible back faces visible

Shading Model

Polygonal Shading: Flat Shading Each point on the polygon is assigned the same shade. Small differences in shading between adjacent polygons are visible.

Shading in OpenGL: Flat Shading OpenGL uses the normal of the first vertex of a single polygon to determine the color. Requested by: glShadeModel(GL_FLAT);

Shading in OpenGL: Smooth Shading Requested by: glShadeModel(GL_SMOOTH); Lighting calculations will be done at each vertex using the material properties, and the vectors v and l calculated for that vertex. Bilinear interpolation is used to determine color values in the interior of the polygon.

Bilinear Interpolation

Flat vs Smooth Shading

Polygonal Shading: Phong Shading Normals are interpolated across each polygon instead of color values.

Global Rendering Local lighting model Each object is shaded independently. Does not consider the effect of other objects on the final shaded color value. Cannot produce shadows. Global lighting model Ray tracing Radiosity

Ray Tracing : Initial Stage Divide the image plane into pixel-sized areas. Generate a cast ray through each pixel. If the ray goes off to infinity without striking anything Assign background color to the pixel. If the ray strikes a surface Calculate a shade for the point of intersection

Ray-casting model