Book Image

WebGL Beginner's Guide

Book Image

WebGL Beginner's Guide

Overview of this book

WebGL is a new web technology that brings hardware-accelerated 3D graphics to the browser without installing additional software. As WebGL is based on OpenGL and brings in a new concept of 3D graphics programming to web development, it may seem unfamiliar to even experienced Web developers.Packed with many examples, this book shows how WebGL can be easy to learn despite its unfriendly appearance. Each chapter addresses one of the important aspects of 3D graphics programming and presents different alternatives for its implementation. The topics are always associated with exercises that will allow the reader to put the concepts to the test in an immediate manner.WebGL Beginner's Guide presents a clear road map to learning WebGL. Each chapter starts with a summary of the learning goals for the chapter, followed by a detailed description of each topic. The book offers example-rich, up-to-date introductions to a wide range of essential WebGL topics, including drawing, color, texture, transformations, framebuffers, light, surfaces, geometry, and more. With each chapter, you will "level up"ù your 3D graphics programming skills. This book will become your trustworthy companion filled with the information required to develop cool-looking 3D web applications with WebGL and JavaScript.
Table of Contents (18 chapters)
WebGL Beginner's Guide
Credits
About the Authors
Acknowledgement
About the Reviewers
www.PacktPub.com
Preface
Index

More on lights: positional lights


Before we finish the chapter, let's revisit the topic of lights. So far we have assumed that our light source is infinitely far away from the scene. This assumption allows us to model the light rays as being parallel to each other. An example of this is sunlight. These lights are called directional lights; now we are going to consider the case where the light source is relatively close to the object that it is going to illuminate. Think, for example, of a lamp desk illuminating the document you are reading. These lights are called positional lights.

As we experienced before, when working with directional lights, only one variable is required. This is the light direction that we have represented in the uniform uLightDirection.

Contrastingly, when working with positional lights, we need to know the location of the light. We can represent it using a uniform that we will name uLightPosition. As when using positional lights, the light rays are not parallel to each...