├── Geometry and Appearances.html
├── Web.config
├── _lib
├── matrix.js
├── polygon.js
├── util.js
└── webgl-util.js
├── images
├── awesomeface.png
├── back(1).jpg
├── back.jpg
├── bottom(1).jpg
├── bottom.jpg
├── brick-diffuse.png
├── brick-normals.png
├── brickwall.jpg
├── brickwall_normal.jpg
├── camera.jpg
├── container2.png
├── container2_specular.png
├── front(1).jpg
├── front.jpg
├── grass.png
├── left(1).jpg
├── left.jpg
├── lena.png
├── marble.jpg
├── metal.png
├── normal_mapping.png
├── right (2).jpg
├── right.jpg
├── sky_cloud.jpg
├── stone.png
├── stone_normal.png
├── top(1).jpg
├── top.jpg
├── wall.jpg
├── window.png
├── wood.png
└── 阴影示例.png
├── lib
├── cuon-matrix.js
├── cuon-utils.js
├── gl-matrix.js
├── jquery-1.9.1.min.js
├── webgl-debug.js
├── webgl-obj-loader.min.js
└── webgl-utils.js
├── models
├── CesiumMan
│ ├── CesiumMan.gltf
│ ├── CesiumMan.jpg
│ └── CesiumMan0.bin
└── female02
│ ├── .htaccess
│ ├── 01_-_Default1noCulling.JPG
│ ├── 02_-_Default1noCulling.JPG
│ ├── 03_-_Default1noCulling.JPG
│ ├── Female02_bin.bin
│ ├── Female02_bin.js
│ ├── Female02_slim.js
│ ├── female02.mtl
│ ├── female02.obj
│ ├── female02_vertex_colors.obj
│ └── readme.txt
├── resources
├── gl-matrix.js
├── m4.js
├── models
│ ├── CesiumMan
│ │ ├── CesiumMan.gltf
│ │ ├── CesiumMan.jpg
│ │ └── CesiumMan0.bin
│ ├── killer_whale
│ │ ├── whale.CYCLES.bin
│ │ └── whale.CYCLES.gltf
│ └── simpleSkin.gltf
├── webgl-lessons-ui.js
├── webgl-tutorials.css
└── webgl-utils.js
├── rtsp.html
├── sample
├── index.html
└── textures
│ ├── grass.jpg
│ ├── misc.jpg
│ └── tree.png
├── webgl-skinning-3d-gltf-skinned.html
├── webgl-skinning-3d-gltf.html
├── webgl-skinning.html
├── 一些比较炫的例子
└── 星系
│ ├── css
│ └── style.css
│ ├── index.html
│ └── js
│ ├── TweenMax.min.js
│ ├── index.js
│ ├── stat.js
│ └── three.min.js
├── 代码库
└── 生成cube.html
├── 学习webgl
├── 你好三角形.html
└── 纹理.html
├── 新建文本文档.html
├── 第一章
├── camera.html
├── coordinateSystem.html
├── texture.html
├── transform.html
└── triangle.html
├── 第三章
├── FaceCulling.html
├── FrameBuffer_cube.html
├── FrameBuffer_cube.js
├── StencilTest.html
├── blending.html
├── blending2.html
├── cubemaps.html
├── depthTest.html
├── discard.html
├── wireframe.html
├── 天空盒-反射效果.html
├── 天空盒-折射效果.html
├── 实例化.html
├── 模板测试.html
├── 深度测试.html
├── 混合-半透明纹理.html
├── 混合-片段丢弃.html
└── 面剔除.html
├── 第二章
├── BaseLighting.html
├── LightingMaps-copy.html
├── LightingMaps.html
├── LoadModel.html
├── MirrorReflect.html
├── SpecularMaps.html
├── color.html
├── material.html
├── 光照贴图-漫反射贴图.html
├── 光照贴图-镜面光贴图.html
├── 基础光照.html
├── 多光源.html
├── 定向光.html
├── 材质.html
├── 点光源的衰减.html
├── 聚光.html
└── 聚光柔和.html
├── 第五章-动画
├── film-grain.html
└── 骨骼动画.html
├── 第四章-高级光照
├── Blinn-Phong.html
├── Gamma校正.html
├── HDR(高动态范围).html
├── PCF阴影消除锯齿.html
├── 多物体高精度PCF-副本.html
├── 多物体高精度PCF.html
├── 法线贴图.html
├── 泛光.html
├── 深度贴图.html
├── 视差贴图.html
├── 阴影映射.html
└── 高级光照.html
└── 视频纹理
├── index.html
├── test.mp4
└── webgl-demo.js
/Web.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/_lib/polygon.js:
--------------------------------------------------------------------------------
1 | // var va = vec4(0.0, 0.0, -1.0,1);
2 | // var vb = vec4(0.0, 0.942809, 0.333333, 1);
3 | // var vc = vec4(-0.816497, -0.471405, 0.333333, 1);
4 | // var vd = vec4(0.816497, -0.471405, 0.333333,1);
5 |
6 | function Polygon(position,normal,color,indices){
7 | this.position=position;
8 | this.normal=normal;
9 | this.color=color;
10 | this.indices=indices;
11 | }
12 | /**
13 | * 平面(2*0*2)
14 | */
15 | function Plane(color){
16 | // v0------v1
17 | // | |
18 | // | |
19 | // | |
20 | // v3------v2
21 | color=color||[1,1,1,1];
22 | var positions = [-1,0,-1, 1,0,-1, 1,0,1, -1,0,1],
23 | normals = [0,1,0, 0,1,0, 0,1,0, 0,1,0],
24 | colors = [],
25 | indices = new Uint8Array([0,2,3,0,1,2]);
26 | for(var i=0;i<4;i++){
27 | colors=colors.concat(color);
28 | }
29 |
30 | return new Polygon(positions,normals,colors,indices);
31 | }
32 |
33 | /**
34 | * 立方体(1*1*1)
35 | */
36 | function Cube(color){
37 | // v4----- v7
38 | // /| /|
39 | // v0------v1|
40 | // | | | |
41 | // | |v5---|-|v6
42 | // |/ |/
43 | // v3------v2
44 | //
45 | color=color||[1,1,1,1];
46 | var colors=[];
47 | for(var i=0;i<24;i++){
48 | colors.push(...color);
49 | }
50 |
51 | // 顶点
52 | var positions = [
53 | -1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, // v0-v1-v2-v3 front
54 | 1, 1, 1, 1, 1, -1, 1, -1,-1, 1, -1, 1, // v1-v7-v6-v2 right
55 | -1,1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, // v4-v7-v1-v0 up
56 | -1, 1, 1, -1,1, -1, -1,-1,-1, -1, -1, 1, // v0-v4-v5-v3 left
57 | -1,-1,-1, -1, -1, 1, 1, -1, 1, 1, -1,-1, // v5-v3-v2-v6 down
58 | -1,1, -1, -1,-1,-1, 1, -1,-1, 1, 1, -1 // v4-v5-v6-v7 back
59 | ];
60 |
61 | // 法向量
62 | var normals = [
63 | 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, // v0-v1-v2-v3 front
64 | 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, // v1-v7-v6-v2 right
65 | 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // v4-v7-v1-v0 up
66 | -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // v0-v4-v5-v3 left
67 | 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, // v5-v3-v2-v6 down
68 | 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1 // v4-v5-v6-v7 back
69 | ];
70 |
71 | // 顶点索引
72 | var indices = new Uint8Array([
73 | 0, 1, 2, 0, 2, 3, // front
74 | 4, 5, 6, 4, 6, 7, // right
75 | 8, 9,10, 8,10,11, // up
76 | 12,13,14, 12,14,15, // left
77 | 16,17,18, 16,18,19, // down
78 | 20,21,22, 20,22,23 // back
79 | ]);
80 |
81 | return new Polygon(positions,normals,colors,indices);
82 | }
83 |
84 | /**
85 | * 圆球(1*1*1)
86 | */
87 | function Sphere(len, color) {
88 | len = len || 15;
89 | color=color||[1,1,1,1];
90 |
91 | var i, ai, si, ci;
92 | var j, aj, sj, cj;
93 | var p1, p2;
94 | var pos = [],nor=[];
95 |
96 | var positions = [],
97 | normals = [],
98 | colors = [],
99 | indices = [];
100 |
101 | // 创建顶点坐标
102 | for (j = 0; j <= len; j++) {
103 | aj = j * Math.PI / len;
104 | sj = Math.sin(aj);
105 | cj = Math.cos(aj);
106 | for (i = 0; i <= len; i++) {
107 | ai = i * 2 * Math.PI / len;
108 | si = Math.sin(ai);
109 | ci = Math.cos(ai);
110 |
111 | pos = [si * sj, cj, ci * sj];// x y z
112 | positions.push(...pos);
113 |
114 | nor=normalize(pos);// 归一化后的顶点坐标就是法向量
115 | normals.push(...nor);
116 |
117 | colors.push(...color);// 颜色
118 | }
119 | }
120 | // 创建顶点索引
121 | for (j = 0; j < len; j++) {
122 | for (i = 0; i < len; i++) {
123 | p1 = j * (len + 1) + i;
124 | p2 = p1 + (len + 1);
125 |
126 | indices.push(p1);
127 | indices.push(p2);
128 | indices.push(p1 + 1);
129 |
130 | indices.push(p1 + 1);
131 | indices.push(p2);
132 | indices.push(p2 + 1);
133 | }
134 | }
135 |
136 | return new Polygon(positions,normals,colors,indices);
137 | }
138 |
139 | /**
140 | * 圆柱体
141 | */
142 | function Cylinder(r,h,l,color){
143 | // 8
144 |
145 | // 1 5
146 | // 0 4
147 |
148 | // 2 6
149 | // 3 7
150 |
151 | // 9
152 | var angle=Math.PI*2/l,
153 | x=0, z=0,
154 | color=color||[1,1,1,1],
155 | colors=[],
156 | positions=[],
157 | normals=[],
158 | indices=[];
159 |
160 | for(var i=0;i element
99 | * @param opt_debug flag to initialize the context for debugging
100 | * @return the rendering context for WebGL
101 | */
102 | function getWebGLContext(canvas, opt_debug) {
103 | // Get the rendering context for WebGL
104 | var gl = WebGLUtils.setupWebGL(canvas);
105 | if (!gl) return null;
106 |
107 | // if opt_debug is explicitly false, create the context for debugging
108 | if (arguments.length < 2 || opt_debug) {
109 | gl = WebGLDebugUtils.makeDebugContext(gl);
110 | }
111 |
112 | return gl;
113 | }
114 |
--------------------------------------------------------------------------------
/lib/webgl-utils.js:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010, Google Inc.
3 | * All rights reserved.
4 | *
5 | * Redistribution and use in source and binary forms, with or without
6 | * modification, are permitted provided that the following conditions are
7 | * met:
8 | *
9 | * * Redistributions of source code must retain the above copyright
10 | * notice, this list of conditions and the following disclaimer.
11 | * * Redistributions in binary form must reproduce the above
12 | * copyright notice, this list of conditions and the following disclaimer
13 | * in the documentation and/or other materials provided with the
14 | * distribution.
15 | * * Neither the name of Google Inc. nor the names of its
16 | * contributors may be used to endorse or promote products derived from
17 | * this software without specific prior written permission.
18 | *
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 | */
31 |
32 |
33 | /**
34 | * @fileoverview This file contains functions every webgl program will need
35 | * a version of one way or another.
36 | *
37 | * Instead of setting up a context manually it is recommended to
38 | * use. This will check for success or failure. On failure it
39 | * will attempt to present an approriate message to the user.
40 | *
41 | * gl = WebGLUtils.setupWebGL(canvas);
42 | *
43 | * For animated WebGL apps use of setTimeout or setInterval are
44 | * discouraged. It is recommended you structure your rendering
45 | * loop like this.
46 | *
47 | * function render() {
48 | * window.requestAnimationFrame(render, canvas);
49 | *
50 | * // do rendering
51 | * ...
52 | * }
53 | * render();
54 | *
55 | * This will call your rendering function up to the refresh rate
56 | * of your display but will stop rendering if your app is not
57 | * visible.
58 | */
59 |
60 | WebGLUtils = function() {
61 |
62 | /**
63 | * Creates the HTLM for a failure message
64 | * @param {string} canvasContainerId id of container of th
65 | * canvas.
66 | * @return {string} The html.
67 | */
68 | var makeFailHTML = function(msg) {
69 | return '' +
70 | '
' + msg + '
';
71 | return '' +
72 | '
' +
73 | '
' +
74 | '
' +
75 | '
' + msg + '
' +
76 | '
' +
77 | '
';
78 | };
79 |
80 | /**
81 | * Mesasge for getting a webgl browser
82 | * @type {string}
83 | */
84 | var GET_A_WEBGL_BROWSER = '' +
85 | 'This page requires a browser that supports WebGL. ' +
86 | 'Click here to upgrade your browser.';
87 |
88 | /**
89 | * Mesasge for need better hardware
90 | * @type {string}
91 | */
92 | var OTHER_PROBLEM = '' +
93 | "It doesn't appear your computer can support WebGL. " +
94 | 'Click here for more information.';
95 |
96 | /**
97 | * Creates a webgl context. If creation fails it will
98 | * change the contents of the container of the