PROFESSIONAL. WebGL Programming DEVELOPING 3D GRAPHICS FOR THE WEB. Andreas Anyuru WILEY. John Wiley & Sons, Ltd.

Similar documents
Ciril Bohak. - INTRODUCTION TO WEBGL

Models and Architectures

CHAPTER 1 Graphics Systems and Models 3

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

WebGL (Web Graphics Library) is the new standard for 3D graphics on the Web, designed for rendering 2D graphics and interactive 3D graphics.


CS 130 Final. Fall 2015

Introduction to Computer Graphics with WebGL

CS451Real-time Rendering Pipeline

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

Spring 2009 Prof. Hyesoon Kim

Getting fancy with texture mapping (Part 2) CS559 Spring Apr 2017

Graphics Performance Optimisation. John Spitzer Director of European Developer Technology

Pipeline Operations. CS 4620 Lecture 14

Spring 2011 Prof. Hyesoon Kim

The Rasterization Pipeline

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Shaders. Slide credit to Prof. Zwicker

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

GLOBAL EDITION. Interactive Computer Graphics. A Top-Down Approach with WebGL SEVENTH EDITION. Edward Angel Dave Shreiner

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

The Application Stage. The Game Loop, Resource Management and Renderer Design

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

CS 4620 Program 3: Pipeline

CSE4030 Introduction to Computer Graphics

The Rasterizer Stage. Texturing, Lighting, Testing and Blending

CS 130 Exam I. Fall 2015

CS GPU and GPGPU Programming Lecture 2: Introduction; GPU Architecture 1. Markus Hadwiger, KAUST

Rendering Objects. Need to transform all geometry then

2.11 Particle Systems

Pipeline Operations. CS 4620 Lecture 10

Objectives. Introduce the OpenGL shading Methods 1) Light and material functions on MV.js 2) per vertex vs per fragment shading 3) Where to carry out

CSE 167: Lecture #8: Lighting. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

OpenGL SUPERBIBLE. Fifth Edition. Comprehensive Tutorial and Reference. Richard S. Wright, Jr. Nicholas Haemel Graham Sellers Benjamin Lipchak

Mattan Erez. The University of Texas at Austin

Visual HTML5. Human Information Interaction for Knowledge Extraction, Interaction, Utilization, Decision making HI-I-KEIUD

CS 464 Review. Review of Computer Graphics for Final Exam

Module 13C: Using The 3D Graphics APIs OpenGL ES

Working with Metal Overview

ECS 175 COMPUTER GRAPHICS. Ken Joy.! Winter 2014

OpenGl Pipeline. triangles, lines, points, images. Per-vertex ops. Primitive assembly. Texturing. Rasterization. Per-fragment ops.

Introduction to Shaders.

Evolution of GPUs Chris Seitz

Graphics Hardware. Instructor Stephen J. Guy

Whiz-Bang Graphics and Media Performance for Java Platform, Micro Edition (JavaME)

Programming Graphics Hardware

Real - Time Rendering. Pipeline optimization. Michal Červeňanský Juraj Starinský

Practical Texturing (WebGL) CS559 Fall 2016 Lecture 20 November 7th 2016

Computer Graphics Coursework 1

Models and Architectures. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

CS130 : Computer Graphics. Tamar Shinar Computer Science & Engineering UC Riverside

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

DEFERRED RENDERING STEFAN MÜLLER ARISONA, ETH ZURICH SMA/

Programming Guide. Aaftab Munshi Dan Ginsburg Dave Shreiner. TT r^addison-wesley

CS 498 VR. Lecture 19-4/9/18. go.illinois.edu/vrlect19

Illumination and Shading

Rasterization Overview

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Lecture 2. Shaders, GLSL and GPGPU

CSE 167: Introduction to Computer Graphics Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

GPU Memory Model. Adapted from:

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

GPU Memory Model Overview

Computer Science 175. Introduction to Computer Graphics lib175 time: m/w 2:30-4:00 pm place:md g125 section times: tba

Shading and Texturing Due: Friday, Feb 17 at 6:00pm

Coding OpenGL ES 3.0 for Better Graphics Quality

CS 418: Interactive Computer Graphics. Basic Shading in WebGL. Eric Shaffer

CS450/550. Pipeline Architecture. Adapted From: Angel and Shreiner: Interactive Computer Graphics6E Addison-Wesley 2012

Grafica Computazionale: Lezione 30. Grafica Computazionale. Hiding complexity... ;) Introduction to OpenGL. lezione30 Introduction to OpenGL

Computer Graphics 1. Chapter 7 (June 17th, 2010, 2-4pm): Shading and rendering. LMU München Medieninformatik Andreas Butz Computergraphik 1 SS2010

