100% found this document useful (2 votes)
9 views

Beginning WebGL for HTML5 Expert s Voice in Web Development 1st ed. Edition Danchilla download

The document provides information about the book 'Beginning WebGL for HTML5' by Brian Danchilla, which covers essential topics in WebGL development such as shaders, textures, lighting, and physics. It includes details about the book's structure, chapters, and supplementary materials available online. The book is aimed at helping readers create interactive 3D graphics for web applications using HTML5 and WebGL.

Uploaded by

anmonapolyak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
9 views

Beginning WebGL for HTML5 Expert s Voice in Web Development 1st ed. Edition Danchilla download

The document provides information about the book 'Beginning WebGL for HTML5' by Brian Danchilla, which covers essential topics in WebGL development such as shaders, textures, lighting, and physics. It includes details about the book's structure, chapters, and supplementary materials available online. The book is aimed at helping readers create interactive 3D graphics for web applications using HTML5 and WebGL.

Uploaded by

anmonapolyak
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

Beginning WebGL for HTML5 Expert s Voice in Web

Development 1st ed. Edition Danchilla pdf


download

https://ebookfinal.com/download/beginning-webgl-for-html5-expert-
s-voice-in-web-development-1st-ed-edition-danchilla/

Explore and download more ebooks or textbooks


at ebookfinal.com
Here are some recommended products for you. Click the link to
download, or explore more at ebookfinal

Beginning Google Sketchup for 3D Printing Expert s Voice


in 3D Printing 1st ed. Edition Sandeep Singh

https://ebookfinal.com/download/beginning-google-sketchup-
for-3d-printing-expert-s-voice-in-3d-printing-1st-ed-edition-sandeep-
singh/

Foundations of Qt Development Expert s Voice in Open


Source 1st ed. Edition Thelin

https://ebookfinal.com/download/foundations-of-qt-development-expert-
s-voice-in-open-source-1st-ed-edition-thelin/

HTML5 Games Creating Fun with HTML5 CSS3 and WebGL 1st
Edition Jacob Seidelin

https://ebookfinal.com/download/html5-games-creating-fun-with-
html5-css3-and-webgl-1st-edition-jacob-seidelin/

Beginning Information Cards and CardSpace From Novice to


Professional Expert s Voice in Net 1st Edition Marc
Mercuri
https://ebookfinal.com/download/beginning-information-cards-and-
cardspace-from-novice-to-professional-expert-s-voice-in-net-1st-
edition-marc-mercuri/
HTML5 Games 2nd Edition Creating Fun with HTML5 CSS3 and
WebGL Jacob Seidelin

https://ebookfinal.com/download/html5-games-2nd-edition-creating-fun-
with-html5-css3-and-webgl-jacob-seidelin/

Beginning Ubuntu LTS Server Administration From Novice to


Professional Second Edition Expert s Voice in Linux Sander
Van Vugt
https://ebookfinal.com/download/beginning-ubuntu-lts-server-
administration-from-novice-to-professional-second-edition-expert-s-
voice-in-linux-sander-van-vugt/

Beginning Nokia Apps Development Qt and HTML5 for Symbian


and MeeGo 1st Edition Ray Rischpater

https://ebookfinal.com/download/beginning-nokia-apps-development-qt-
and-html5-for-symbian-and-meego-1st-edition-ray-rischpater/

Linux Kernel Networking Implementation and Theory Expert s


Voice in Open Source 1st ed. Edition Rosen

https://ebookfinal.com/download/linux-kernel-networking-
implementation-and-theory-expert-s-voice-in-open-source-1st-ed-
edition-rosen/

HTML5 for Web Designers 1st Edition Jeremy Keith

https://ebookfinal.com/download/html5-for-web-designers-1st-edition-
jeremy-keith/
Beginning WebGL for HTML5 Expert s Voice in Web
Development 1st ed. Edition Danchilla Digital Instant
Download
Author(s): Danchilla, Brian
ISBN(s): 9781430239963, 1430239964
Edition: 1st ed.
File Details: PDF, 9.74 MB
Year: 2012
Language: english
Beginning WebGL
for HTML5

Brian Danchilla
Beginning WebGL for HTML5
Copyright © 2012 by Brian Danchilla
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material
is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting,
reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval,
electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter
developed. Exempted from this legal reservation are brief excerpts in connection with reviews or scholarly
analysis or material supplied specifically for the purpose of being entered and executed on a computer system,
for exclusive use by the purchaser of the work. Duplication of this publication or parts thereof is permitted only
under the provisions of the Copyright Law of the Publisher’s location, in its current version, and permission
for use must always be obtained from Springer. Permissions for use may be obtained through RightsLink at the
Copyright Clearance Center. Violations are liable to prosecution under the respective Copyright Law.
ISBN-13 978-1-4302-3996-3
ISBN-13 978-1-4302-3997-0 (eBook)
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial
fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are
not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material
contained herein.
President and Publisher: Paul Manning
Lead Editor: Ben Renow-Clarke
Technical Reviewer: Massimo Nardone
Editorial Board: Steve Anglin, Ewan Buckingham, Gary Cornell, Louise Corrigan, Morgan Ertel, Jonathan
Gennick, Jonathan Hassell, Robert Hutchinson, Michelle Lowman, James Markham, Matthew
Moodie, Jeff Olson, Jeffrey Pepper, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft,
Gwenan Spearing, Matt Wade, Tom Welsh
Coordinating Editor: Jennifer Blackwell, Anamika Panchoo
Copy Editor: Nancy Sixsmith
Compositor: SPi Global
Indexer: SPi Global
Artist: SPi Global
Cover Designer: Anna Ishchenko
Distributed to the book trade worldwide by Springer Science + Business Media New York, 233 Spring Street, 6th
Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348–4505, e-mail orders-ny@springer-sbm.com,
or visit www.springeronline.com.
For information on translations, please e-mail rights@apress.com, or visit www.apress.com.
Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use.
eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk
Sales–eBook Licensing web page at www.apress.com/bulk-sales.
Any source code or other supplementary materials referenced by the author in this text is available to readers at
www.apress.com. For detailed information about how to locate your book’s source code, go to
www.apress.com/source-code.
For Tressa, as fierce as she is delicate.
Contents at a Glance

About the Author .......................................................................................................... xv


About the Technical Reviewer ..................................................................................... xvi
Acknowledgments ...................................................................................................... xvii
Introduction ............................................................................................................... xviii

N Chapter 1: Setting the Scene .......................................................................................1


N Chapter 2: Shaders 101 .............................................................................................33
N Chapter 3: Textures and Lighting...............................................................................57
N Chapter 4: Increasing Realism ..................................................................................85
N Chapter 5: Physics...................................................................................................115
N Chapter 6: Fractals, Height Maps, and Particle Systems.........................................139
N Chapter 7: Three.js Framework ...............................................................................173
N Chapter 8: Productivity Tools ..................................................................................205
N Chapter 9: Debugging and Performance..................................................................233
N Chapter 10: Effects, Tips, and Tricks .......................................................................267
N Afterword: The Future of WebGL ..............................................................................299

