Project 5 Lamp Shader Fri, Nov 7, 2003 Due Mon, Nov 17, 2003.

Slides:



Advertisements
Similar presentations
Computer Graphics 2D & 3D Transformation.
Advertisements

3D Game Programming Geometric Transformations
Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.
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.
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.
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.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 11: OpenGL 3
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.
Computer Graphics (Spring 2008) COMS 4160, Lecture 14: OpenGL 3
Illumination and Shading
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Illumination and Shading. Illumination (Lighting) Model the interaction of light with surface points to determine their final color and brightness OpenGL.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
1 Graphics CSCI 343, Fall 2013 Lecture 20 Lighting and Shading III.
Polygon Shading. Assigning color to a shape to make graphical scenes look realistic, or artistic, or whatever effect we’re attempting to achieve But first.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Shading in OpenGL.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
19/17/ :25 UML Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera Real Light Synthetic.
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.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
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.
CS559: Computer Graphics Lecture 15: Hierarchical Modeling and Shading Li Zhang Spring 2008.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Shading I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
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);
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.
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.
Specular Reflection Lecture 27 Mon, Nov 10, 2003.
Local Illumination and Shading
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.
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
David Luebke3/16/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
Illumination CSE 410. Basic steps of lighting Enable smooth shading Set global ambient light glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); GLfloat.
Some Notes on 3-D Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 24, 2003.
CS559: Computer Graphics Lecture 16: Shading and OpenGL Li Zhang Spring 2008.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
Chapter 5. Lighting Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
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.
CSC Graphics Programming
Shading To determine the correct shades of color on the surface of graphical objects.
Tips for Shading Your Terrain
Vectors, Normals, & Shading
Shading in OpenGL Ed Angel
CSC461: Lecture 24 Lighting and Shading in OpenGL
Lighting Phong's Lighting Model normals
Lighting and Materials
Lighting – Light Sources
Lighting – Material Properties
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Geometric Objects and Transformations (II)
ICG 2018 Fall Homework1 Guidance
Computer Graphics 4Practical Lesson
Computer Graphics 5Practical Lesson
Computer Graphics Material Colours and Lighting
Computer Graphics Shading in OpenGL
Shading in OpenGL Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

Project 5 Lamp Shader Fri, Nov 7, 2003 Due Mon, Nov 17, 2003

Lamp Shader Read the handout.handout Download the files. LampShader.cpp. LampShader.cpp mesh.h. mesh.h mesh.cpp. mesh.cpp point3.h. point3.h point3.cpp. point3.cpp vector3.h. vector3.h vector3.cpp. vector3.cpp face.h. face.h vertexid.h. vertexid.h Run LampShader.exe.LampShader.exe

Lamp Shader The primary purpose of this project is to compute the lighting of a vertex, and therefore of a mesh, in a way that exactly matches the lighting calculated by the graphics pipeline.

The Scene The scene consists of a lamp with a lampshade. Each object is represented as a mesh. The basic shapes are spheres, cylinders, cones, and toruses.

The Basic Meshes sphere“cylinder”cone torus

The Basic Meshes These correspond to meshes that are available from the glu and glut libraries. gluSphere(obj, radius, slices, stacks). gluCylinder(obj, baseRad, topRad, height, slices, stacks). glutSolidCone(radius, height, slices, stacks). glutSolidTorus(innerRad, outerRad, nsides, rings).

The Basic Meshes If we used the library functions, that would present two problems in trying to compute the lighting at a vertex. How would we obtain access to the coordinates and normal at a vertex? Even if we did have that access, how would we know the transformed coordinates and normals at a vertex?

The Basic Meshes To avoid both of these problems, we will use our own meshes. The program LampShader.cpp uses the Mesh-class function create() to create a mesh. Among the parameters are functions to compute the vertices and normals in terms of parameters u and v.

The Basic Meshes This solves the problem of access to the coordinates and normals of the meshes. They are stored in the data members of the Mesh object. Point3* pt; Vector3* norm;

Transforming the Meshes OpenGL has functions glTranslate(), glRotate(), and glScale() that will transform the meshes. However, we should not use them. Why not? Instead, the Mesh class has member functions that will translate, rotate, and scale the mesh.

Transforming the Meshes Their prototypes are similar to the OpenGL functions. void translate(dx, dy, dz); void rotate(angle, ux, uy, uz); void scale(sx, sy, sz); This solves the problem of access to the transformed coordinates and normals.

