Let your WebGL program dance

Slides:



Advertisements
Similar presentations
HbbTV Hybrid broadcast broadband TV EBU / ETSI Hybrid Broadcast Broadband Workshop Amsterdam, 9 th September, 2009.
Advertisements

An introduction to WebGL Viktor Kovács. Content A little 3D modeling. What is WebGL? Introducing Three.js. Visualizing GDL objects.
Real-time Dynamic HDR Based Lighting in a Static Environment Marcus Hennix Daniel Johansson Gunnar Johansson Martin Wassborn.
FUNDAMENTALS OF PROGRAMMING SM1204 Semester A 2010/2011.
Video Object Tracking and Replacement for Post TV Production LYU0303 Final Year Project Spring 2004.
CS-557 Gregory Dudek CD Contents. CS-557 Gregory Dudek Course description Lecture schedule by week 1997 Image Gallery Assignments Page Morphing Notes.
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.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
FUNDAMENTALS OF PROGRAMMING SM1204 SEMESTER A 2012.
Control Systems An Overview. Definition A control system is a device or set of devices that are coordinated to execute a planned set of actions.
CNIT 133 Interactive Web Pags – JavaScript and AJAX JavaScript Environment.
Introduction to Alice Alice is named in honor of Lewis Carroll’s Alice in Wonderland.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
UX design for Google Glass Alena Kovárová PeWe Seminar
1 Graphics CSCI 343, Fall 2015 Lecture 1 Introduction to Graphics Read: Chapter 1 of textbook.
Funativity CS 426 Fall Team Members David Smits – Lead Chintan Patel – Programmer Jim Gagliano – Programmer Ashleigh Wiatrowski - Artist.
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 2 Introduction to HTML, JavaScript and WebGL.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
AJAX Compiled from “AJAX Programming” [Sang Shin] (Asynchronous JavaScript and XML)
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Introduction to Alice Alice is named in honor of Lewis Carroll’s Alice in Wonderland.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
1 Graphics CSCI 343, Fall 2015 Lecture 3 Introduction to WebGL.
CompSci Introduction to Jam’s Video Game Package.
Attack of the Clones Image source:
Event Handling & AJAX IT210 Web Systems. Question How do we enable users to dynamically interact with a website? Answer: Use mouse and keyboard to trigger.
3D Objects in WebGL Loading 3D model files. Announcement Midterm exam on 12/2 –No Internet connection. –Example code and exam questions will be on USB.
Mouse Input. For Further Reading Learning WebGL, Lesson 11: 2.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Web Audio API Let your WebGL program dance. Announcement Final project proposal due in one week. Choice of demo date? Plan for the 12/23 class. 2.
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 of Scratch (1/4) You can find Scratch on the Web:
Lecture 8: Discussion of papers OpenGL programming Lecturer: Simon Winberg Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
What is DirectX? DirectX is built by Microsoft as a collection of API’s (Application Programming Interfaces) for the purpose of multimedia processing.
MPEG-4 Binary Information for Scenes (BIFS)
Video on the Web.
AJAX and jQuery AJAX AJAX Concepts, XMLHttpRequest, jQuery AJAX: $.ajax(), $.get(), $.post() jQuery AJAX XMLHttpRequest SoftUni Team Technical Trainers.
Introduction to Computer Graphics with WebGL
Understand Windows Forms Applications and Console-based Applications
Introduction to Computer Graphics with WebGL
HbbTV Hybrid broadcast broadband TV
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Continuous - Discrete Sampling Demo (CON2DIS) team
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 Alice Alice is named in honor of
Introduction to Computer Graphics with WebGL
…Dedicated Micros has introduced a new Entry-Level DVR.
Introduction to HTML5 and WebSockets.
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
A guide to Humanities A/B Created by: Ms. Miller
Today’s Objectives Week 12 Announcements ASP.NET
Introduction to Computer Graphics with WebGL
Javascript and JQuery SRM DSC.
Interactive media.
Introduction to Computer Graphics with WebGL
03 | Creating, Texturing and Moving Objects
Mouse Input.
Web Programming and Design
Web Programming and Design
OpenGL-Rendering Pipeline
Introduction to WebGL 3D with HTML5 and Babylon.js
Engine and functionalities
Presentation transcript:

Let your WebGL program dance Web Audio API Let your WebGL program dance

Announcement Final project proposal due in one week. Demo on Jan. 16, 2017.