N Appendix A: Essential HTML5 and JavaScript .........................................................303


N Appendix B: Graphics Refresher ..............................................................................309
N Appendix C: WebGL Spec. Odds and Ends................................................................315
N Appendix D: Additional Resources ..........................................................................317
N Index........................................................................................................................323

iv
Contents

About the Author .......................................................................................................... xv


About the Technical Reviewer ..................................................................................... xvi
Acknowledgments ...................................................................................................... xvii
Introduction ............................................................................................................... xviii

N Chapter 1: Setting the Scene .......................................................................................1


A Blank Canvas....................................................................................................................... 1
Getting Context ....................................................................................................................... 2
WebGL Components ............................................................................................................... 4
The Drawing Buffers ...................................................................................................................................... 4
Primitive Types .............................................................................................................................................. 5
Vertex Data .................................................................................................................................................... 6

Rendering in Two Dimensions ................................................................................................ 8


The View: Part I..................................................................................................................... 16
Clip Coordinates .......................................................................................................................................... 17
Why Manipulate Coordinates? .................................................................................................................... 18
The Viewport ................................................................................................................................................ 18

Adding Color ......................................................................................................................... 20


Animation and Model Movement.......................................................................................... 22
Using requestAnimationFrame .................................................................................................................... 22

The View: Part II.................................................................................................................... 24


Model-View Matrix ...................................................................................................................................... 24

v
N CONTENTS

Three-Dimensional Rendering.............................................................................................. 26
2D Models in a 3D World ............................................................................................................................. 26
An Example with Depth ............................................................................................................................... 28

Summary .............................................................................................................................. 32
N Chapter 2: Shaders 101 .............................................................................................33
Graphics Pipelines ................................................................................................................ 33
Fixed Functionality or Programmable Shaders............................................................................................ 33
Why Shaders?.............................................................................................................................................. 34
The WebGL Graphics Pipeline ...................................................................................................................... 34

GL Shading Language .......................................................................................................... 35


Background ................................................................................................................................................. 35
Shader Roles ............................................................................................................................................... 36

Basic Usage.......................................................................................................................... 37
Setting Up a Shader Program ...................................................................................................................... 37
Clean Up ...................................................................................................................................................... 38
Loading Shaders with Ajax .......................................................................................................................... 39

GLSL Specification in More Detail ........................................................................................ 42


Primitive Types ............................................................................................................................................ 42
Qualifiers ..................................................................................................................................................... 42
Built-in Variables ......................................................................................................................................... 44
Built-in Constants ........................................................................................................................................ 44
Vector Components ..................................................................................................................................... 44
Vector and Matrix Operations ...................................................................................................................... 45

Built-in Functions ................................................................................................................. 46


Angle and Trigonometry Functions .............................................................................................................. 46
Exponential Functions ................................................................................................................................. 47
Common Functions ...................................................................................................................................... 47
Geometric Functions.................................................................................................................................... 48
Matrix and Vector Functions ........................................................................................................................ 49
Texture Lookup Functions............................................................................................................................ 50

vi
N CONTENTS

Interactive GLSL Environs..................................................................................................... 50


Procedural Shaders .............................................................................................................. 51
Summary .............................................................................................................................. 56
N Chapter 3: Textures and Lighting...............................................................................57
Textures ................................................................................................................................ 58
Texture Coordinates ..................................................................................................................................... 58
Texture Objects ............................................................................................................................................ 58
texImage2D.................................................................................................................................................. 59
Loading Images into a Texture Object.......................................................................................................... 59
Application and Shader Interaction ............................................................................................................. 61
Using a Texture in Our Shader ..................................................................................................................... 61

Texture Options .................................................................................................................... 62


Texture Filtering ........................................................................................................................................... 62
Texture Wrapping ......................................................................................................................................... 63
Data Storage ................................................................................................................................................ 64
Mipmaps ...................................................................................................................................................... 65

Texturing a 3D Object ........................................................................................................... 66


Texture Coordinate Attribute ........................................................................................................................ 66
Adjusting Our Shaders ................................................................................................................................. 67
Data Changes .............................................................................................................................................. 68

Toggling State ...................................................................................................................... 70


Toggling Textures On and Off ....................................................................................................................... 71

Multiple Textures .................................................................................................................. 72


Application Changes.......................................................................................................................................................... 72
Shader Program Changes ............................................................................................................................ 73

Lighting ................................................................................................................................ 75
Light Components........................................................................................................................................ 75
Types of Lights............................................................................................................................................. 75
Normal Vectors ............................................................................................................................................ 76

vii
N CONTENTS

Lighting Models .................................................................................................................... 76


Ambient and Directional Light ..................................................................................................................... 77
A Point Light ................................................................................................................................................ 81

Texture and Lighting Together .............................................................................................. 81


Summary .............................................................................................................................. 83
N Chapter 4: Increasing Realism ..................................................................................85
Setup .................................................................................................................................... 86
A Vector Object ............................................................................................................................................ 86
Plane Class .................................................................................................................................................. 87
Spheres ....................................................................................................................................................... 88

Lighting Revisited ................................................................................................................. 91


Shading Models ........................................................................................................................................... 91
Phong Illumination Model ............................................................................................................................ 98
Attenuation ................................................................................................................................................ 103
Spotlights .................................................................................................................................................. 104
More Advanced Lighting ............................................................................................................................ 106

Fog ..................................................................................................................................... 106


Shadows............................................................................................................................. 107
Ambient Occlusion ..................................................................................................................................... 108
Shadow Maps ............................................................................................................................................ 108

Depth Buffer ....................................................................................................................... 109


Blending ............................................................................................................................. 109
Reflection and Refraction ................................................................................................... 112
Fresnel effect............................................................................................................................................. 113
Fresnel Shader .......................................................................................................................................... 113

Putting it All Together ......................................................................................................... 113


Summary ............................................................................................................................ 114
N Chapter 5: Physics...................................................................................................115
Background ........................................................................................................................ 115

viii
N CONTENTS

Forces Acting Upon Us ....................................................................................................... 115


Scalars and Vectors ................................................................................................................................... 115
Rates of Change ........................................................................................................................................ 116

Code Setup ......................................................................................................................... 116


Storing Information.................................................................................................................................... 117
Interactively Adjusting the Camera ............................................................................................................ 118

Gravity ................................................................................................................................ 120


Free Falling ................................................................................................................................................ 120
Falling and Colliding With the Ground........................................................................................................ 122
Falling Down, but Bouncing Back Up ......................................................................................................... 123
Falling and Bouncing Up; Repeat............................................................................................................... 124
Nonperfect Elasticity ................................................................................................................................. 125

Velocity in Three Dimensions ............................................................................................. 126


Detecting Collisions with Many Walls ........................................................................................................ 126

Intercollisions ..................................................................................................................... 127


Bounding Boxes and Spheres .................................................................................................................... 127
Conservation of Momentum ...................................................................................................................... 128
Uniform Mass Collisions ............................................................................................................................ 128
Collisions of Different Mass ....................................................................................................................... 130

Projectiles .......................................................................................................................... 131


