-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.html
104 lines (92 loc) · 3.95 KB
/
index.html
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>Three Body</title>
<!--<style>canvas { width: 100%; height: 100% }</style>-->
</head>
<body>
<script src="lib/jquery-1.8.3.min.js"></script>
<script src="lib/three.js"></script>
<script src="lib/stats.min.js"></script>
<script src="lib/dat.gui.min.js"></script>
<script src="lib/uclass_BeveledBlockGeometry.js"></script>
<!-- ---------------- Custom Shader Code ------------------------ -->
<script id="vertexShader" type="x-shader/x-vertex">
varying vec2 vUv;
void main()
{
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
}
</script>
<!-- fragment shader a.k.a. pixel shader -->
<script id="noiseFragmentShader" type="x-shader/x-vertex">
// noise randomizing
uniform sampler2D baseTexture;
uniform sampler2D noiseTexture;
uniform float baseSpeed; // speed of changing the sampling on the noise texture
uniform float noiseScale;
uniform float alpha;
uniform float time; // need to update this variable each frame
// color ramp sampling
uniform sampler2D colorRampTexture;
uniform float darkValue; // 0~1, the coordinate on the color ramp for the darkest value
uniform float lightValue; // 0~1, the coordinate on the color ramp for the lightest value
varying vec2 vUv;
void main()
{
vec2 uvTimeShift = vUv + vec2( -0.7, 1.5 ) * time * baseSpeed;
vec4 noiseGeneratorTimeShift = texture2D( noiseTexture, uvTimeShift );
vec2 uvNoiseTimeShift = vUv + noiseScale * vec2( noiseGeneratorTimeShift.r, 0 ); // only shift in x direction because of sphere wrapping
vec4 grayScale = texture2D( baseTexture, uvNoiseTimeShift);
vec4 resultColor = texture2D(colorRampTexture, vec2(darkValue + grayScale.r * (lightValue - darkValue), 0));
//vec4 resultColor = texture2D(colorRampTexture, vec2(lightValue, 0));
resultColor.a = alpha;
//gl_FragColor = vec4(resultColor.r * grayScale.r, resultColor.g * grayScale.r, resultColor.b * grayScale.r, alpha);
gl_FragColor = resultColor;
}
</script>
<script id="coronaFragmentShader" type="x-shader/x-vertex">
// noise randomizing
uniform sampler2D noiseTexture;
uniform float baseSpeed; // speed of changing the sampling on the noise texture
uniform float noiseScale;
uniform float time; // need to update this variable each frame
// color ramp sampling
uniform sampler2D colorRampTexture;
uniform float colorRampValue; // 0~1, the coordinate on the color ramp for the corona color
// corona attributes
uniform float alpha;
uniform float innerRadius; // 0~1
uniform float rotation; // 0~1
varying vec2 vUv;
void main()
{
float d = distance(vUv, vec2(0.5, 0.5)) * 2.0; // 0~1
vec4 color = texture2D(colorRampTexture, vec2(colorRampValue, 0));
color.a = alpha;
if (d > innerRadius)
{
vec2 pos = vUv - vec2(0.5, 0.5);
float angle = atan(pos.y, pos.x);
vec2 noiseUv = vec2( 1.0, 0 ) * time * baseSpeed + vec2(0.0, rotation + angle / 6.28318530718);
vec4 noiseValue = texture2D( noiseTexture, noiseUv );
color.a = alpha * (1.0 + (d - innerRadius) / (innerRadius - 1.0) / noiseValue.r);
}
gl_FragColor = color;
}
</script>
<!-- ----------------------------------------------------------- -->
<!-- js files for three body project -->
<script src="js/utils.js"></script>
<script src="js/Star.js"></script>
<script src="js/OrbitControls.js"></script>
<script src="js/FreeControls.js"></script>
<script src="js/RotationDisplay.js"></script>
<script src="js/AxisIndicator.js"></script>
<script src="js/StarMaterial.js"></script>
<script src="js/CoronaMaterial.js"></script>
<script src="js/DrinkingBird.js"></script>
<script src="js/main.js"></script>
</body>
</html>