Final Projects Individual or Team of 2. Voting during the demo. Do NOT use THREE.js Themes for this semester: Interactive Art in WebGL Animating objects with changing colors, positions, shapes, …etc. Interacts with mouse input, audio input (music), or gyro input.

Win Me

Possible Interactions Input: Mouse, keyboard, gyroscope Audio Video or camera? Output – changing the following Size, number, position, color, texture, …etc. Viewpoint Lighting

For Further Reading Web Audio API: Watch out for deprecated functions: Good introduction at: http://www.html5rocks.com/en/tutorials/webaudio/intro/ More information on the frequency analyzer: http://srchea.com/experimenting-with-web-audio-api-three-js-webgl Watch out for deprecated functions: e.g., createJavaScriptNode() replaced by createScriptProcessor()

WEB AUDIO

Loading the Music: Option #1 Option #1: <audio> element in HTML The following code produces an audio element with playback controls. <button id="xButton">Rotate X</button> <button id="yButton">Rotate Y</button> <button id="zButton">Rotate Z</button> <br/> <button id="pButton" ...>Pause</button> <button id="dButton" ...>Depth Test</button> <audio id="myAudio" src="Sleep Away.mp3" controls></audio>

A Simple Player // Experimenting with HTML5 audio var context = new AudioContext(); var audio = document.getElementById('myAudio'); var audioSrc = context.createMediaElementSource(audio); audioSrc.connect(context.destination); audio.play(); Source: https://www.html5rocks.com/en/tutorials/webaudio/intro/

Adding Frequency Analyzer var context = new AudioContext(); var audio = document.getElementById('myAudio'); var audioSrc = context.createMediaElementSource(audio); var sourceJs = context.createScriptProcessor(2048); analyser = context.createAnalyser(); analyser.smoothingTimeConstant = 0.6; analyser.fftSize = 512; // Connect the MediaElementSource with the analyser audioSrc.connect(analyser); analyser.connect(sourceJs); sourceJs.buffer = audioSrc.buffer; sourceJs.connect(context.destination); audioSrc.connect(context.destination);

sourceJs.onaudioprocess = function(e) { // frequencyBinCount: how many values from the analyser frequencyData = new Uint8Array( analyser.frequencyBinCount); analyser.getByteFrequencyData( frequencyData ); }; Source: https://www.html5rocks.com/en/tutorials/webaudio/intro/

Visualization function render() { ... // update data in frequencyData analyser.getByteFrequencyData(frequencyData); // render frame based on values in frequencyData gl.uniform1f( volumeLoc, frequencyData[160] / 255 ); gl.drawArrays( gl.TRIANGLES, 0, numVertices ); requestAnimFrame( render ); }

Loading the Music: Option #2 Option #2: XMLHttpRequest() in JS loadSound("your_song.mp3"); function loadSound(url) { var request = new XMLHttpRequest(); request.open('GET', url, true); request.responseType = 'arraybuffer'; // When loaded decode the data request.onload = function() { context.decodeAudioData( request.response, ... ... } request.send();

Lab Time! Download cube3_music.zip Change frequencyData[160] to other entry. How does it respond to the music? Uncomment console.log(frequencyData) What do you see in the console? How about visualizing the whole array of frequencyData[0..255]?

Attack of the Clones Image source: https://en.wikipedia.org/wiki/File:Imperialmarch.jpg

Clones of the Cube

5x5x5 Array of Cubes (JS code) function render() { ... gl.uniformMatrix4fv( viewingLoc, 0, flatten(viewing) ); gl.uniformMatrix4fv( projectionLoc, 0, flatten(projection) ); gl.uniformMatrix4fv( lightMatrixLoc,0, flatten(moonRotationMatrix) ); for (i=-2; i<=2; i++) { for (j=-2; j<=2; j++) { for (k=-2; k<=2; k++) { var cloned = mult(modeling, mult( translate(0.2*i, 0.2*j, 0.2*k), scale(0.12, 0.12, 0.12))); gl.uniformMatrix4fv( modelingLoc, 0, flatten(cloned) ); gl.drawArrays( gl.TRIANGLES, 0, numVertices ); }

MV.Js bug Two versions of scale() in MV.js function Scale( x, y, z ) function Scale( s, u ) The solution is rename scale(s, u).

Lab Time! Uncomment the line that sets “var cloned” and see what happens. Create more cube! How about 10x10x10? 100x100x100? Can your PC handle them? Can you display 5x5x5 cows using the OBJViewer example of last week? How about using different colors for the cubes? Passing different color attributes to the shaders? How about changing the colors directly within the shaders?