Potential Energy ................................................................................................................. 134
Summary ............................................................................................................................ 137
N Chapter 6: Fractals, Height Maps, and Particle Systems.........................................139
Painting Directly with the GPU ........................................................................................... 139
Color Lookups ............................................................................................................................................ 141

Fractals .............................................................................................................................. 144


Mandelbrot Set .......................................................................................................................................... 144
Julia Set..................................................................................................................................................... 147
Adding Interactivity.................................................................................................................................... 147

Generation of Fractals ........................................................................................................ 156

ix
N CONTENTS

Rendering a Grid Mesh with One TRIANGLE_STRIP Call..................................................... 157


Height Maps ....................................................................................................................... 161
Bump/Normal Mapping ............................................................................................................................. 162

Terrain ................................................................................................................................ 162


Midpoint Displacement .............................................................................................................................. 162

Particle Systems ................................................................................................................ 166


Enhancements ........................................................................................................................................... 168

Summary ............................................................................................................................ 171


N Chapter 7: Three.js Framework ...............................................................................173
Background ........................................................................................................................ 173
Features..................................................................................................................................................... 174

Setup .................................................................................................................................. 174


Obtaining the Library ................................................................................................................................. 174
Directory Structure .................................................................................................................................... 174
Basic Elements .......................................................................................................................................... 175

Basic Usage........................................................................................................................ 175


Hello World! ............................................................................................................................................... 175
Adding Some Details ................................................................................................................................. 179
Lighting...................................................................................................................................................... 180

Updating Objects ................................................................................................................ 183


Falling Back to the 2D Canvas Context............................................................................... 183
Shaders .............................................................................................................................. 184
Revisiting Earlier Book Code .............................................................................................. 185
2D Rendering ............................................................................................................................................. 185
Custom Mesh ............................................................................................................................................. 185
The Triangular Prism .................................................................................................................................. 189
Texturing .................................................................................................................................................... 191
Lighting and Texturing ............................................................................................................................... 197
Particle System.......................................................................................................................................... 199

x
N CONTENTS

Advanced Usage ................................................................................................................. 201


Import/Export ............................................................................................................................................. 202
tQuery ........................................................................................................................................................ 202

Summary ............................................................................................................................ 203


N Chapter 8: Productivity Tools ..................................................................................205
Frameworks ....................................................................................................................... 205
Many Choices ............................................................................................................................................ 205
Available Frameworks ............................................................................................................................... 206
A philoGL “Hello World!” Example ............................................................................................................. 208
A GLGE “Hello World!” Example ................................................................................................................. 211

Meshes ............................................................................................................................... 213


Loading Existing Meshes ........................................................................................................................... 213
Modeling Resources .................................................................................................................................. 214
File Formats ............................................................................................................................................... 214
Importing, Exporting, and Format Conversion ........................................................................................... 216

Shaders .............................................................................................................................. 224


Textures .............................................................................................................................. 224
Physics Engines ................................................................................................................. 225
Revisiting Old Code with physi.js and Three.js .......................................................................................... 225

Summary ............................................................................................................................ 231


N Chapter 9: Debugging and Performance..................................................................233
Debugging .......................................................................................................................... 233
Integrated Development Environment (IDE) ............................................................................................... 233
Browser Developer Tools ........................................................................................................................... 234
Generic WebGL Error Codes ....................................................................................................................... 237
Context Errors ............................................................................................................................................ 237
Continuously Checking For Errors ............................................................................................................. 239
WebGL Inspector........................................................................................................................................ 240
Testing with glsl-unit ................................................................................................................................. 247
Common Pitfalls ........................................................................................................................................ 247

xi
N CONTENTS

Performance ....................................................................................................................... 250


Measuring Framerate ................................................................................................................................ 250
Complexity in Optimizations ...................................................................................................................... 251
Bottlenecks ................................................................................................................................................ 252
Browser Resources ................................................................................................................................... 253
Blocking the GPU ....................................................................................................................................... 253

Summary ............................................................................................................................ 266


N Chapter 10: Effects, Tips, and Tricks .......................................................................267
Effects ................................................................................................................................ 267
Basic Image Manipulation ......................................................................................................................... 267
Convolution Filters ..................................................................................................................................... 271

Antialiasing......................................................................................................................... 282
Nonphotorealistic Rendering .............................................................................................. 283
Cartoon Shading ........................................................................................................................................ 283
Technical Diagrams ................................................................................................................................... 285

Framebuffers ...................................................................................................................... 286


Creating a Framebuffer Object .................................................................................................................. 287
Attaching a Texture to the Framebuffer ..................................................................................................... 287
Binding the Framebuffer............................................................................................................................ 288
Changing Shader Functionality per Framebuffer ....................................................................................... 289
Adding a Depth Attachment ....................................................................................................................... 291

Picking Objects................................................................................................................... 292


Looking Up a Value .................................................................................................................................... 293

Shadow Map Implementation ............................................................................................ 294


Summary ............................................................................................................................ 298
N Afterword: The Future of WebGL ..............................................................................299
Support............................................................................................................................... 299
Browser support ........................................................................................................................................ 299
Mobile Device support .............................................................................................................................. 299

xii
N CONTENTS

Adoption ............................................................................................................................. 300


What WebGL Has Going for It ..................................................................................................................... 300
Concerns.................................................................................................................................................... 300
Game Developers ...................................................................................................................................... 301

Active Development ........................................................................................................... 301


Extensions ................................................................................................................................................. 301

The Final Word.................................................................................................................... 301


N Appendix A: Essential HTML5 and JavaScript .........................................................303
Essential HTML5 ................................................................................................................. 303
Brevity ....................................................................................................................................................... 303
Semantic Areas.......................................................................................................................................... 304
The <canvas> Element ............................................................................................................................. 305

Essential JavaScript ........................................................................................................... 306


Self-invoking Anonymous Functions ......................................................................................................... 307

jQuery ................................................................................................................................. 307


N Appendix B: Graphics Refresher ..............................................................................309
Pixels .................................................................................................................................. 309
Primitives ........................................................................................................................... 309
Colors ................................................................................................................................. 310
Coordinate Systems ........................................................................................................... 310
Transforms ......................................................................................................................... 310
Math ................................................................................................................................... 312
Angles ........................................................................................................................................................ 312
Pi................................................................................................................................................................ 312
Radians ...................................................................................................................................................... 313
Trigonometry ............................................................................................................................................. 313
Rotations ................................................................................................................................................... 314
Vectors....................................................................................................................................................... 314

N Appendix C: WebGL Spec. Odds and Ends................................................................315


WebGLContextAttributes..................................................................................................... 315
xiii
N CONTENTS

Texture Properties .............................................................................................................. 315


Cube Map Targets............................................................................................................... 316
texImage2D................................................................................................................................................ 316

Framebuffer and RenderBuffer Targets and Attachments .................................................. 316