Blue colour text questions Black colour text sample answers Red colour text further explanation or references for the sample answers

Shading. Shading = find color values at pixels of screen (when rendering a virtual 3D scene).

Rationale for Non-Programmable Additions to OpenGL 2.0

1.2.3 The Graphics Hardware Pipeline

Chapter Answers. Appendix A. Chapter 1. This appendix provides answers to all of the book s chapter review questions.

BCA611 Video Oyunları için 3B Grafik

I expect to interact in class with the students, so I expect students to be engaged. (no laptops, smartphones,...) (fig)

Free Downloads OpenGL ES 3.0 Programming Guide

Optimizing Games for ATI s IMAGEON Aaftab Munshi. 3D Architect ATI Research

Computer Graphics I Lecture 11

Chapter IV Fragment Processing and Output Merging. 3D Graphics for Game Programming

EE 4702 GPU Programming

Could you make the XNA functions yourself?

Game Graphics & Real-time Rendering

Deferred Rendering Due: Wednesday November 15 at 10pm

CS GPU and GPGPU Programming Lecture 12: GPU Texturing 1. Markus Hadwiger, KAUST

OpenGL Programmable Shaders

- Location: Annenberg Text: Mostly Self-Contained on course Web pages. - Al Barr

Mattan Erez. The University of Texas at Austin

Introduction to Visualization and Computer Graphics

CS427 Multicore Architecture and Parallel Computing

COMP371 COMPUTER GRAPHICS

Rasterization-based pipeline

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

Blis: Better Language for Image Stuff Project Proposal Programming Languages and Translators, Spring 2017

Transcription:

PROFESSIONAL WebGL Programming DEVELOPING 3D GRAPHICS FOR THE WEB Andreas Anyuru WILEY John Wiley & Sons, Ltd.

INTRODUCTION xxl CHAPTER 1: INTRODUCING WEBGL 1 The Basics of WebGL 1 So Why Is WebGL So Great? 2 Designing a Graphics API 3 An Immediate-Mode API 3 A Retained-Mode API 4 An Overview of Graphics Hardware 4 GPU 5 Framebuffer 5 Texture Memory 7 Video Controller 7 Understanding the WebGL Graphics Pipeline 7 Vertex Shader 8 Primitive Assembly 12 Rasterization 14 FragmentShader 14 Per Fragment Operations 17 Comparing WebGL to Other Graphics Technologies 19 OpenGL 19 OpenGL ES 2.0 21 Direct3D 23 HTML5 Canvas 24 Scalable Vector Graphics 28 VRML and X3D 30 Linear Algebra for 3D Graphics 31 Coordinate System 31 Points or Vertices 31 Vectors 32 Dot Product or Scalar Product 33 Cross Product 34 Homogeneous Coordinates 35 Matrices 35 Affine Transformations 38 Summary 44

CHAPTER 2: CREATING BASIC WEBGL EXAMPLES 45 Drawing a Triangle Creating the WebGL Context Creating the Vertex Shader and the Fragment Shader Compiling the Shaders Creating the Program Object and Linking the Shaders Setting Up the Buffers Drawing the Scene Understanding the WebGL Coding Style Debugging Your WebGL Application Using Chrome Developer Tools Using Firebug WebGL Error Handling and Error Codes WebGL Inspector Troubleshooting WebGL Using the DOM API to Load Your Shaders Putting It Together in a Slightly More Advanced Example Experimenting with Code Summary CHAPTER 3: DRAWING WebGL Drawing Primitives and Drawing Methods Primitives Understanding the Importance of Winding Order WebGL's Drawing Methods Typed Arrays Buffer and View Supported View Types Exploring Different Ways to Draw gl.drawarrays() and gl.triangles gl.drawarraysq and gl.triangle_strip gl.drawelementsq and gl.triangles gl.drawelementso and gl.triangle_strip Conclusions of the Comparison Pre-Transform Vertex Cache and Post-Transform Vertex Cache Interleaving Your Vertex Data for Improved Performance Using an Array of Structures Using a Vertex Array or Constant Vertex Data A Last Example to Wind Things Up Some Things to Experiment With Summary 46 49 51 52 53 54 56 57 58 58 65 67 70 76 78 80 83 84 85 86 86 91 93 99 100 101 102 103 105 106 108 111 111 114 115 123 124 134 134

