Packt+ | Advance your knowledge in tech (2024)

Table of Contents (18) Chapters

WebGL Beginner's Guide

    Credits

      About the Authors

        Acknowledgement

          About the Reviewers

            www.PacktPub.com

              Preface

                1. Getting Started with WebGL

                • System requirements
                • What kind of rendering does WebGL offer?
                • Structure of a WebGL application
                • Creating an HTML5 canvas
                • Time for action – creating an HTML5 canvas
                • Accessing a WebGL context
                • Time for action – accessing the WebGL context
                • WebGL is a state machine
                • Time for action – setting up WebGL context attributes
                • Loading a 3D scene
                • Time for action – visualizing a finished scene
                • Summary

                2. Rendering Geometry

                • Vertices and Indices
                • Overview of WebGL's rendering pipeline
                • Rendering geometry in WebGL
                • Putting everything together
                • Time for action – rendering a square
                • Rendering modes
                • Time for action – rendering modes
                • WebGL as a state machine: buffer manipulation
                • Time for action – enquiring on the state of buffers
                • Advanced geometry loading techniques: JavaScript Object Notation (JSON) and AJAX
                • Time for action – JSON encoding and decoding
                • Time for action – loading a cone with AJAX + JSON
                • Summary

                3. Lights!

                • Lights, normals, and materials
                • Using lights, normals, and materials in the pipeline
                • Shading methods and light reflection models
                • ESSL—OpenGL ES Shading Language
                • Writing ESSL programs
                • Time for action – updating uniforms in real time
                • Time for action – Goraud shading
                • Time for action – Phong shading with Phong lighting
                • Back to WebGL
                • Bridging the gap between WebGL and ESSL
                • Time for action – working on the wall
                • More on lights: positional lights
                • Time for action – positional lights in action
                • Summary

                4. Camera

                • WebGL does not have cameras
                • Vertex transformations
                • Normal transformations
                • WebGL implementation
                • The Model-View matrix
                • The Camera matrix
                • Time for action – exploring translations: world space versus camera space
                • Time for action – exploring rotations: world space versus camera space
                • Basic camera types
                • Time for action – exploring the Nissan GTX
                • The Perspective matrix
                • Time for action – orthographic and perspective projections
                • Structure of the WebGL examples
                • Summary

                5. Action

                • Matrix stacks
                • Animating a 3D scene
                • Timing strategies
                • Architectural updates
                • Connecting matrix stacks and JavaScript timers
                • Time for action – simple animation
                • Parametric curves
                • Time for action – bouncing ball
                • Optimization strategies
                • Interpolation
                • Time for action – interpolation
                • Summary

                6. Colors, Depth Testing, and Alpha Blending

                • Using colors in WebGL
                • Use of color in objects
                • Time for action – coloring the cube
                • Use of color in lights
                • Architectural updates
                • Time for action – adding a blue light to a scene
                • Time for action – adding a white light to a scene
                • Time for action – directional point lights
                • Use of color in the scene
                • Depth testing
                • Alpha blending
                • Time for action – blending workbench
                • Creating transparent objects
                • Time for action – culling
                • Time for action – creating a transparent wall
                • Summary

                7. Textures

                • What is texture mapping?
                • Creating and uploading a texture
                • Using texture coordinates
                • Using textures in a shader
                • Time for action – texturing the cube
                • Texture filter modes
                • Time for action – trying different filter modes
                • Texture wrapping
                • Time for action – trying different wrap modes
                • Using multiple textures
                • Time for action – using multitexturing
                • Cube maps
                • Time for action – trying out cube maps
                • Summary

                8. Picking

                • Picking
                • Setting up an offscreen framebuffer
                • Assigning one color per object in the scene
                • Rendering to an offscreen framebuffer
                • Clicking on the canvas
                • Reading pixels from the offscreen framebuffer
                • Looking for hits
                • Processing hits
                • Architectural updates
                • Time for action – picking
                • Implementing unique object labels
                • Time for action – unique object labels
                • Summary

                9. Putting It All Together

                • Creating a WebGL application
                • Architectural review
                • Virtual Car Showroom application
                • Defining what the GUI will look like
                • Implementing the shaders
                • Setting up the scene
                • Configuring some WebGL properties
                • Loading the cars
                • Rendering
                • Time for action – customizing the application
                • Summary

                10. Advanced Techniques

                • Post-processing
                • Architectural updates
                • Time for action – testing some post-process effects
                • Point sprites
                • Time for action – using point sprites to create a fountain of sparks
                • Normal mapping
                • Time for action – normal mapping in action
                • Ray tracing in fragment shaders
                • Time for action – examining the ray traced scene
                • Summary

                Index

                  Chapter1.Getting Started with WebGL

                  In 2007, Vladimir Vukicevic, an American-Serbian software engineer, began working on an OpenGL prototype for the then upcoming HTML <canvas> element which he called Canvas 3D. In March, 2011, his work would lead Kronos Group, the nonprofit organization behind OpenGL, to create WebGL: a specification to grant Internet browsers access to Graphic Processing Units (GPUs) on those computers where they were used.

                  WebGL was originally based on OpenGL ES 2.0 (ES standing for Embedded Systems), the OpenGL specification version for devices such as Apple's iPhone and iPad. But as the specification evolved, it became independent with the goal of providing portability across various operating systems and devices. The idea of web-based, real-time rendering opened a new universe of possibilities for web-based 3D environments such as videogames, scientific visualization, and medical imaging. Additionally, due to the pervasiveness of web browsers, these and other kinds of 3D applications could be taken to mobile devices such as smart phones and tablets. Whether you want to create your first web-based videogame, a 3D art project for a virtual gallery, visualize the data from your experiments, or any other 3D application you could have in mind, the first step will be always to make sure that your environment is ready.

                  In this chapter, you will:

                  • Understand the structure of a WebGL application

                  • Set up your drawing area (canvas)

                  • Test your browser's WebGL capabilities

                  • Understand that WebGL acts as a state machine

                  • Modify WebGL variables that affect your scene

                  • Load and examine a fully-functional scene

                  Previous Section

                  Section 1 of 13

                  Next Section

                  Packt+ | Advance your knowledge in tech (2024)

                  FAQs

                  What does Packt do? ›

                  Packt's mission is to help the world put software to work through the delivery of effective learning and information services.

                  How do I cancel my Packt subscription? ›

                  To cancel your trial go to My Account and under My Subscription click the 'Cancel Subscription' button below plan expiration date See the example below. We might ask you the reason you ​wish to cancel. This is so we can understand the kind of features and content we might be missing.

                  What is packt Birmingham S? ›

                  Packt is a publishing company founded in 2003 and headquartered in Birmingham, UK, with offices in Mumbai, India.

                  Who is the CEO of Packt? ›

                  Dave Maclean (@davemaclean) / X. CEO and Founder Packt. Every company is, or soon will be a tech company.

                  What services are like Packt? ›

                  • monday.com.
                  • Connecteam.
                  • Zendesk Suite.
                  • Freshdesk.
                  • LiveAgent.

                  How do I quit a subscription? ›

                  To cancel an unused prepaid subscription plan:
                  1. On your Android device, go to subscriptions on Google Play.
                  2. Select the subscription or prepaid plan you want to cancel.
                  3. Tap Cancel subscription.
                  4. Follow the on-screen instructions.

                  What does cancel my subscription mean? ›

                  A person who cancels their subscription is someone who has decided to terminate their ongoing subscription to a service or product.

                  How do I cancel a subscription charge? ›

                  One solution is to send letters revoking your authorization to the subscription company and your bank. Some banks offer ready-made online forms to help you do so. Another way is to give your bank a stop payment order in person, over the phone, or in writing.

                  What payment methods does Packtpub use? ›

                  Click Update Card Details and you'll be given the choice of paying by PayPal or by debit/credit card. If you have any difficulties in getting your preferred payment method working then please let us know - we'd be happy to help!

                  What is the address of Packt? ›

                  PACKT PUBLISHING PRIVATE LIMITED's Corporate Identification Number (CIN) is U22100MH2005PTC152766. You can contact them by sending an email to financedesk@packtpub.com or visit them at their registered address PLOT NO 103 3RD FLOOR ARENA HOUSE 12TH ROAD MIDC ANDHERI EAST MUMBAI Mumbai City MH IN 400093.

                  What is the turnover of Packt Publishing? ›

                  Packt Publishing Private Limited's operating revenues range is INR 1 cr - 100 cr for the financial year ending on 31 March, 2022.

                  Who are Packt Publishing competitors? ›

                  Packt Publishing Ltd.'s primary competitors are O'Reilly, Udemy, Pluralsight and 15 more.

                  What is the revenue of Packt Publishing? ›

                  What is the annual revenue of Packt? The Packt annual revenue was $29.9 million in 2024.

                  Top Articles
                  Latest Posts
                  Article information

                  Author: Chrissy Homenick

                  Last Updated:

                  Views: 5711

                  Rating: 4.3 / 5 (74 voted)

                  Reviews: 81% of readers found this page helpful

                  Author information

                  Name: Chrissy Homenick

                  Birthday: 2001-10-22

                  Address: 611 Kuhn Oval, Feltonbury, NY 02783-3818

                  Phone: +96619177651654

                  Job: Mining Representative

                  Hobby: amateur radio, Sculling, Knife making, Gardening, Watching movies, Gunsmithing, Video gaming

                  Introduction: My name is Chrissy Homenick, I am a tender, funny, determined, tender, glorious, fancy, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.