OpenGL Vertex Arrays OpenGL vertex arrays store vertex properties such as coordinates, normal vectors, color values and texture coordinates. These properties.

Slides:



Advertisements
Similar presentations
Chapter 11. Faster Geometry Throughput Presented by Garrett Yeh.
Advertisements

1Computer Graphics Building Models John Shearer Culture Lab – space 2
Lecture 8 Transparency, Mirroring
COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.
©Zachary Wartell, UNCC9/28/ :30 AM 1 Overview of OpenGL Revision: 1.2 Copyright Professor Zachary Wartell, University of North Carolina All Rights.
Virtual Realism TEXTURE MAPPING. The Quest for Visual Realism.
Polygon Rendering Flat Rendering Goraud Rendering Uses Phong Reflectance Phong Rendering.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Building Models modified by Ray Wisman Ed Angel Professor of Computer Science,
1 Building Models. 2 Objectives Introduce simple data structures for building polygonal models ­Vertex lists ­Edge lists OpenGL vertex arrays.
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.
Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
OPENGL Return of the Survival Guide. Buffers (0,0) OpenGL holds the buffers in a coordinate system such that the origin is the lower left corner.
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
 The success of GL lead to OpenGL (1992), a platform-independent API that was  Easy to use  Close enough to the hardware to get excellent performance.
OpenGL Son of the Survival Guide. Last Time on OpenGL Windowing … glut Rendering Primatives Transformations Projections State Management.
Meshes Dr. Scott Schaefer. 3D Surfaces Vertex Table.
Drawing Geometric Objects
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
Shading in OpenGL Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Hofstra University1 Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass,
Environmental Maps Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
CS 4731: Computer Graphics Lecture 17: Texturing Emmanuel Agu.
CS 470 Introduction to Computer Graphics Basic 3D in OpenGL.
1 Computer Graphics Week13 –Shading Models. Shading Models Flat Shading Model: In this technique, each surface is assumed to have one normal vector (usually.
Modeling. Geometric Models  2D and 3D objects  Triangles, quadrilaterals, polygons  Spheres, cones, boxes  Surface characteristics  Color  Texture.
Shading in OpenGL.
OpenGL - Lighting, Shading and Material Properties
Texture Mapping (cont.) Jian Huang, CS 594, updated in Fall’08.
Speeding Up Rendering After Deciding What to Draw.
ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny TA. Abhishek Gattani TA. Stephen
CS 480/680 Computer Graphics Shader Applications Dr. Frederick C Harris, Jr. Fall 2011.
Texture Mapping Applications 2. Parallax Mapping with Slope  parallax mapping assumes that the surface is a single plane  a better approximation  surface.
Computer Graphics I, Fall 2010 Shading in OpenGL.
CS380 LAB IV OpenGL Jonghyeob Lee Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Texture Mapping Fall, Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.
State Management and Drawing Geometry Objects
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
Game Programming 06 The Rendering Engine
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
More on Environment Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, December 10, 2003.
Objectives Introduce simple data structures for building polygonal models -- Vertex lists and Edge lists Introduce simple data structures for building.
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
Shader Applications Ed Angel Professor Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive Computer Graphics.
UniS CS297 Graphics with Java and OpenGL State Management and Drawing Primative Geometric Objects.
Global Illumination. Local Illumination  the GPU pipeline is designed for local illumination  only the surface data at the visible point is needed to.
Bump Map 1. High Field Function: H(u, v) New Normal : N’
11/24/ :45 Graphics II Shadow Maps Reflections Session 5.
Module 06 –environment mapping Module 06 – environment mapping Module 06 Advanced mapping techniques: Environment mapping.
Computer Graphics I, Fall 2010 Building Models.
Homogeneous Coordinates and Matrix Representations Cartesian coordinate (x, y, z) Homogeneous coordinate (x h, y h, z h, h) Usually h = 1. But there are.
11/16/04© University of Wisconsin, CS559 Fall 2004 Last Time Texture Anti-Aliasing Texture boundaries Modeling introduction.
Module 05 –Bump mapping Module 05 – Bump mapping Module 05 Advanced mapping techniques: Bump mapping.
4. Geometric Objects and Transformations
Texture Mapping CEng 477 Introduction to Computer Graphics.
Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Texture Mapping Fall, 2016.
Building Models Ed Angel
Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass, wall paper. Use.
Geb Thomas Adapted from the OpenGL Programming Guide
Class 26 more textures environmental textures Color ramps
Isaac Gang University of Mary Hardin-Baylor
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Computer Graphics Practical Lesson 8
Geometric Objects and Transformations (I)
Last Time Liang-Barsky Details Weiler-Atherton clipping algorithm
Class 27 more textures environmental textures Color ramps
Texture Mapping Jung Lee.
Computer Graphics Vertex Array Object
Presentation transcript:

OpenGL Vertex Arrays OpenGL vertex arrays store vertex properties such as coordinates, normal vectors, color values and texture coordinates. These properties can be specified indirectly using their positions in the arrays, instead of calling glVertex*(), glNormal*(), glColor*() and glTexCoord*(). Procedures to use vertex arrays: Enable vertex arrays. Specify data for the arrays. Dereference the arrays and render primitives.

Enable Vertex Arrays void glEnableClientState(GLenum array) void glDisableClientState(GLenum array) Disable vertex array array Meaning GL_VERTEX_ARRAY Array with vertex coordinates GL_COLOR_ARRAY Array with color values GL_NORMAL_ARRAY Array with normal vectors GL_TEXTURE_COORD_ARRAY Array with texture coordinates When using multitexture, glEnableClientState() and glDisableClientState() only affect current client texture unit specified by glClientActiveTexture() void glClientActiveTexture(GLenum texUnit) Select current client texture unit. texUnit is the texture unit identifier.

Specify Data for the Arrays void glVertexPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) Specify array with vertex coordinates size: Number of coordinates per vertex. Must be 2, 3 or 4. type: Data type for vertex coordinates. GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE. stride: Byte offset between consecutive vertices. If stride = 0, the vertices are assumed to be tightly packed in the array. pointer: Pointer to the array that stores vertex coordinates. void glColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer) void glNormalPointer(GLenum type, GLsizei stride, const GLvoid *pointer) void glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)

