Interactive Computer Graphics CS 418 – Fall 2017 Indexed Meshes Transformations Background Imagery: http://www.cs.cmu.edu/~kmcrane/Projects/ModelRepository/yeahright.png.

Slides:



Advertisements
Similar presentations
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
Advertisements

Animation and Input CSCI Day Six. Animation Basic Steps to Draw Something: var vertices = [ … ]; var BufferId = gl.CreateBuffer(); gl.bindBuffer.
 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.
As well as colors, normals, and other vertex data PUSHIN’ GEO TO THE GPU JEFF CHASTINE 1.
CHAPTER 7 Viewing and Transformations © 2008 Cengage Learning EMEA.
WebGL: a New Platform for 3D Games Advanced Games Programming by Jarek Francik 2011.
2D graphics 3D graphics Segoe UI Fonts, text analysis, layout Image & video decoding GPGPU Too.
Michael Robertson Yuta Takayama. WebGL is OpenGL on a web browser. OpenGL is a low-level 3D graphics API Basically, WebGL is a 3D graphics API that generates.
Basic Graphics Concepts Day One CSCI 440. Terminology object - the thing being modeled image - view of object(s) on the screen frame buffer - memory that.
CS559: Computer Graphics Lecture 33: Shape Modeling Li Zhang Spring 2008.
A Really (too) Short Introduction to OpenGL Peter Rautek.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
CS 418: Interactive Computer Graphics Introduction to WebGL: HelloTriangle.html Eric Shaffer.
WebGL: in-browser 3D graphics Nick Whitelegg Maritme and Technology Faculty Southampton Solent University.
CS 450: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CS 638, Fall 2001 Multi-Pass Rendering The pipeline takes one triangle at a time, so only local information, and pre-computed maps, are available Multi-Pass.
Interactive Computer Graphics CS 418 – Spring 2015 Mesh Rendering, Transformation, Camera Viewing and Projection in OpenGL TA: Zhicheng Yan Sushma S Kini.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
Representation. Objectives Introduce concepts such as dimension and basis Introduce coordinate systems for representing vectors spaces and frames for.
OPENGL INTRODUCTION 林宏祥 2014/10/06. 此投影片已被稍微簡化過,跟今日課堂上的內容不太一樣。 如果想要看更詳細說明的人,請參考每頁投影片下面的『備忘稿』
Control flow for interactive applications CSE 3541 Matt Boggus.
User Input and Animation. For Further Reading Angel 7 th Ed: –Chapter 3: Input and Animation. –Chapter 4: Rotation and other transformation. Beginning.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
1 Graphics CSCI 343, Fall 2015 Lecture 5 Color in WebGL.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor.
Computer Graphics Matrices
MP3 Frequently Asked Questions (IN OFFICE HOURS).
A study of efficiency INDEX BUFFERS JEFF CHASTINE 1.
Mobile & Casual Gaming OpenGL ES Intro. /red/chapter03.html.
CS 480/680 Computer Graphics Programming with Open GL Part 2: Complete Programs Dr. Frederick C Harris, Jr. Fall 2011.
Introduction to Computer Graphics
Pushin’ Geo to the GPU As well as colors, normals, and other vertex data Made by Jeff Chastine, Modified by Chao Mei Jeff Chastine.
Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009
Interactive Computer Graphics CS 418 – Fall 2017
- Introduction - Graphics Pipeline
Computer Graphics Raster Devices Transformations
Graphics CSCI 343, Fall 2017 Lecture 13 More on WebGL
Tips for Shading Your Terrain
Real-Time Rendering Buffers in OpenGL 3.3
Real-Time Rendering Geometry and Buffers
Introduction to OpenGL
CS451Real-time Rendering Pipeline
Introduction to Computer Graphics with WebGL
Building Models Ed Angel
Programming with OpenGL Part 2: Complete Programs
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
Introduction to Computer Graphics with WebGL
Transformation, perspective projection, and LookAT in WebGL vs.OpenGL
Building Models Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
Isaac Gang University of Mary Hardin-Baylor
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Building Models Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Isaac Gang University of Mary Hardin-Baylor
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
Introduction to Computer Graphics with WebGL
03 | Creating, Texturing and Moving Objects
Introduction to OpenGL
Mickaël Sereno Graphics Memory Mickaël Sereno 11/07/2019 Mickaël Sereno -
Presentation transcript:

Interactive Computer Graphics CS 418 – Fall 2017 Indexed Meshes Transformations Background Imagery: http://www.cs.cmu.edu/~kmcrane/Projects/ModelRepository/yeahright.png

Agenda Indexed Mesh Structures Review Drawing with WebGL Review Matrix transformation Changing Geometry Directly

Mesh Structure (Indexed Face Set) Stores vertex coordinates in one array Triangles in another Each triangle is specified by the indices of its vertices in the other array Here is what we’ve seen, drawing two triangles vertexPositionBuffer = gl.createBuffer(); var triangleVertices = new Float32Array([ 0.50, 0.75, 0.0, -0.5, 0.75, 0.0, -0.5, -0.75, 0.0, 0.50, -0.75, 0.0, 0.50, 0.75, 0.0 ]);

Mesh Structure Here is what’s possible with indexing vertexPositionBuffer = gl.createBuffer(); indexBuffer = gl.createBuffer(); var vertices = new Float32Array([ 0.50, 0.75, 0.0, -0.50, 0.75, 0.0, -0.50, -0.75, 0.0, 0.50, -0.75, 0.0 ]); var indices = new Int32Array([ 0,1,2, 2,3,0

Display Your Mesh gl.bindBuffer(gl.ARRAY_BUFFER, vertexPositionBuffer); gl.bufferData(gl.ARRAY_BUFFER, vertices ,gl.STATIC_DRAW); vertexPositionBuffer.itemSize = 3; vertexPositionBuffer.numberOfItems = 4; gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer); gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices ,gl.STATIC_DRAW); indexBuffer.itemSize = 1; indexBuffer.numberOfItems = 6; gl.drawElements(gl.TRIANGLES, 2, gl.UNSIGNED_INT, 0);