N Appendix D: Additional Resources ..........................................................................317
Companion Website ............................................................................................................ 317
Topics ................................................................................................................................. 317
Ajax ............................................................................................................................................................ 317
Debugging ................................................................................................................................................. 317
Demos........................................................................................................................................................ 318
HTML ......................................................................................................................................................... 318
JavaScript .................................................................................................................................................. 318
LAMP, MAMP, and WAMP ............................................................................................................................ 318
Libraries and Frameworks ......................................................................................................................... 318
GLGE .......................................................................................................................................................... 319
PhiloGL....................................................................................................................................................... 319
Three.JS..................................................................................................................................................... 319
Lighting...................................................................................................................................................... 319
Mathematics .............................................................................................................................................. 320
Matrix and Vector Libraries........................................................................................................................ 320
Mesh File Formats ..................................................................................................................................... 320
Performance and Best Practices ............................................................................................................... 321
Physics ...................................................................................................................................................... 321
WebGL........................................................................................................................................................ 321
WebGL Future ............................................................................................................................................ 322
WebGL SL (OpenGL ES SL) ......................................................................................................................... 322

N Index ........................................................................................................................323

xiv
About the Author

Brian Danchilla is a freelance developer and author. He is ZEND PHP Certified


and cowrote the book Pro PHP Programming. Brian is a contributing author
to the book HTML5 Games Most Wanted, and was a technical reviewer for
Foundation HTML5 Animation for JavaScript and PHP: The Good Parts.
Brian is a seasoned web developer, Java, and OpenGL programmer and has
a BA degree as a double major in computer science and mathematics. After
several years working within the computer industry, he is now enjoying the
flexibility of freelance work. Brian has a strong desire and ability to learn new
technologies and APIs and is an avid technical reader. When not programming,
Brian likes to play guitar, cook, and travel. He resides in Saskatoon, SK, Canada
with his fiancée Tressa.

xv
About the Technical Reviewer

Massimo Nardone holds a Master of Science degree in Computing Science


from the University of Salerno, Italy. He works currently as a PCI QSA and
Senior Lead IT Security/Cloud Architect for IBM Finland. With more than
19 years of work experience in Cloud Computing, IT Infrastructure, Mobile,
Security and WWW technology areas for both national and international
projects, Massimo has worked as a Project Manager, Software Engineer,
Research Engineer, Chief Security Architect, and Software Specialist. He
worked as visiting lecturer and supervisor for exercises at the Networking
Laboratory of the Helsinki University of Technology (Helsinki University of
Technology TKK became a part of Aalto University) for the course of “Security
of Communication Protocols.” He holds four international patents (PKI, SIP,
SAML and Proxy areas). His beloved baby girl, Neve, was born some days ago
and he wants to welcome her from the bottom of his heart.

xvi
Acknowledgments

I would like to thank my family: mom, dad, Robert, Karen, Tressa. Longtime friends: Vince, Nick, and Tim. It was
not always a smooth journey during this book project and I am very grateful for your support along the way.
Thank you to everyone on the Apress team who was involved with this book. I would especially like to thank
Ben Renow-Clarke for getting this book title off the ground, Louise Corrigan for valuable editing advice, Anamika
Panchoo for her coordinating skills, and the technical reviewing of Massimo Nardone.
Thank you to my university professor David Mould for introducing me to OpenGL,and my high school art
teacher Mrs. Robinson for helping develop my artistic side.
I am thankful for having a good set of headphones and a great music collection that enabled me to zone in
and work. Thanks to late, late night Super Mario Galaxy 2 sessions for inspiration and coffee, lots of coffee.
Several years ago, I first read computer graphics books and thoroughly enjoyed the experience. Now I am
blessed to have been able to write my own book about an exciting new technology, WebGL.

xvii
Introduction

WebGL (Web-based Graphics Language) is a wonderful and exciting new technology that lets you create
powerful 3D graphics within a web browser. The way that this is achieved is by using a JavaScript API that
interacts with the Graphics Processing Unit (GPU). This book will quickly get you on your way to demystify
shaders and render realistic scenes. To ensure enjoyable development, we will show how to use debugging tools
and survey libraries which can maximize productivity.

Audience
Beginning WebGL for HTML5 is aimed at graphics enthusiasts with a basic knowledge of computer graphics
techniques. A knowledge of OpenGL, especially a version that uses the programmable pipeline, such as OpenGL
ES is beneficial, but not essential. We will go through all the relevant material. A JavaScript background will
certainly help.
When writing a book of this nature, we unfortunately cannot cover all the prerequisite material. Baseline
assumptions about the reader need to be made. The assumptions that I have made are that the reader has a
basic knowledge of 2D and 3D computer graphics concepts such as pixels, colors, primitives, and transforms.
Appendix B quickly refreshes these concepts. It is also assumed that the reader is familiar (though need not be an
expert) with HTML, CSS, and JavaScript. Although much of the book makes use of plain “vanilla” JavaScript, we
will use some jQuery. Appendix A discusses newer HTML5 concepts and a quick jQuery crash course that will be
essential for properly understanding the text. Appendix D provides a complete reference for further reading on
topics that are presented throughout the book.

What You Will Learn


This book presents theory when necessary and examples whenever possible. You will get a good overview of what
you can do with WebGL. What you will learn includes the following:

v Understanding the model view matrix and setting up a scene


v Rendering and manipulating primitives
v Understanding shaders and loving their power and flexibility
v Exploring techniques to create realistic scenes
v Using basic physics to simulate interaction
v Using mathematics models to render particle systems, terrain, and fractals
v Getting productive with existing models, shaders, and libraries

xviii
N INTRODUCTION

v Using the Three.js framework


v Learning about GLGE and philoGL frameworks and a survey of other frameworks
available
v Debugging and performance tips
v Understanding other shader uses, such as image processing and nonphotorealistic
rendering
v Using an alternate framebuffer to implement picking and shadowmaps
v Learning about current browser and mobile support and the future of WebGL

Book Structure
It is recommended that you start by reading the first two chapters before moving on to other areas of the book.
Even though the book does follow a fairly natural progression, you may choose to read the book in order or skip
around as desired. For example, the debugging section of Chapter 9 is not strictly essential, but is very useful
information to know as soon as possible.

Chapter 1: Setting the Scene


We go through all the steps to render an image with WebGL, including testing for browser support and setting
up the WebGL environment, using vertex buffer objects (VBOs), and basic shaders. We start with creating a one
color static 2D image, and by the end of the chapter have a moving 3D mesh with multiple colors.

Chapter 2: Shaders 101


Shaders are covered in depth. We show an overview of graphics pipelines (fixed and programmable), give a
background of the GL Shading Language (GLSL), and explain the roles of vertex and fragment shaders. Next we
go over the primitive types and language details of GLSL and how our WebGL application will interact with our
shaders. Finally, we show several examples of GLSL usage.

Chapter 3: Textures and Lighting


We show how to apply texture and simple lighting. We explain texture objects and how to set up and configure
them and combine texture lookups with a lighting model in our shader.

Chapter 4: Increasing Realism


A more realistic lighting model—Phong illumination—is explained and implemented. We discuss the difference
between flat and smooth shading and vertex and fragment calculations. We show how to add fog and blend
objects; and discuss shadows, global illumination, and reflection and refraction.