Command size type glVertexPointer (Vertex coordinates) 2, 3, 4 GL_SHORT, GL_INT, GL_FLOAT, GL_DOUBLE glColorPointer (Color values) 3, 4 GL_BYTE, GL_UNSIGNED_BYTE, GL_SHORT, GL_UNSIGNED_SHORT, GL_INT, GL_UNSIGNED_INT, glNormalPointer (Normal vectors) 3 GL_BYTE, GL_SHORT, GL_INT, glTexCoordPointer (Texture coordinates) 1, 2, 3, 4 When using multitexture, glTexCoordPointer() only affects current client texture unit specified by glClientActiveTexture()

Dereference the Arrays and Render Primitives De-reference a Single Array Element void glArrayElement(GLint i) Specify vertex properties for the ith vertex for all enabled arrays. This command is usually called between glBegin( ) and glEnd( ). This is equivalent to: if (color array is enabled) glColor*v(cpointer + i * cstride); if (normal array is enabled) glNormal*v(npointer + i * nstride); if (texture coordinate array is enabled) glTexCoord*v(tpointer + i * tstride); if (vertex array is enabled) glVertex*v(vpointer + i * vstride);

De-reference a List of Array Elements void glDrawElements( GLenum mode, GLsizei count, GLenum type, GLvoid *indices) Draw a sequence of primitives using array elements referenced by an index array. mode: Primitive type. Same as the argument in glBegin(). count: Number of elements to specify. type: Data type for index array indices. GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT. indices: Pointer to the index array. Equivalent to: glBegin (mode); for (i = 0; i < count; ++i) glArrayElement (indices[i]); glEnd();