Color Your Mesh colors = new Float32Array([ 1.0, 0.0, 0.0, 1.0, //red 0.0, 1.0, 0.0, 1.0, //green 0.0, 0.0, 1.0, 1.0, //blue 0.0, 0.0, 0.0, 1.0 //black ]); gl.bindBuffer(gl.ARRAY_BUFFER, vertexColorBuffer); gl.bufferData(gl.ARRAY_BUFFER, colors ,gl.STATIC_DRAW); vertexColorBuffer.itemSize = 4; vertexColorBuffer.numberOfItems = 4;

Render Your Mesh Bind the program Get the variable location Enable that shader variable Do all the buffer setup we just saw Finally point the shader variable to the buffers we created earlier gl.useProgram(exampleShaderProgram); shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition"); gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute); … gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, vertexPositionBuffer.itemSize, gl.FLOAT, false, 0, 0);

In a Nut Shell gl.bindBuffer(gl.ARRAY_BUFFER, vertexPositionBuffer); gl.bufferData(gl.ARRAY_BUFFER, vertices ,gl.STATIC_DRAW); vertexPositionBuffer.itemSize = 3; vertexPositionBuffer.numberOfItems = 4; gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, vertexPositionBuffer.itemSize, gl.FLOAT, false, 0, 0); gl.bindBuffer(gl.ARRAY_BUFFER, vertexColorBuffer); gl.bufferData(gl.ARRAY_BUFFER, colors ,gl.STATIC_DRAW); vertexColorBuffer.itemSize = 4; vertexColorBuffer.numberOfItems = 4; gl.vertexAttribPointer(shaderProgram.vertexColorAttribute, vertexColorBuffer.itemSize, gl.FLOAT, false, 0, 0); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer); gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, indices ,gl.STATIC_DRAW); indexBuffer.itemSize = 1; indexBuffer.numberOfItems = 6; gl.drawElements(gl.TRIANGLES, indexBuffer.numberOfItems, gl.UNSIGNED_SHORT, 0);

Result

Review of Matrix Ops. Scale 10

Scaling 11

Translation 12

Translation 13

Rotation 14

Rotation You may also specify rotation about an arbitrary axis. 15

Last Transform Applied First var mvMatrix = mat4.create(); var mvMatrix = mat4.create(); mat4.rotateX(mvMatrix…) mat4.translate(mvMatrix…) mat4.translate(mvMatrix…) mat4.rotateX(mvMatrix…) M=I R T M=I T R

Exercise Draw the result of the following OpenGL transformation code. var mvMatrix = mat4.create(); mat4.scale(mvMatrix,mvMatrix,vec3.fromValues(1.5, 1.0, 1.0)); mat4.rotateZ(mvMatrix, mvMatrix, degToRad(90)); mat4.translate(mvMatrix, mvMatrix,vec3.fromValues(2.0, 2.0, 0.0)); draw_teapot_image();

Exercise var mvMatrix = mat4.create(); mat4.scale(mvMatrix,mvMatrix,vec3.fromValues(1.5, 1.0, 1.0)); mat4.rotateZ(mvMatrix, mvMatrix, degToRad(90)); mat4.translate(mvMatrix, mvMatrix,vec3.fromValues(2.0, 2.0, 0.0)); draw_teapot_image();

Exercise var mvMatrix = mat4.create(); mat4.scale(mvMatrix,mvMatrix,vec3.fromValues(1.5, 1.0, 1.0)); mat4.rotateZ(mvMatrix, mvMatrix, degToRad(90)); mat4.translate(mvMatrix, mvMatrix,vec3.fromValues(2.0, 2.0, 0.0)); draw_teapot_image();

Exercise var mvMatrix = mat4.create(); mat4.scale(mvMatrix,mvMatrix,vec3.fromValues(1.5, 1.0, 1.0)); mat4.rotateZ(mvMatrix, mvMatrix, degToRad(90)); mat4.translate(mvMatrix, mvMatrix,vec3.fromValues(2.0, 2.0, 0.0)); draw_teapot_image();

Exercise var mvMatrix = mat4.create(); mat4.scale(mvMatrix,mvMatrix,vec3.fromValues(1.5, 1.0, 1.0)); mat4.rotateZ(mvMatrix, mvMatrix, degToRad(90)); mat4.translate(mvMatrix, mvMatrix,vec3.fromValues(2.0, 2.0, 0.0)); draw_teapot_image();

Animation You can animate just by changing the geometry in your vertex array The Process You can include variables inside your array declaration! Each frame you update the variables Each frame you need to reallocate the array Rebuffer the geometry gl.bindBuffer(gl.ARRAY_BUFFER, vertexPositionBuffer); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(triangleVertices), gl.DYNAMIC_DRAW); var triangleVertices = [ -0.25, -0.5, 0.0, 0.35+x_offset, -0.75+y_offset, 0.0, 0.35+x_offset, -0.5+y_offset, 0.0 ];

Animation Can you create an animation Where the geometry is changed along a curve? Hint: consider using something like var triangleVertices = [ -0.25+Math.sin(sinscalar-0.25)*0.5, 0.75+Math.cos(sinscalar)*0.05, 0.0,