Chapter 5: Physics
This chapter shows how to model gravity, elasticity, and friction. We detect and react to collisions, model
projectiles and explore both the conservation of momentum and potential and kinetic energy.

xix
Discovering Diverse Content Through
Random Scribd Documents
On Morris’s return to the Base Camp, the party was completed.
One of the difficulties in having so large an outfit as ours was the
difficulty of obtaining transport when necessary. Therefore, as soon
as we saw signs of the monsoon, it was necessary to make
arrangements for our return, as at least fifteen days were required
to collect the still large number of animals required for our moving.
These animals have to be searched for all down the Dzakar Chu,
collected, and brought up; nor when once collected could they be
kept waiting for very long, as the supply of fodder in the upper
valley was absolutely nil—fodder did not exist. When we sent off the
previous party they travelled as lightly as possible, but even then the
small number of animals which was required for their transport had
not been obtained with any great ease. Fortunately, John Macdonald
was with us and was free, and it was owing to his help (for he
speaks Tibetan as well as Nepali, and is thoroughly accustomed to
deal with the people) that the two parties of Strutt and Norton were
able to proceed with such little delay. It had required a full fifteen
days to collect enough animals to move the main body. I had
arranged for a latitude of one or two days, which meant that they
should have spare food up to that extent, but beyond that it would
be quite impossible, naturally, to make provision. Of course, as one
of our secondary objects we had hoped, if our party had not been
exhausted, to have explored the West Rongbuk and the great glens
on the Western faces of Everest. And besides this most interesting
piece of exploration, of which really not very much more than
glimpses were obtained during 1921, there is the prodigious and
fascinating group of Cho Uyo and Gyachang Kang to be explored.
Watching the Dancers, Rongbuk Monastery.

As I before pointed out, of course, not only was our major work
and the whole object of the Expedition the tackling of the great
mountain, but also it was a race against the weather, so we could let
nothing interfere with our main object. It was quite clear now, as we
were situated, that an exploration of the West Rongbuk was entirely
beyond consideration. Not only was the whole party fairly played
out, but to get up enthusiasm in a new direction after what we had
gone through was pretty nearly out of the question. Somervell, the
absolutely untireable, had very strong yearnings in that direction,
but it would have been nothing more than a scramble in the dark if
he had gone. The weather was broken and was getting worse and
worse every day. Snow fell occasionally even at our camp. Further
up everything was getting smothered. Everest, when we had
glimpses of it, was a smother of snow from head to foot, and no one
who saw it in these days could ever imagine that it was a rock peak.
I am afraid also that most of us had only one real idea at the time,
and that was to get out of the Rongbuk Valley. However, during our
wait for the transport the annual fête of the Rongbuk Monastery
occurred. There was a great pilgrimage to the monastery to receive
the blessing of the Lama and to witness the annual dances. Most of
our party went down to see dances, and Noel especially to
cinematograph the whole ceremony, dances as well as religious
ceremonies. I have not done justice up to this point to Noel’s work.
He was quite indefatigable from the start, and had lost no
opportunity during our march up, not only of taking many pictures of
the country and Expedition, both with his ordinary camera and with
his cinema camera, but of studying Tibetan life as well. He had in
the Rongbuk Valley pitched his developing tents near the only
available clear water at the moment, and had there been untiring in
developing his cinema photographs. He had made two expeditions to
the head of the East Rongbuk Glacier, and had even taken his
cameras and his cinema outfit on to the North Col itself where he
remained for no less than four days—a most remarkable tour de
force. On the last occasion he had accompanied the evacuation
party, and had been actually taking pictures of the start of the last
attempt to get to the North Col and to climb Everest. Of course, his
performances with the camera are entirely unprecedented. The
amount of work he carried out was prodigious, and the enthusiasm
he displayed under the most trying conditions of wind and weather
was quite wonderful. We now feel that we can produce a real
representation of our life and of life in Tibet in a manner in which it
has never hitherto been brought before people’s eyes, and this gives
a reality to the whole Expedition which I hope will make all those
who are interested in mountain exploration understand the
wonderful performances and the great difficulties under which the
climbing members of this Expedition and the transport officers
laboured.
After the news of the accident had been received, we immediately
got in touch with the great Lama of Rongbuk, who was intensely
sympathetic and kind over the whole matter. It is very strange to
have to deal with these curious people; they are an extraordinary
mixture of superstition and nice feelings. Buddhist services were
held in the monasteries for the men who had been lost and for the
families; and all the porters, and especially the relations of the men
who were killed, were received and specially blessed by the Rongbuk
Lama himself. All the Nepalese tribes who live high up in the
mountains, and also the Sherpa Bhotias, have a belief that when a
man slips on the mountains and is killed, or when he slips on a cliff
above a river and falls into it and is drowned, that this is a sacrifice
to God, and especially to the god of the actual mountain or river.
They further believe that anyone whosoever who happens to be on
the same cliff or on the same mountain at the same place, exactly at
the same time of year, on the same date and at the same hour, will
also immediately slip and be killed.
I also received during our return a very kind letter from the
Maharajah of Nepal condoling with us on the loss of our porters. He
writes as follows:—
“Personally, and as a member of the Royal Geographical Society, I
share with you the grief that must have resulted from the frustration
of the keen hope entertained by you and the party. My heartiest
sympathies go to you and to the families of the seven men who lost
their lives in the attempt. This puts in my mind the curious belief
that persistently prevails with the people here, and which I came to
learn so long ago in the time of our mutual friend, Colonel Manners
Smith, when the question of giving permission for the project of
climbing the King of Heights through Nepal was brought by you and
discussed in a council of Bharadars. It is to the effect that the height
is the abode of the god and goddess Shiva and Parvati, and any
attempt to invade the privacy of it would be a sacrilege fraught with
disastrous consequences to this Hindu country and its people, and
this belief or superstition, as one may choose to call it, is so firm and
strong that people attribute the present tragic occurrence to the
divine wrath which on no occasion they would draw on their heads
by their actions.”
This, I must point out, is, of course, the Southern and Hindu
people’s tradition, and did not in the same way affect all the porters
whom we employed, as they were Buddhists by faith. The whole of
our people, however, took the view common to both and dismissed
their troubles very rapidly and very lightly, holding simply that the
men’s time had come, and so there was no more to be said about it.
If their time had not come, they would not have died. It had come,
and they had died and that was all. What need to say any more? As
a matter of fact, this philosophic way of looking on everything also
allowed them to say that they were perfectly ready to come back for
the next attempt, because if it was written that they should die on
Everest, they should die on Everest; if it was written that they would
not die on Everest, they would not, and that was all there was to be
said in the matter.
CHAPTER III

THE RETURN BY KHARTA

On June 14 we were cheered with the news that our transport


