-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticle_System.html
More file actions
104 lines (79 loc) · 3.56 KB
/
Copy pathParticle_System.html
File metadata and controls
104 lines (79 loc) · 3.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Particle System</title>
<meta charset="utf-8">
</head>
<script id="shader-vs" type="x-shader/x-vertex">
attribute vec3 aVertexNormal;
attribute vec3 aVertexPosition;
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat3 uNMatrix;
uniform vec3 uLightPosition;
uniform vec3 uAmbientLightColor;
uniform vec3 uDiffuseLightColor;
uniform vec3 uSpecularLightColor;
uniform vec3 uAmbientMatColor;
uniform vec3 uDiffuseMatColor;
uniform vec3 uSpecularMatColor;
const float shininess = 32.0;
varying vec4 vColor;
void main(void) {
// Get the vertex position in eye coordinates
vec4 vertexPositionEye4 = uMVMatrix * vec4(aVertexPosition, 1.0);
vec3 vertexPositionEye3 = vertexPositionEye4.xyz;
// Calculate the vector (l) to the light source
vec3 vectorToLightSource = normalize(uLightPosition - vertexPositionEye3);
// Transform the normal (n) to eye coordinates
vec3 normalEye = normalize(uNMatrix * aVertexNormal);
// Calculate n dot l for diffuse lighting
float diffuseLightWeighting = max(dot(normalEye,
vectorToLightSource), 0.0);
// Calculate the reflection vector (r) that is needed for specular light
vec3 reflectionVector = normalize(reflect(-vectorToLightSource,
normalEye));
// The camera in eye coordinates is located at the origin and is pointing
// along the negative z-axis. Calculate viewVector (v)
// in eye coordinates as:
// (0.0, 0.0, 0.0) - vertexPositionEye3
vec3 viewVectorEye = -normalize(vertexPositionEye3);
float rdotv = max(dot(reflectionVector, viewVectorEye), 0.0);
float specularLightWeighting = pow(rdotv, shininess);
// Sum up all three reflection components and send to the fragment shader
vColor = vec4((uAmbientLightColor * uAmbientMatColor)
+ ((uDiffuseLightColor * uDiffuseMatColor) * diffuseLightWeighting)
+ ((uSpecularLightColor * uSpecularMatColor) * specularLightWeighting),1.0);
gl_Position = uPMatrix*uMVMatrix*vec4(aVertexPosition, 1.0);
}
</script>
<script id="shader-fs" type="x-shader/x-fragment">
precision mediump float;
varying vec4 vColor;
void main(void) {
gl_FragColor = vColor;
}
</script>
<script src="gl-matrix-min.js"></script>
<script src="webgl-utils.js"></script>
<script src="simpleModeling.js"></script>
<script src="Particle_System.js"></script>
<body onload="startup();">
<canvas id="myGLCanvas" width="800" height="800"></canvas>
</body>
<section>
<h1>Controls</h1>
<p>
Left Arrow - Go Left | Right Arrow - Go Right | Up Arrow - Go Up | Down Arrow - Go Down | O - Go Forward | P - Go Backward | U - Rotate View Left | I - Rotate View Right<br /><br />
A - Add a Random Sphere | Q - Add a Big Red Sphere | W - Add a Big Green Sphere | E - Add a Big Blue Sphere | Z - Remove Most Recent Sphere | H - Delete All Spheres<br /><br />
G - Toggle Gravity | D - Toggle Drag<br /><br />
T - Increase Coefficient of Restitution | Y - Decrease Coefficient of Restitution<br /><br />
J - Speed Up All Spheres | K - Slow Down All Spheres<br /><br />
L - Gravity Demo<br /><br />
R - Reset Everything
</p>
</section>
<section>
<h1>Created by Dan Johnson</h1>
</section>
</html>