De-reference a Sequence of Array Elements void glDrawArrays(GLenum mode, GLint first, GLsizei count) Draw a sequence of primitives using array elements starting from first and ending at first + count – 1. mode: Primitive type. Same as the argument in glBegin(). first: Starting element index. count: Number of elements to specify. Equivalent to: glBegin (mode); for (i = 0; i < count; ++i) glArrayElement (first + i); glEnd();

Example y 8 9 10 11 4 5 6 7 x 1 2 3 Vertex Index Coordinates 1 2 3 Vertex Index Coordinates Texture Coordinates (0.0, 0.0, 0.0) (0.0, 0.0) 1 (5.0, 0.0, 0.0) (1.0, 0.0) 2 (10.0, 0.0, 0.0) (2.0, 0.0) 3 (15.0, 0.0, 0.0) (3.0, 0.0) 4 (0.0, 4.0, 0.0) (0.0, 0.5) 5 (5.0, 4.0, 0.0) (1.0, 0.5) Vertex Index Coordinates Texture Coordinates 6 (10.0, 4.0, 0.0) (2.0, 0.5) 7 (15.0, 4.0, 0.0) (3.0, 0.5) 8 (0.0, 8.0, 0.0) (0.0, 1.0) 9 (5.0, 8.0, 0.0) (1.0, 1.0) 10 (10.0, 8.0, 0.0) (2.0, 1.0) 11 (15.0, 8.0, 0.0) (3.0, 1.0)

struct VERTEX { float x[3]; // position float t[2]; // texture coordinates }; static VERTEX v[12] = { {0.0, 0.0, 0.0, 0.0, 0.0}, {5.0, 0.0, 0.0, 1.0, 0.0}, {10.0, 0.0, 0.0, 2.0, 0.0}, {15.0, 0.0, 0.0, 3.0, 0.0}, {0.0, 4.0, 0.0, 0.0, 0.5}, {5.0, 4.0, 0.0, 1.0, 0.5}, {10.0, 4.0, 0.0, 2.0, 0.5}, {15.0, 4.0, 0.0, 3.0, 0.5}, {0.0, 8.0, 0.0, 0.0, 1.0}, {5.0, 8.0, 0.0, 1.0, 1.0}, {10.0, 8.0, 0.0, 2.0, 1.0}, {15.0, 8.0, 0.0, 3.0, 1.0}}; glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(3, GL_FLOAT, 5*sizeof(VERTEX), v[0].x); glTexCoordPointer(2, GL_FLOAT, 5*sizeof(VERTEX), v[0].t);

static unsigned int vindex[24]={ 0, 1, 5, 4, 1, 2, 6, 5, 2, 3, 7, 6, 4, 5, 9, 8, 5, 6, 10, 9, 6, 7, 11, 10}; glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, tex_obj); glDrawElements(GL_QUADS, 24, GL_UNSIGNED_INT, vindex);

Environment Mapping Environment mapping is used to render reflective surface. It assumes that the environment is much larger than the object and far away from the object. Viewer N R V Environment Map Object Surface N Unit Surface Normal V Unit Direction Vector to Viewer R Unit Reflection Vector

Environment Mapping Procedure 1. Generate Environment Map Place a camera at the center of the object and take a panorama snapshot of the surrounding environment. Store the image as a texture. This texture is called Environment Map. 2. Obtain Reflection Vector 3. Generate Texture Coordinates for Sampling in the Environment Map Using Reflection Vector R

Sphere Environment Mapping Sphere Environment Mapped Object

The surrounding environment is projected onto an enclosing sphere The surrounding environment is projected onto an enclosing sphere. The image on the sphere surface is then mapped into a circular area on a 2D texture. Unit Reflection Vector x R W z Texture Coordinates:

