OpenGL - Lighting, Shading and Material Properties

Slides:



Advertisements
Similar presentations
Polygon Rendering Flat Rendering Goraud Rendering Uses Phong Reflectance Phong Rendering.
Advertisements

Illumination Lighting and Shading CSE 470/598 Introduction to Computer Graphics Arizona State University Dianne Hansford.
Graphics Pipeline.
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.
3D Graphics Rendering and Terrain Modeling
1. What is Lighting? 2 Example 1. Find the cubic polynomial or that passes through the four points and satisfies 1.As a photon Metal Insulator.
Computer Graphics - Class 10
OpenGL Son of the Survival Guide. Last Time on OpenGL Windowing … glut Rendering Primatives Transformations Projections State Management.
Shading in OpenGL CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 CSCE 641: Computer Graphics Lighting Jinxiang Chai.
7M836 Animation & Rendering
Now Playing: Multiply Jamie Lidell from Multiply Released June 13, 2005.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Models and Architectures Ed Angel Professor of Computer Science, Electrical and Computer.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
Shadows Computer Graphics. Shadows Shadows Extended light sources produce penumbras In real-time, we only use point light sources –Extended light sources.
1 Computer Graphics Week13 –Shading Models. Shading Models Flat Shading Model: In this technique, each surface is assumed to have one normal vector (usually.
Lecture 5: 3D Rendering Pipeline (II) Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Institute of Technology.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Shading in OpenGL.
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.
CS 481 Preview, Some Lighting Details Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 19, 2003.
Shading and Illumination. OpenGL Shading Without ShadingWith Shading.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Computer Graphics I, Fall 2010 Shading in OpenGL.
CS447/ Realistic Rendering -- Radiosity Methods-- Introduction to 2D and 3D Computer Graphics.
Programming for Virtual Reality Applications Projection in OpenGL Lighting and Shading Lecture 17.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
Lecture 14 Shading models 1.Shading Constant Shading (to be implemented) Gouraud Shading Phong Shading 2.Light and shading with OpenGL 1.
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 10/24/ :01 UML Graphics II Shadows Session 4.
1Computer Graphics Lecture 4 - Models and Architectures John Shearer Culture Lab – space 2
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Lighting and Shading Part II.
OpenGL Color and Lighting 2003 Spring Keng Shih-Ling.
Lighting Review & Example Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 17, 2003.
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.
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E.
RENDERING Introduction to Shading models – Flat and Smooth shading – Adding texture to faces – Adding shadows of objects – Building a camera in a program.
Global Illumination. Local Illumination  the GPU pipeline is designed for local illumination  only the surface data at the visible point is needed to.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
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.
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
Render methods. Contents Levels of rendering Wireframe Plain shadow Gouraud Phong Comparison Gouraud-Phong.
Shading NOTE: Some of these slides are from Ed Angel’s presentation at SIGGRAPH February 27, 2008.
Chapter 1 Graphics Systems and Models Models and Architectures.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
Computer Graphics Ken-Yi Lee National Taiwan University (the slides are adapted from Bing-Yi Chen and Yung-Yu Chuang)
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
Computer Graphics (fall,2010) School of Computer Science University of Seoul Minho Kim.
CSC Graphics Programming
Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1
© University of Wisconsin, CS559 Spring 2004
Shading To determine the correct shades of color on the surface of graphical objects.
@ 2017 by Jim X. Chen George Mason University
3D Graphics Rendering PPT By Ricardo Veguilla.
School of Computer Science
Models and Architectures
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Shading in OpenGL Ed Angel
Lighting and Materials
Lighting – Light Sources
Computer Graphics 4Practical Lesson
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Presentation transcript:

OpenGL - Lighting, Shading and Material Properties Computer Graphics OpenGL - Lighting, Shading and Material Properties

Hidden Surface Removal First we begin with hidden surface removal. When drawing objects in order which does not match the order of their appearance (distance from the camera) we get wrong occlusions. Note: the order is view dependent, therefore for each viewpoint a different drawing order should be found. occluded Drawn next Result without hidden surface removal Drawn first

Hidden Surface Removal OpenGL solves this problem by holding a depth-map called “Z-Buffer”. This buffer holds the depths (distances on the Z direction) of each pixel drawn on the frame buffer. Then, when a new object is painted, a depth test determines for each pixel if it should be updated or not. To turn this mechanism on, the following steps should be taken: gluInitDisplayMode(GLUT_DEPTH | … ) ; glEnable(GL_DEPTH_TEST) ; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) ;

OpenGL’s Shading models glShadeModel(GLenum mode) - Sets the shading model which can be either GL_SMOOTH or GL_FLAT. FLAT shading model: The color of one particular vertex is used to render the entire primitive. SMOOTH shading model: The color used to render the primitive is a result of color interpolation between the primitive’s vertices’ colors.

OpenGL’s Lighting model OpenGL supports a lighting model which includes: Multiple light sources. Spots, Points and directional light sources. Different material properties. Surface normals. The lighting model uses above factor to estimate vertices colors. glEnable(GL_LIGHTING) - will enable OpenGL’s lighting model. Once this is enables the glColor doesn’t effects the vertices colors (material color attributes are now responsible for the objects own color).