was approaching, and I think a good many sighs of relief were
uttered. We had quite made up our minds to cross over into the
Kharta Valley, and, having had a sufficiency of rest, to explore the
Kama Chu more completely than had been done in 1921, and, if
possible, to examine the whole gorge of the Arun where it breaks
through the great Himalayan range; but our first idea was to get
down to a decent elevation where some rest could be obtained,
where we could get adequate bathing and washing for our clothes
and get everybody into a fairly respectable condition again. Living
continuously for many weeks at elevations never below, and
generally far above, 16,500 feet, does not tend to general
cleanliness, and it also, after a time, I think, tends to general
degeneration. At the same time, we were by no means convinced
that at medium elevations there is any particular loss of physical
powers or that acclimatisation takes long to complete. I found,
personally, that I was getting better and better when exerting myself
at the medium heights to which I went. I found, during the march
that was in front of us, that I could walk at elevations of over 16,000
feet very much more easily than when I first arrived at the Rongbuk
Glacier, and this certainly does not show that one had been
degenerating physically. I think, really, that the strain was more a
mental one; and this remark probably also applies to every member
of our party. At the same time, it was most exhilarating to think that
one was descending to a low altitude.
We made our first march back to the Rongbuk Glacier, and that
evening we were left in peace—by the Lamas, that is to say, but not
by the wind, which howled consistently, bringing with it thin driving
sleet.

The Chief Lama, Rongbuk Monastery.

On the following morning we arranged that we should all meet the


Rongbuk Lama; and so, having got our kit packed, we left it to be
loaded by the Tibetans, and the whole party, including all our
followers, porters, all the Gurkhas who were with us (with the
exception of Tejbir, who had gone on in advance with Geoffrey Bruce
and Norton), went up to the monastery. There we waited in the
courtyard until the Lama himself descended from his inner sanctuary
in state. Tea was first served in the usual way, ordinary tea being
provided, I am glad to say, for the others and myself by special
arrangement of the interpreter. I think Noel, however, a man of
infinite pluck, took down a bowl or two of true Tibetan tea. The
Lama made special inquiries after the Expedition, and then began
the blessing. He offered us his very best wishes, and presented me,
through Paul, with a special mark of his goodwill, a little image of
one of the Taras, or queens, of Tibetan mythology. My special one
was the Green Tara, who takes precedence among all ladies. This
was a mark of very great favour. Paul was also presented with
another little mark and many little packets of medicine, which were
to preserve him from all and every description of the illnesses which
afflict and worry humanity. The Buddhistic side of Paul came up on
this occasion, and he received his blessings and the medicines in the
most humble and reverent spirit. The Gurkhas all went up too, and
were suitably blessed, being even more humble in their aspect than
the very much overcome and reverent porters themselves; they
could hardly be induced to approach his Holiness. However, we all
parted on the most friendly terms, and left our own good wishes, for
what they were worth, with the old gentleman.
By three o’clock in the afternoon we arrived at Chodzong. But
what a difference there was in our march! The few days of the
monsoon and the small amount of rain which had fallen, even this
little way back from the mountains, had changed the whole aspect
of the valley. Flowers had begun to show, and in places there was
even a little green grass. At Chodzong there was quite a
considerable amount of grass, and we enjoyed here what was more
pleasant than anything we had experienced for a long time—a
shower of rain. We had almost forgotten the existence of rain, and
the relief from the very trying dryness of the Tibetan atmosphere,
which parches one’s skin as if one was in the Sahara, was immense.
Still, at Chodzong it was cold at night and the temperature below
freezing-point. Here we found all our ponies and their saises
returned from taking Norton and Geoffrey Bruce over to the Kharta
Valley. Also the gigantic D(r)ubla and his small Gyamda very fit and
well.
This camp at Chodzong was a place particularly impressed on our
minds on our way up, as we had there the very coldest breakfast
that we anywhere indulged in. The wind was blowing half a
hurricane, and the temperature nearly at zero, while our breakfast
was actually being brought to us in the morning, and the misery and
discomfort of that particular temperature was in great contrast to
the delightful weather we were now experiencing. From this place
we diverted a large convoy of our spare baggage to Shekar, to await
our return after we had finished our further wanderings in Kharta.
The following day took us up the Rebu Valley. It was a fairly long
and very windy march, but the climate was so greatly improved that,
generally speaking, it was very enjoyable, and again we camped in a
very pleasant spot in grassy fields—such a change from our late life.
Not only that, but in the evening, as the people up here had no
prejudices, we caught a sufficient number of snow-trout, really a
barbel, to make a dish. My own servant, Kehar Sing, the cook,
always had a reputation for being, and always was, a first-rate
poacher. At any form of netting or tickling trout he was a great hand.
However, he was completely eclipsed later on by one of Macdonald’s
servants, to whom I am quite certain no fish-poacher that ever was
could have given a wrinkle. He was also quite a good hand at
catching fish with rod-and-line. The Gurkhas, as usual, took a hand;
they are immensely fond of fish, and their methods are primitive.
Tejbir, who came along with us, was nearly recovered from his
exertions with Finch and Geoffrey; he had lost a good deal of skin
from seven or eight fingers and a large patch off his foot, but though
his frostbites were many, they were slight. He was really suffering
from being rather overdone, and took at least a fortnight to recover.
The next day’s was an interesting march, though very long, and
tiring for the animals. Our way led over the high ridge which divides
the Dzakar Chu country from the Kharta district. Although the rise
was not very great from our camp at approximately 13,500 feet, still
the pass itself was just 17,000 feet, or rather, to be absolutely
accurate, just 3 feet under. The way led for several miles, hardly
rising at all, up a grassy valley, and then over the strangest and
wildest and most completely barren of hillsides. From here, no
doubt, we should have a fine view of the great supporters of
Everest, but clouds completely obliterated the mountains. We had
the ordinary balmy Tibetan breezes through the snows, but modified
to what they would have been quite a short time before.
The descent from the Doya La was very fine indeed; the colour
wonderful, and very soon giving promise of a greener land. The first
300 feet on the Kharta side is down a very steep rocky track, and I
was told afterwards by Geoffrey Bruce that he never dismounted,
and that the wonderful Gyamda had carried him down without
making a mistake. On that day we all of us well overtopped 17,000
feet. There was a little joke about Crawford, who was not very tall,
but who certainly did not deserve his nickname of the “Two-and-a-
half-footer” given him by the porters. It was a joke among them
afterwards, when told the height of the pass, that he had just
missed the 17,000 feet by 6 inches.
It was a very long descent, but into a valley rapidly changing from
bare hillsides to grassy banks. Never was there a more welcome
change, and here we came into a real profusion of Alpine flowers. It
was a full 20-mile march to our halting-place at Trateza, and as we
got down where the valley narrowed we passed the very
picturesquely situated village of Teng. Everybody was delighted with
the change. Our camp was pitched near the village on quite thick
and beautiful green grass, and the hillsides were green and covered
with bushes. We were absolutely happy and intensely relieved, and
pleased with our surroundings. The ponies and animals simply
pounced on the green grass, and were even more happy than their
masters.
The following morning we all started off in wonderful spirits,
shared in by the yaks, several of whom took it into their heads to
run amuck, and we had a first-class scene of confusion in the rather
tight camp before we could get matters straightened out. One yak
especially was peculiarly gay here, and took to the hillside after
throwing his load on three or four occasions. We had, in fact, a real
hunt after him; everybody joined in the fun, and I am afraid on one
or two occasions some of the more light-hearted of the porters kept
him going on purpose. This march, however, was even pleasanter
than the one before. The part we were travelling down grew richer
and richer; the hillsides were thickly clothed in cedar trees and in
shrubs of many kinds; the valley itself, wherever possible, was
cultivated. We passed on our way two or three small villages
extremely well situated, and finally debouched into an open valley
full of fields and cultivation, where we joined the main Arun Valley
and the district of Kharta proper. Kharta is a fairly large district, and
not a village. The largest settlement is called Kharta Shika, and it is
there that the Dzongpen has his abode. The whole of this district,
also, is under the Dzongpen of Shekar Dzong, and the Dzongpen of
Shika apparently has not as full powers by any means as the
Dzongpen at Shekar Dzong. However, for all that, he appears to be
quite a little autocrat.
It was quite delightful riding out into the main valley, and there
also we were cheered by meeting Geoffrey Bruce and John
Macdonald, who had come out some miles from where our camp
had been established at the small village of Teng. We passed, also,
the old gentleman, known, I think, in the last year’s Expedition as
“the Havildar,” but whom Geoffrey and Norton had promptly
christened Father William. He was a rather officious, but at the same
time most helpful, old man, and on our way back he asked us to
come in for a meal into his very attractive garden; but as it was only
a mile or so from Teng, where our camp was pitched, we did not
think it was worth while then, knowing we should see a good deal
more of the old gentleman. He brought us plenty of what we were
yearning for—fresh green vegetables, the very greatest boon.
We found our invalids very nearly recovered; Norton’s feet,
however, were tender, and Geoffrey’s toes still in a distinctly
unpleasant condition. It was wonderful, nevertheless, how well both
were able to get about with the help of plenty of socks. Our camp
was pitched in fields at a height of about 10,800 feet, and below us,
at about the distance of 3 miles, we could see the entrance to the
great Arun Gorge where it cuts through the Himalaya. On the
opposite side of the Arun the two mountains, old friends of ours that
we had noticed on our way up, looked down on the camp. On the
whole of my way down I was struck with the resemblance between
these valleys and parts of Lahoul and Kailang. They were less rich,
however, and the forests of pencil cedar not so fine, but still the
whole character of the country and of the hillsides was very much
the same.
Tibetan Dancing Man.
Tibetan Dancing Woman.

