Interactive Computer Graphics CS 418 – Fall 2017

Slides:



Advertisements
Similar presentations
SE 313 – Computer Graphics Lecture 13: Lighting and Materials Practice Lecturer: Gazihan Alankuş 1.
Advertisements

 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.
Particle Systems Final Exam Study Guide Game Design Experience Professor Jim Whitehead March 16, 2009 Creative Commons Attribution 3.0 (Except copyrighted.
WebGL: a New Platform for 3D Games Advanced Games Programming by Jarek Francik 2011.
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
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.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
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.
CS 418: Interactive Computer Graphics Introduction to WebGL: HelloTriangle.html Eric Shaffer.
1 k Jarek Rossignac,  2008 Processing  Install Processing  Learn how to edit, run, save, export, post programs  Understand.
WebGL: in-browser 3D graphics Nick Whitelegg Maritme and Technology Faculty Southampton Solent University.
Interactive Computer Graphics CS 418 – Spring 2015 TA: Zhicheng Yan, Sushma S Kini, Mary Pietrowicz Originally created by Mahsa Kamali.
CS 450: COMPUTER GRAPHICS PORTRAIT OF AN OPENGL PROGRAM SPRING 2015 DR. MICHAEL J. REALE.
Interactive Computer Graphics CS 418 – Spring 2015 Mesh Rendering, Transformation, Camera Viewing and Projection in OpenGL TA: Zhicheng Yan Sushma S Kini.
ISC/GAM 4322 ISC 6310 Multimedia Development and Programming Introduction.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
به نام خدا تنظیم کننده : فرانه حدادی استاد : مهندس زمانیان تابستان 92.
1 Graphics CSCI 343, Fall 2015 Lecture 2 Introduction to HTML, JavaScript and WebGL.
Lecture 2: Some definitions of terms 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 711,  ex 2271 
OpenGL Shader Language Vertex and Fragment Shading Programs.
1 Graphics CSCI 343, Fall 2015 Lecture 21 Lighting and Shading III.
1 Graphics CSCI 343, Fall 2015 Lecture 5 Color in WebGL.
1 Graphics CSCI 343, Fall 2015 Lecture 3 Introduction to WebGL.
Mesh Skinning Sébastien Dominé. Agenda Introduction to Mesh Skinning 2 matrix skinning 4 matrix skinning with lighting Complex skinning for character.
MP3 Frequently Asked Questions (IN OFFICE HOURS).
A study of efficiency INDEX BUFFERS JEFF CHASTINE 1.
Pushin’ Geo to the GPU As well as colors, normals, and other vertex data Made by Jeff Chastine, Modified by Chao Mei Jeff Chastine.
Development Environment
Essential tools for implementing and testing websites
Interactive Computer Graphics CS 418 – Fall 2017 Indexed Meshes Transformations Background Imagery:
Ying Zhu Georgia State University
Course Information and Introductions
CMSC201 Computer Science I for Majors Lecture 13 – Midterm Review
Graphics CSCI 343, Fall 2017 Lecture 13 More on WebGL
Tips for Shading Your Terrain
Tutorial: How to Creat a Website.
The Basics: HTML5, Drawing, and Source Code Organization
Computer Graphics Index Buffers
Chapter 3 Drawing In the World.
Tips for Environment Mapping
Introduction to OpenGL
CMSC201 Computer Science I for Majors Lecture 27 – Final Exam Review
CS451Real-time Rendering Pipeline
Programming with OpenGL Part 2: Complete Programs
The Canvas.
Getting Started and working with Pearson myautomotivelab
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
Chapter VI OpenGL ES and Shader
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
HW for Computer Graphics
Modeler Help Session CSE 457, Autumn 2007
Introduction to Computer Graphics with WebGL
Accelerated Introduction to Computer Science
ULTRA SESSION PREPARATION KIT
Computer Graphics Module Overview
Please remind your group members to enter quietly.
Modeler Help Session CSE 457, Spring 2008
Debugging Tools Tim Purcell NVIDIA.
Mickaël Sereno Shaders Mickaël Sereno 25/04/2019 Mickaël Sereno -
CS 4722 Computer Graphics and Multimedia Spring 2018
Modeler Help Session CSE 457, Spring 2007
Introduction to Computer Graphics with WebGL
Introduction to OpenGL
Please remind your group members to enter quietly.
Presentation transcript:

Interactive Computer Graphics CS 418 – Fall 2017 TAs: Kartik Agrawal.  Office Hour: Tuesday 2:00-3:00 SC 0207 Bolun Qi. Office Hour: Thursday 12:00-1:00 SC 0207 Xiaofo Yu. Office Hour: Thursday 2:30-3:30 SC 0207 Peiyuan Zhao. Ofc. Hour: Friday 2:00-3:00 SC 0207

Agenda for today Class Information Useful WebGL Programming Resources Programming Meshes Programming Transformations Programming Exercise (get out your laptops)

General Pattern for Discussion Present Information (Useful for Doing MPs) Walk Through Slides Look at Demo Code Do an Exercise (Useful for Doing MPs) Write or Modify Some Code Do a Worksheet Do Pencil & Paper Problems BRING YOUR LAPTOPS!

Other Things We Do in Discussion Exam Review (Useful for Taking Exams) MP Q&A Days (Useful for Doing the MPs)

Piazza For fastest responses to questions www.piazza.com Post questions that might be beneficial to everyone You can also help each other out by answering your classmates’ questions Don’t wait until the night before the exam or the night before the MP is due (!) Send in your questions and ask for help soon!

TA Info Kartik Agrawal. Office Hour: Tuesday 2:00-3:00 SC 0207 Bolun Qi. Office Hour: Thursday 12:00-1:00 SC 0207 Xiaofo Yu. Office Hour: Thursday 2:30-3:30 SC 0207 Peiyuan Zhao. Ofc. Hour: Friday 2:00-3:00 SC 0207

WebGL Resources General Resources Tutorials Google StackOverflow Mozzilla WebGL API reference https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API Tutorials Learning WebGL (http://learningwebgl.com/blog/?page_id=1217) Tutorials Point http://www.tutorialspoint.com/webgl/

Student Graphics @ Illinois UIUC Student Chapter of ACM SIGGRAPH http://www.acm.uiuc.edu/siggraph/ Short Films, Video Games, Graphics Research GameBuilders http://www.acm.uiuc.edu/gamebuilders/ Video Games

Brackets Useful Editor for WebGL http://brackets.io File->Open Folder points Brackets to your code Click on a file to edit it, File->Save to save it To run a WebGL program, click on its html file, then click the lightening bolt

Chrome Development Tools Recommended Development Environment http://www.google.com/chrome Built-in debugging environment within Google Chrome browser Use this to set breakpoints, examine variables, etc. (the usual debugging functions) Check out the chrome devtools overview https://developer.chrome.com/devtools

Tips for success Start Early Write modular code (test progressively) Ask questions early (if it bugs you ask) Avoid long (all night) debug sessions Take breaks during debugging (sleep)

Can You Hack the HelloColor Example? Grab the example from https://courses.engr.illinois.edu/cs418/fa2017/HelloColor.html Can you have it draw 2 triangles?

Mesh Data Structure Here is a data structure which can be used to draw 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 Data Structure: Indexed Face Sets But you can store vertex attributes in one array and face indices in another array (a more efficient way): 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 ]);

Indexed Face Sets: 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, indexBuffer.numberOfItems, 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;

Build the Bridge Between the Shader Program and WebGL 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(shaderProgram); 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

Programming Transformations One way to move geometry is to apply an affine transformation to it. We can encode that transformation using a matrix multiplication The transformation can be implemented in the vertex shader In the JavaScript we create a matrix using the glMatrix library That matrix is then passed to the vertex shader as a Uniform variable Let’s look at the math and the code……

Scaling

Scaling

Translation

Translation

Rotation

Rotation You may also specify rotation about an arbitrary axis…

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=IR T M=ITR

Exercise: Slide 1 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: Slide 2 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: Slide 3 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: Slide 4 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: Slide 5 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();

Programming Exercise Download Brackets if you need an editor Download the demo code bundle from the discussion website, and unzip it Your Mission: Modify the code to display a capital block I instead of an L Make it multi-colored. You could change it to display a gradient from orange to blue, for example. Apply an affine transformation to the colored block I.

Exercise Walk-Through