Transforming the Meshes There is a consequence to transforming the points in the mesh object rather than leaving them alone and modifying the ModelView matrix. The transformations must appear in the order in which they are applied, not in reverse order.

Example Mesh.create(…); Mesh.scale(1, 1, 2); Mesh.rotate(90, 0, 1, 0); Mesh.translate(2, 0, 0); Mesh.draw(); glMatrixMode(…); glLoadIdentity(); glTranslatef(2, 0, 0); glRotatef(90, 0, 1, 0); glScalef(1, 1, 2); drawObject(); Compare

Accessing State Variables The draw() function needs to know the values of various state variables concerning light and material properties. Light position. Light color for ambient, diffuse, and specular light. The scene ambient light. Material reflection of ambient, diffuse, and specular light. Material shininess.

Obtaining Light Properties float lightAmbient[4]; float lightDiffuse[4]; float lightSpecular[4]; glGetLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient); glGetLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); glGetLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular); float sceneAmbient[4]; glGetFloatv(GL_LIGHT_MODEL_AMBIENT, sceneAmbient);

Obtaining Material Properties float matAmbient[4]; float matDiffuse[4]; float matSpecular[4]; float matShininess[1]; glGetMaterialfv(GL_FRONT, GL_AMBIENT, matAmbient); glGetMaterialfv(GL_FRONT, GL_DIFFUSE, matDiffuse); glGetMaterialfv(GL_FRONT, GL_SPECULAR, matSpecular); glGetMaterialfv(GL_FRONT, GL_SHININESS, matShininess);

Computing Lighting You should implement the formulas r a = s a m a + L a m a. r d = L d m d (s  n). r s = L s m s (h  n) shiny. where s a = sceneAmbient. L a = lightAmbient. L d = lightDiffuse. L s = lightSpecular.

Computing Lighting and m a = matAmbient. m d = matDiffuse. m s = matSpecular. shiny = matShininess.

Computing Lighting The vectors needed are n = the surface normal. s = the vector to the light source. v = the vector to the viewer. Each of these should be a unit vector.

Computing Lighting n is contained in the Mesh object. s is computed from the point on the surface (pt) and the light position (lightPos). v is computed from the point on the surface (pt) and the location of the viewer (eye). lightPos, eye, and look are global external variables.

Drawing the Vertex Once you have computed the color, you should set it, using glColor(). Then draw the vertex in the usual way, using glVertex(). Since OpenGL lighting is turned off (under software lighting), there will be no lighting effects added to the color that you set. (“What you set is what you get.”)

The Light Position It is possible to obtain the position of the light source from a state variable. glGetLightfv(GL_LIGHT0, GL_POSITION, lightPos); However, this gives its position after the view matrix has been applied! Thus, its coordinates are not in the same system as the point on the surface or the position of the viewer.

Infinite vs. Local Viewer OpenGL treats the viewer as located “at infinity” only for the purpose of calculating specular lighting. The advantage is that the viewer vector v does not change from one point to another on the surface.

Infinite Viewer The viewer is not truly at infinity. The vector v is the vector from the look point to the eye point. That single value of v is used for every point on the surface (as though the viewer were infinitely far away).

Local Viewer If the viewer is “local,” then the viewer vector v is defined to be the vector from the point on the surface to the eye point, normalized. Thus, it must be recomputed for every point on the surface.

Positional vs. Directional Light If the light is positional, then the light vector s goes from the point on the surface (pt) to the light source (lightPos) and must be recomputed for each point. If the light is directional, then it goes from the origin to the light source and need be computed only once.

Suggestions Try implementing ambient light first, then diffuse light, then specular light. While debugging ambient light, turn off diffuse and specular light. While debugging diffuse light, turn off specular light.

Further Purposes of this Project What is the value in doing the lighting calculations that OpenGL already does? Further awareness of how OpenGL works. Ability to modify the lighting model to suit yourself, e.g., Phong vs. Blinn. For example, you might want to create a “bike reflector” that reflects light back towards the light source.

Further Purposes of this Project The latest graphics cards are programmable (in Cg): the programmer may program the lighting of each vertex or each pixel!  A vertex program will color each vertex. OpenGL will interpolate over the polygon.  A fragment program will color each pixel.