Above the camp at Teng was a very well situated monastery,


which Noel afterwards photographed. Soon after our arrival during
the afternoon, the Dzongpen from Kharta Shika arrived to meet us.
He was reported at first to be very suspicious of the party, and such,
indeed, appeared to be the case. However, after a long conversation,
and having presented him with pictures of the Dalai Lama and of the
Tashilumpo Lama, as well as with the ubiquitous Homburg hat, he
became much more confidential, and we finished up very good
friends. He also told us that on the following day he would bring
down some Tibetan dancers and acrobats to give us a performance.
The rapidity with which the whole party seemed to recover at
Kharta was perfectly wonderful. Everybody was in first-class health
and spirits, especially all our porters, and that night their high spirits
were not only due to the atmospheric conditions, but were taken
into them in a manner they thoroughly approved of and of which
they had been deprived for some time. However, after all their very
hard work and the wonderful way in which they had played up, it is
not altogether to be wondered at if they did occasionally “go on the
spree” on their way back.
So attractive was the whole country, and so strong was the call of
the Kama Valley, that we were all very soon anxious to get a move
on again. Tejbir was still not quite recovered, and would be all the
better for further rest, so he was detailed with one of the other
Gurkhas, Sarabjit, to stay behind and take charge of our camp and
spare equipment. The rest of us all set to work and planned an
advance into the Kama Valley, and, we hoped also, an exploration of
it, both towards the snows up and to the Popti La, which is the main
road into the valley of the Arun, and, if possible, up the great Arun
Gorge itself. But this year’s monsoon never gave us a chance of
carrying out more than a small portion of that programme. We were
now living in an entirely different climate. We had many showers of
rain, which were hailed with delight by the people of the country, as
their crops were now fairly well advanced. The crops at Kharta
consist chiefly of peas and barley, as usual, but there is a certain
amount of other grain and vegetables to be obtained from the
gardens.
Having arranged the transport, we started our caravan off to
Kharta Shika. Norton had issued a large-hearted invitation for us to
lunch with him at the mouth of the Arun Gorge. Previously Norton
and Geoffrey had explored, while they were waiting, the country
round as far as they could go on horseback, and Norton had
discovered at the mouth of a gorge an alp like those on the Kashmir
Mountains, surrounded with a forest which he described as equal to
a Southern Himalayan forest, and we positively must go and see it,
and climb up the hillsides and look down into the gorge itself.
We all accepted his invitation with the greatest alacrity. On the
afternoon of the day before starting, the Dzongpen, as he had
promised, produced us his acrobats and dancers, and we had a very
hilarious afternoon. They were not particularly good either as actors
or as acrobats, but they danced with prodigious vigour, and it was
altogether great fun. Before all the dances and the little plays they
covered their faces with masks of an extremely primitive kind. They
failed at most of their tricks once or twice before accomplishment,
and these failures were invariably greeted both by the spectators
and by the actors with shrieks of laughter.
On the following day (June 19) we all set off, the luggage
proceeding direct to Kharta Shika under the charge of the interpreter
and the Gurkhas, while we switched off to Norton’s alp. It really was
delightful, and though the forest was rather a dwarfed forest, it
contained several kinds of fir trees, birch, and rhododendron scrub,
and, after Tibet, was in every way quite charming. We climbed up
the hillsides and suddenly came round the corner on to great cliffs
diving straight down into the Arun Valley, and we could see further
down how enormously the scale of the mountains increased. It was
a most attractive gorge, but on our side it appeared to be almost
impossible to have got along, so steep were the hillsides. On the far
bank, that is, the true left bank, the East bank, there was a well-
marked track, and it appears that lower down it crosses to the right
bank and then continues on the right bank to the junction with the
Kama Chu. Later on Noel and Morris were able to explore and
photograph the greater part of the gorge. We all sat on the top of
the cliffs and indulged in the very pleasant amusement of rolling
great rocks into the river a thousand feet below us—always a
fascinating pursuit, especially when one is quite certain that there is
no one in the neighbourhood. The lunch did not turn up for some
time, when an exploring party discovered that our porters, who had
been detailed to carry it, had dropped in at a village and visited the
Barley Mow, and could hardly get along at all in consequence; finally,
however, the lunch was rescued and an extremely pleasant time
passed. It was absolutely epicurean: Gruyère cheese, sardines,
truffled yaks, and, finally, almost our last three bottles of
champagne. It was intended to be an epicurean feast—and it was
so.
By the evening we arrived in Shika, and found our camp pitched in
beautiful grassy fields high above the village of Shika. The Dzongpen
was very anxious to entertain the whole party, but we were rather
lazy and did not want to go down to his village, which was some
way off, but promised him that we would pay him a visit on our
return from Kama. The Dzongpen, however, imported his cooks and
full outfit and gave us a dinner in our own tent, himself sitting down
with us and joining in. He was a plump and very well dressed little
man, and by now had completely recovered his confidence in us. He
was, however, very anxious that we should do no shooting, and this
anxiety of his was no doubt very largely occasioned by the fact that
he had only arrived from Lhasa about a fortnight before our arrival.
We were to reach in two marches Sakiathang, in the Kama Valley,
where Colonel Howard-Bury and his party had encamped the year
before. Our first march led us over the Samchang La to a camp
called Chokarbō. It was a steep and rough walk over the pass, but
knowing the wonderful capacity of the Tibetan pony, several of the
party took ponies with them. It was necessary both for Geoffrey and
for Norton to rest their feet as much as possible until completely
cured, and so on arrival at Chokarbō they took their ponies on over
our next pass, the Chog La, which is no less than 16,280 feet, and
down into the Kama Chu. This is a very rough road indeed.
We had here reached the most perfect land of flowers, and in the
low land which lies between the Samchang La and our camp at
Chokarbō we found every description of Alpine flora, reinforced by
rhododendrons—the very last of the rhododendrons. We also found
several kinds of iris.
The road leading up to the Samchang La was extremely steep and
rough, but the path was well marked, and it was evident there was a
considerable amount of traffic leading into the Kama Chu. The local
people stoutly denied that yaks could cross, but later on we actually
found yaks carrying loads over this road. I can quite understand
their reason for not wishing to send their yaks, as the road from one
end to the other is very bad for animals. At Chokarbō all the riding
ponies were dispensed with, with the exception of Geoffrey’s and
Norton’s; these two ponies they particularly wished to look after, as
they had bought them, knowing that they must assure mounts,
probably to the end of the journey. They had certainly picked up the
most useful little couple. All the same, they had to walk most of the
way, as it was quite out of the question for anyone to have ridden at
all, except over short pieces of open ground, and it was perfectly
wonderful the way in which these two ponies got over the most
shocking collection of rocks, big and little, and how they negotiated
the extremely slippery and rocky path which led down from the Chog
La. The ascent to the Chog La was easy, and the latter half of it still
under winter snow, as also was the first thousand feet of the
descent. The mountains were interesting on each side, so much so
that Somervell and Crawford went off for a little climb on the way.
The descent was delightful, although the road was, as I have said,
very stony indeed. One passes through every description of Eastern
Himalayan forest and wonderful banks of rhododendrons of many
kinds. We were, unfortunately, much too late for their full bloom, but
a month earlier this descent must be perfectly gorgeous, the whole
hillsides being covered with flowering rhododendrons.
Old Tibetan Woman and Child.

