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
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Part 3: Three Dimensions.
Advertisements

Fractals Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New.
1 CSC461 Lecture 7: 3D Programming in OpenGL Objectives: Develop 2D and 3D examples -- Sierpinski gasket: a fractal Develop 2D and 3D examples -- Sierpinski.
Open Graphics Library (OpenGL)
1 Intro to Computer Graphics CSCI E 72 Jeff Parker, 2013 Based on lectures by Ed Angel © Ed Angel "Hardware: The parts of a computer system that can be.
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 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 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
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.
1Computer Graphics Programming with OpenGL Three Dimensions Lecture 06 John Shearer Culture Lab – space 2
Computer Graphics I, Fall 2010 Programming with OpenGL Part 3: Three Dimensions.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Programming with OpenGL Review.
CS 480/680 Computer Graphics Programming with Open GL Part 6: Three Dimensions Dr. Frederick C Harris, Jr. Fall 2011.
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 Building Models Ed Angel Professor Emeritus of Computer Science University of New Mexico Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley.
User Input and Animation. For Further Reading Angel 7 th Ed: –Chapter 3: Input and Animation. –Chapter 4: Rotation and other transformation. Beginning.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Graphics CSCI 343, Fall 2015 Lecture 5 Color in WebGL.
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.
Vertex Buffer Objects and Shader Attributes. For Further Reading Angel 7 th Ed: –Most parts of Chapter 2. Beginning WebGL: –Chapter 1: vertex Buffer Objects,
Programming with OpenGL Part 0: 3D API. For Further Reading Angel 7 th Ed: –2.2: JavaScript –2.3: OpenGL & WebGL –2.8: fragment & vertex shaders Beginning.
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.
Fractals Ed Angel Professor Emeritus of Computer Science
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 Programming with OpenGL Part 3: Three Dimensions Ed Angel Professor of Computer Science,
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 6: Three Dimensions Ed Angel Professor.
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 ADOPTED from Ed Angel Chapter 2 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015.
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.
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 3: Three Dimensions
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 2: Complete Programs
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
Programming with OpenGL Part 3: Three Dimensions
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
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 6: Three Dimensions
Programming with OpenGL Part 3: Three Dimensions
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Programming with OpenGL Part 3: Three Dimensions
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
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 Programming with WebGL Part 6: Three Dimensions Ed Angel Professor Emeritus of Computer Science University of New Mexico Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

3 Objectives Develop a more sophisticated three- dimensional example ­Sierpinski gasket: a fractal Introduce hidden-surface removal Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

4 Three-dimensional Applications In WebGL, two-dimensional applications are a special case of three-dimensional graphics Going to 3D ­Not much changes ­Use vec3, gl.uniform3f ­Have to worry about the order in which primitives are rendered or use hidden-surface removal Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

5 Sierpinski Gasket (2D) Start with a triangle Connect bisectors of sides and remove central triangle Repeat Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

6 Example Five subdivisions Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

7 The gasket as a fractal Consider the filled area (black) and the perimeter (the length of all the lines around the filled triangles) As we continue subdividing ­the area goes to zero ­but the perimeter goes to infinity This is not an ordinary geometric object ­It is neither two- nor three-dimensional It is a fractal (fractional dimension) object Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

Gasket Program HTML file ­Same as in other examples ­Pass through vertex shader ­Fragment shader sets color ­Read in JS file 8 Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

9 Gasket Program var points = []; var NumTimesToSubdivide = 5; /* initial triangle */ var vertices = [ vec2( -1, -1 ), vec2( 0, 1 ), vec2( 1, -1 ) ]; divideTriangle( vertices[0],vertices[1], vertices[2], NumTimesToSubdivide); Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

10 Draw one triangle /* display one triangle */ function triangle( a, b, c ){ points.push( a, b, c ); } Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

11 Triangle Subdivision function divideTriangle( a, b, c, count ){ // check for end of recursion if ( count === 0 ) { triangle( a, b, c ); } else { //bisect the sides var ab = mix( a, b, 0.5 ); var ac = mix( a, c, 0.5 ); var bc = mix( b, c, 0.5 ); --count; // three new triangles divideTriangle( a, ab, ac, count-1 ); divideTriangle( c, ac, bc, count-1 ); divideTriangle( b, bc, ab, count-1 ); } Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

12 init() var program = initShaders( gl, "vertex- shader", "fragment-shader" ); gl.useProgram( program ); var bufferId = gl.createBuffer(); gl.bindBuffer( gl.ARRAY_BUFFER, bufferId ) gl.bufferData( gl.ARRAY_BUFFER, flatten(points), gl.STATIC_DRAW ); var vPosition = gl.getAttribLocation( program, "vPosition" ); gl.vertexAttribPointer( vPosition, 2, gl.FLOAT, false, 0, 0 ); gl.enableVertexAttribArray( vPosition ); render(); Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015

13 Render Function function render(){ gl.clear( gl.COLOR_BUFFER_BIT ); gl.drawArrays( gl.TRIANGLES, 0, points.length ); } Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley 2015