OpenGL’s Lighting model The Lighting Model: Before describing each term, we’ll go through the commands that defines lights and materials properties. glEnable(GL_LIGHTX) - X = 0…7 - enable light source. glLight{if}(GLenum lightnum, GLenum pname, TYPE param) glLight{if}v(GLenum lightnum, GLenum pname, TYPE *param) - sets the property pname of light lightnum to be param: GL_AMBIENT (R,G,B,A) RGBA values. GL_DIFFUSE (R,G,B,A) RGBA values. GL_SPECULAR (R,G,B,A) RGBA values. GL_POSITION (X,Y,Z,W) Position in space.

OpenGL’s Lighting model GL_SPOT_DIRECTION (x,y,z) Direction vector GL_SPOT_EXPONENT e spotlight exponent GL_SPOT_CUTOFF ang spotlight cutoff angle GL_CONSTANT_ATTENUATION kc Const. Attn. Factor GL_LINEAR_ATTENUATION kl Linear Attn. Factor GL_CONSTANT_ATTENUATION kq Quadric Attn. Factor glMaterial{if}(GLenum face, GLenum pname, TYPE param) glMaterial{if}v(GLenum face, GLenum pname, TYPE *param) - sets the vertex material property pname to be param on face. GL_AMBIENT (R,G,B,A) RGBA color GL_DIFFUSE (R,G,B,A) RGBA color GL_SPECULAR (R,G,B,A) RGBA color GL_SHININESS s specular exponent GL_EMISSION e emissive color of vertex.

OpenGL’s Lighting model Argument face is: GL_FRONT GL_BACK GL_FRONT_AND_BACK This determines on which face of the primitive to apply the glMaterial. Primitives’ sides are determined by the order of their vertices: glFrontFace(GLenum mode) - determines which order will define the front face. Arguments: GL_CCW, GL_CW (order on the projected windows) v1 v1 v3 v2 v2 v3 ClockWise CounterClockWise

OpenGL’s Lighting model Emission term: The material emissive light value (GL_EMISSION) Attenuation Factor: Spotlight Effect:

OpenGL’s Lighting model Ambient Term: is simply the light’s ambient color scaled by the materials (GL_AMBIENT): Note: The multiplication above is individually for the R,G,B and A color components. Diffuse Term: The direct light that reaches the vertex. It is directional depended: glNormal3{bsidf}(TYPE nx, TYPE ny, TYPE nz) glNormal3{bsidf}v(TYPE *v) - Defines the current normal vector. Next time glVertex will be called, the current normal will be assigned to the vertex. Note: OpenGL - can receive non-unit normals and normalize them if glEnable(GL_NORMALIZE) is called.

OpenGL’s Lighting model Specular Term: Is calculated as follows: All together gives:

OpenGL’s Lighting model Light sources types: Point - Light coming from a single point in 3D space. This is the default light source. Distant/directional - Light coming from a direction. Light Rays a parallel. This is specified by putting 0 zero in the fourth coordinate of the GL_POSITION attribute of the light source. (Remember what vectors of the type (x,y,z,0) mean in projective spaces). Spot - Light coming from a point same as in Point lights, but has a direction around which light intensity drops. Specified by setting GL_SPOT_CUTOFF to be less than 180.

OpenGL’s Lighting model Point: Distant: Spot: GL_SPOT_CUTOFF

OpenGL’s Lighting model Lights Position: we can think of three relations between the light position and the objects position: A light position that remains fixed. A light that moves around a stationary object. A light that moves along with the viewpoint. A important fact needed in order to achieve the above cases is: When glLight is called to specify the position or the direction of a light source, the position or direction is transformed by the current modelview matrix.

OpenGL’s Lighting model A light position that remains fixed: In this case lights (pos/dirs) should go only through the viewing transformations. This means that we will specify the light pos/dirs After view trans has been defined but before model trans has been defined: glMatrixMode(GL_MODELVIEW) ; glLookAt / any view transform glLight(GL_POSITION/DIRECTION) glRotate/glTranslate/glScale - on the objects.

OpenGL’s Lighting model A light that moves around a stationary object: In this case lights (pos/dirs) should go only through the viewing and model transformations, while the objects will go only through view transformations. This means that we will specify the light pos/dirs after view and model trans. But the objects won’t go through the model trans: glMatrixMode(GL_MODELVIEW) ; glLookAt / any view transform glPushMatrix() ; glTranslate() / glRotate() (for light pos and dir) glLight(GL_POSITION/DIRECTION) glPopMatrix() ; glBegin() … glEnd() // Draw the objects.

OpenGL’s Lighting model A light that moves along with the viewpoint: In this case lights (pos/dirs) should not go through any transformations. They stay in the camera (eyes) coordinate system. First we call glLight when modelview is identity*. Then we specify view and model transformations for the objects: glMatrixMode(GL_MODELVIEW) ; glLoadIdentity() ; (*or any location / rotation in eye coord. sys.) glLight(GL_POSITION/DIRECTION) glLookAt / any view transform glTranslate() / glRotate() (for objects) glBegin() … glEnd() // Draw the objects.

Shading models FLAT SMOOTH Gouraud Phong

Global and Local Lighting Models Global models Local Models

Ray Tracing Global lighting model based on ray casting techniques, instead of Z-buffering incorporates (indeed, it is inherent within the technique) such crucial realism elements as visible surface detection, shadowing, reflection, transparency, mapping, and multiple light sources.

Radiosity Global lighting model more accurately render environments characterised more by diffuse reflection the system looks solely at the light/energy balance in a closed environment The closed environment is one in which all energy emitted or reflected from a given surface is accounted for by reflection and/or absorption by other surfaces