Cube Environment Mapped Object Cube Environment Mapping Cube Environment Map Cube Environment Mapped Object

The surrounding environment is projected onto an enclosing cube. The images on the six sides of the cube are then stored as six 2D textures.  y z x x z y x y z z x z x x z x z y y y y z y x

w = max (|Rx|, |Ry|, |Rz|); Cube Map Face Local x Local y x z y x z y x z R w = max (|Rx|, |Ry|, |Rz|); if (w == |Rx| and Rx > 0) {Choose +x face; s = Rz / w; t = Ry / w;} if (w == |Rx| and Rx < 0) {Choose x face; s = Rz / w; t = Ry / w;} if (w == |Ry| and Ry > 0) {Choose +y face; s = Rx / w; t = Rz / w;} if (w == |Ry| and Ry < 0) {Choose y face; s = Rx / w; t = Rz / w;} if (w == |Rz| and Rz > 0) {Choose +z face; s = Rx / w; t = Ry / w;} if (w == |Rz| and Rz < 0) {Choose z face; s = Rx / w; t = Ry / w;} s = 0.5(s + 1); t = 0.5(t + 1);

Light Map Light map: Texture that stores the lighting intensities of a surface.  Scene with base textures Light Maps = Textured scene modulated by light maps For static scene under static lighting, light maps can be pre-computed.

Light map was first introduced in Quake engine. Without Light Map With Light Map Light Map

Bump Mapping + Texture Mapped Object Height Map = Bump Mapped Object

Normal texture mapping creates a flat looking surface. Light Source Viewer Bump mapping applies a perturbation to surface normal and uses the perturbed normal for lighting calculation. Thus creates an illusion of surface bumpiness. Light Source Viewer

Create Bump Map from Height Map Height Map h(x, y): A 2D texture that stores the height perturbation of a surface. Bump Map Nb(x, y) :A 2D texture that stores perturbed normal vectors of a surface. Calculate perturbed normal: Use finite difference

Normalization: Change component range from [1, 1] to [0, 1]: Store nx, ny, nz in R, G, B components of the bump map. To retrieve perturbed normal, do the inverse:

Transform Vectors from Object Space to Texture Space Bump map stores perturbed surface normals in texture space. Thus transformation from object space to texture space is needed. Obtain base vectors for texture space N N Unit normal vector T Unit tangent vector B Unit binormal vector B T

For curved surface with parametric equation P = P(u, v) Example: Sphere z N B T P r  y  x

For a point P with texture coordinates (s, t) on the triangle surface For triangle surface with texture coordinates specified for each vertex N3 B3 Vertex Texture Coordinates P1 P2 P3 (s1, t1) (s2, t2) (s3, t3) P3 T3 N1 B1 N2 P T1 P1 B2 P2 T2 For a point P with texture coordinates (s, t) on the triangle surface Replace P with P2 and P3:

Solve the above equations to obtain T1 and B1: T1 and B1 are then normalized to unit vectors T2 , B2 , T3 , B3 can be obtained similarly. Transform vectors from object space to local texture space For direction to light vector L For direction to viewer vector V

Lighting Calculation Use Nb, L' and V' for lighting calculation.

Displacement Mapping Bump Mapping only perturbs surface in N direction and only uses perturbed normal for lighting calculations. Displacement Mapping perturbs surface in N, T, B directions. It not only uses perturbed normal for lighting calculations, but also displaces surface position for real.

Parallax Occlusion Mapping

Water Surface Animation and Rendering Plane Wave Equation Surface Point P = (x, y, z) A Amplitude f frequency Lx Wave length in x direction Ly Wave length in y direction Surface Normal

Reflection Rendering Transparent Effect z xy plane Camera N N: Surface normal V R Water Surface xy plane P Direction to camera vector Reflection vector Use R to sample environment map to obtain reflection color Transparent Effect Use color blending