The descent to Sakiathang is at least 5,000 feet, and may be a


little more. Thang means “a flat bench,” and such was Sakiathang,
set in gorgeous forest, and deep in grass and flowers. But the
weather was breaking fast, and by evening the clouds had
descended and wiped out the whole of the valley. Before it was quite
obliterated we got glimpses of what it must be like in fine weather.
In the early morning of the following day (Thursday, June 22),
when I woke up and looked out of my tent, the mouth of which
looked straight up the valley between the big mountains, the clouds
had lifted somewhat, and the whole end of the valley was filled with
the gorgeous Chomolönzo peak, and for an hour or so I was able to
watch it with the clouds drifting round its flanks, and then, just as
the sun lit up the valley for a moment, the great monsoon clouds
coming up from the valley of the Arun, driven by the wind up the
Kama Chu, completely wiped it out again. It was a glorious glimpse,
and the only one we obtained during our stay of more than a week
in Sakiathang.
We found encamped in the neighbouring woods Nepalese
shepherds, with their flocks of sheep, and saw for the first time the
very fine type of sheep which these men own—a far bigger and
better breed of sheep than exists in Tibet, and also carrying a very
much finer coat of wool. They were rather strange to look at at first,
as the whole fore-part of their body was black and the hind-part
white. We also found that the Nepalese shepherds thoroughly
understood the value of their own sheep. They keep them all to
make butter from their milk, which they collect and sell in the
bazaars in Nepal. All these shepherds were Gurkhas belonging either
to the Gurung tribe or Kirantis, and, curiously enough, one of them
was related to my servant Kehar Sing, he having gone through the
“mit” ceremony with his relations, and that is quite sufficient for him
to be also a “mit.” This “mit” ceremony is rather difficult to explain.
It is not exactly blood-brotherhood, it is more of the nature of
religious brotherhood; but it is quite binding, as much so as an
ordinary relationship. This eased the situation for us pretty
considerably in the matter of obtaining milk and butter. As I have
before mentioned, I do not myself eat butter in an uncooked state,
but the remainder of the party reported that this sheep’s butter was
of very fine quality, and it was certainly very clean. These shepherd
establishments are known as gôts. Naturally forgetting that certain
terms are unfamiliar, I told Wakefield that I had bought two sheep
from the gôts. He seemed more confused than usual by the
strangeness of the country.
As we were rather short of provisions, we despatched Noel’s
servant and our excellent Chongay Tindel to obtain supplies for us;
the first down to the junction with the Arun, and the second over the
Popti into Damtang, a large Nepalese settlement.
The remainder of the party stayed behind, hoping for better
weather in order to explore the upper valley of the snows, and up to
the Popti to get a view of the country into Nepal, if possible. It was
no use attempting to move unless the weather cleared to a certain
extent. Meanwhile we were living in a smother of cloud, mist, and
rain. But how delightful it was to have an ample supply of firewood
and to be able to build, for the first time since we had entered Tibet,
a reckless camp-fire round which we could all sit! It is a real
hardship in Tibet never to have a good roaring fire, and it is a little
damping to one’s spirits having always to go to bed in order to get
warm. Whenever it cleared, we went for short walks through the
neighbouring forests and into the neighbouring valleys, and saw
quite enough to fill us with a desire for much more exploration. The
forest of the Kama is unbelievably rich; the undergrowth, especially
the hill bamboo, of a very vivid green, and the cedar and fir appear
very dark, almost black, against it. But the forest also contains every
other kind of tree and shrub proper to the Eastern Himalaya, and the
river-banks were, in places, overhung with the most glorious
Himalayan larch, identical with the European larch in appearance,
but with possibly a greater spread of branch.
The weather got worse and worse, and our food supplies lower
and lower. There were no signs of the return either of Noel’s servant
or of the Chongay from Nepal, and so, with the greatest reluctance,
we gave up further exploration as a body. We were reduced to only
half a day’s grain-food for our following, and not only that, but the
Tibetan porters whom we were expecting to help us back, and who
had been ordered, showed no signs of arriving. Having searched the
country round, we managed to rope in a few local people, mostly
Tibetans, who had come over from Kharta for wood. There is
considerable traffic from the Tibetan side, as in this well-wooded
country they cut most of the timber required for their houses and
carry it over on their own backs, or else on the backs of unfortunate
yaks, when they can bring themselves to risk their yaks’ legs over
this awful road. We carried as much luggage as we possibly could
with us, not knowing how many men we should be able to obtain to
send for the remainder. We had not enough men with us to carry the
whole camp, and so two Gurkhas were left here in charge of what
remained. They were also to meet Chongay and bring him back with
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebookfinal.com

You might also like