CHAPTER 4: COMPACT JAVASCRIPT LIBRARIES AND TRANSFORMATIONS 137 Working with Matrices and Vectors in JavaScript 138 Sylvester 139 WebGL-mjs 142 gimatrix 146 Using Transformations 150 How Transformations Are Used 150 Understanding the Complete Transformation Pipeline 157 Getting Practical with Transformations 158 Setting Up Buffers with Object Coordinates 159 Creating Transformation Matrices with JavaScript and Uploading Them to the Shader 160 Uploading the Transformation Matrices to the Vertex Shader in the GPU 161 Calling Your Drawing Methods 162 Understanding the Importance of Transformation Order 162 Using a Grand, Fixed Coordinate System 163 Using a Moving, Local Coordinate System 165 Pushing and Popping Transformation Matrices 167 A Complete Example: Drawing Several Transformed Objects 171 Creating a Cube with WebGL 173 Organization of the View Transformation and the Model Transformation 175 Summary 176 CHAPTER 5: TEXTURING 177 Understanding Lost Context 178 Understanding the Setup Required to Handle Lost Context 179 Factors to Consider When Handling Lost Context 181 Introducing 2D Textures and Cubemap Textures 183 Loading Your Textures 185 Creating a WebGLTexture Object 185 Binding Your Texture 185 Loading the Image Data 186 Uploading the Texture to the GPU 187 Specifying Texture Parameters 189 Understanding the Complete Procedure of Loading a Texture 190 Defining Your Texture Coordinates 193 xvii

Using Your Textures in Shaders 195 Working with Texture Image Units 197 Working with Texture Filtering 198 Understanding Magnification 199 Understanding Minification 200 Understanding Mipmapping 200 Understanding Texture Coordinate Wrapping 203 Using the gl.repeat Wrap Mode 203 Using the gl.mirrored_repeat Wrap Mode 205 Using the gl.clamp_to_edge Wrap Mode 206 A Complete Texture Example 207 Using Images for Your Textures 210 Downloading Free Textures 210 Basing Textures on Your Own Photos 211 Drawing Images 211 Buying Textures 211 Understanding Same-Origin Policy and Cross-Origin Resource Sharing 212 Understanding Same-Origin Policy for Images in General 212 Understanding Same-Origin Policy for Textures 214 Understanding Cross-Origin Resource Sharing 215 Summary 217 CHAPTER 6: ANIMATIONS AND USER INPUT 219 Animating the Scene 219 Using setlnterval() and settimeout() 221 Using requestanimationframe() 222 Compensating Movement for Different Frame Rates 225 Creating an FPS Counter to Measure the Smoothness of Your Animation 226 Understanding the Disadvantages of Using FPS as a Measurement 228 Event Handling for User Interaction 230 Basic Event Handling with DOM Level 0 231 Advanced Event Handling with DOM Level 2 232 Key Input 234 Mouse Input 239 Applying Your New Knowledge 240 Summary 246 CHAPTER 7: LIGHTING 249 Understanding Light 249 Working with a Local Lighting Model 250 xviii

Understanding the Phong Reflection Model 251 Ambient Reflection 252 Diffuse Reflection 253 Specular Reflection 255 Understanding the Complete Equation and Shaders for the Phong Reflection Model 259 Using Lighting with Texturing 263 Understanding the JavaScript Code Needed for WebGL Lighting 267 Setting Up Buffers with Vertex Normals 268 Calculating and Uploading the Normal Matrix to the Shader 270 Uploading the Light Information to the Shader 270 Using Different Interpolation Techniques for Shading 271 Flat Shading 272 Gouraud Shading 273 Phong Shading 274 Understanding the Vectors That Must Be Normalized 278 Normalization in the Vertex Shader 278 Normalization in the Fragment Shader 279 Using Different Types of Lights 279 Directional Lights 280 Point Lights 280 Spot Lights 281 Understanding the Attenuation of Light 284 Understanding Light Mapping 288 Summary 289 CHAPTER 8: WEBGL PERFORMANCE OPTIMIZATIONS 291 WebGL under the Hood 292 Hardware that Powers WebGL 292 Key Software Components 294 WebGL Performance Optimizations 296 Avoiding a Typical Beginner's Mistake 296 Locating the Bottleneck 298 General Performance Advice 302 Performance Advice for CPU-Limited WebGL 305 Performance Advice for Vertex-Limited WebGL 307 Performance Advice for Pixel-Limited WebGL 308 A Closer Look at Blending 310 Introducing Blending 310 Setting the Blending Functions 311

Understanding Drawing Order and the Depth Buffer 314 Drawing a Scene with Both Opaque and Semi-Transparent Objects 315 Changing the Default Operator for the Blend Equation 315 Using Premultiplied Alpha 316 Taking WebGL Further 317 Using WebGL Frameworks 317 Publishing to the Google Chrome Web Store 318 Using Additional Resources 318 Summary 319 INDEX 321