1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Projection Matrices Ed Angel
1 Chapter 5 Viewing. 2 Perspective Projection 3 Parallel Projection.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
1 E. Angel and D. Shreiner : Interactive Computer Graphics 6E © Addison-Wesley 2012 Classical Viewing Sai-Keung Wong ( 黃世強 ) Computer Science National.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Computer Graphics I, Fall 2010 Computer Viewing.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
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 Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Viewing and Projection
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.
Viewing and Projection
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Computer Viewing Isaac Gang University of Mary Hardin-Baylor.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Viewing.
Computer Viewing.
Introduction to Computer Graphics with WebGL
Isaac Gang University of Mary Hardin-Baylor
Introduction to Computer Graphics with WebGL
Projections and Normalization
Introduction to Computer Graphics with WebGL
CSC461: Lecture 19 Computer Viewing
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Projections and Hidden Surface Removal
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
University of New Mexico
Computer Graphics Computer Viewing
Computer Viewing Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Presentation transcript:

1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science Laboratory University of New Mexico Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

2 Computer Viewing Projection Ed Angel Professor Emeritus of Computer Science University of New Mexico Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

3 Objectives Introduce the mathematics of projection Add WebGL projection functions in MV.js Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

4 Projections and Normalization The default projection in the eye (camera) frame is orthogonal For points within the default view volume Most graphics systems use view normalization ­All other views are converted to the default view by transformations that determine the projection matrix ­Allows use of the same pipeline for all views x p = x y p = y z p = 0 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

5 Homogeneous Coordinate Representation x p = x y p = y z p = 0 w p = 1 p p = Mp M = In practice, we can let M = I and set the z term to zero later default orthographic projection Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

6 Simple Perspective Center of projection at the origin Projection plane z = d, d < 0 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

7 Perspective Equations Consider top and side views x p =y p = z p = d Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

8 Homogeneous Coordinate Form M = consider q = Mp where p =  q = Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

9 Perspective Division However w  1, so we must divide by w to return from homogeneous coordinates This perspective division yields the desired perspective equations We will consider the corresponding clipping volume with mat.h functions that are equivalent to deprecated OpenGL functions x p =y p = z p = d Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

10 WebGL Orthogonal Viewing ortho(left,right,bottom,top,near,far) near and far measured from camera Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 negative

11 WebGL Orthogonal Viewing Try “ortho.html” (which uses ortho.js)ortho.htmlortho.js IMPORTANT NOTE : ­In ortho.js, the following lines were modified to show the effect of moving the near and far planes. Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 document.getElementById("Button1").onclick = function () { near += 0.1; far += 0.1; }; // original code-> function(){near *= 1.1; far *= 1.1;}; document.getElementById("Button2").onclick = function () { near -= 0.1; far -= 0.1; }; // original code-> function(){near *= 0.9; far *= 0.9;};

12 WebGL Perspective (frustum not implemented in MV.js) frustum(left,right,bottom,top,near,far) Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015 negative

13 Using Field of View With frustum it is often difficult to get the desired view perpective(fovy, aspect, near, far) often provides a better interface aspect = w/h front plane Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Computing Matrices (see perspective2.html + perspective2.js)perspective2.htmlperspective2.js Compute in JS file, send to vertex shader with gl.uniformMatrix4fv Dynamic: update in render() or shader 14 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

persepctive2.js 15 var render = function(){ gl.clear( gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); eye = vec3(radius*Math.sin(theta)*Math.cos(phi), radius*Math.sin(theta)*Math.sin(phi), radius*Math.cos(theta)); modelViewMatrix = lookAt(eye, at, up); projectionMatrix = perspective(fovy, aspect, near, far); gl.uniformMatrix4fv( modelViewMatrixLoc, false, flatten(modelViewMatrix) ); gl.uniformMatrix4fv( projectionMatrixLoc, false, flatten(projectionMatrix) ); gl.drawArrays( gl.TRIANGLES, 0, NumVertices ); requestAnimFrame(render); } Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

vertex shader 16 attribute vec4 vPosition; attribute vec4 vColor; varying vec4 fColor; uniform mat4 modelViewMatrix; uniform mat4 projectionMatrix; void main() { gl_Position = projectionMatrix*modelViewMatrix*vPosition; fColor = vColor; } Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Try « projection.exe » from the « Tutor » zip file. 17 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009