-
Notifications
You must be signed in to change notification settings - Fork 4
/
shader.html
266 lines (223 loc) · 6.18 KB
/
shader.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<!DOCTYPE html>
<html lang="en">
<head>
<title>Workshop</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
font-family: Monospace;
background-color: #000;
color: #000;
margin: 0px;
overflow: hidden;
}
#info {
color: #000;
position: absolute;
top: 10px;
width: 100%;
text-align: center;
z-index: 100;
display:block;
}
#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
</style>
</head>
<body>
<div id="workshop"></div>
<script src="js/three.min.r58.js"></script>
<script src="js/OBJLoader.js"></script>
<script src="js/FirstPersonControls.js"></script>
<script src="js/sphere-shader.js"></script>
</body>
</html>
<script id="vertex-basic" type="x-shader/x-vertex">
varying vec3 vNormal;
void main()
{
vNormal = normal;
gl_Position = vec4(position, 1.0);
}
</script>
<script id="vertex-sphere" type="x-shader/x-vertex">
varying vec3 vNormal;
void main()
{
vNormal = normal;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
</script>
<script id="fragment-gradient" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 resolution;
uniform vec2 mouse;
uniform float time;
varying vec3 vNormal;
vec2 position = gl_FragCoord.xy / resolution;
void main() {
gl_FragColor = vec4(cos(position.x * 30.0) * 0.5 + 0.5, position.y, sin(time), mouse.y); //position.y, (1.0 - position.x), 1.0);
}
</script>
<script id="fragment-mouse-gradient" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 resolution;
uniform vec2 mouse;
uniform float time;
varying vec3 vNormal;
vec2 position = gl_FragCoord.xy / resolution;
void main() {
vec3 light = vec3(mouse.x, 1.0 - mouse.y, 1.0);
light = normalize(light);
float reflection = max(0.0, dot(light, vNormal));
gl_FragColor = vec4(position.x, position.y, (1.0 - position.x), 1.0) * reflection;
}
</script>
<script id="fragment-shifting" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
vec2 fitPlane(vec2 positive) {
return positive * 2.0 - 1.0;
}
float fitPositive(float plane) {
return plane * 0.5 + 0.5;
}
uniform vec2 resolution;
uniform vec2 mouse;
uniform float time;
varying vec3 vNormal;
vec2 position = fitPlane(gl_FragCoord.xy / resolution);
vec2 clock = vec2(sin(time*3.0), cos(time*3.0));
float progress = dot(clock, position) * 0.5 + 0.5;
void main() {
vec3 light = vec3(mouse.x, 1.0 - mouse.y, 1.0);
light = normalize(light);
float reflection = max(0.0, dot(light, vNormal));
gl_FragColor = vec4(progress, 1.0 - progress, 0.0, 1.0) * reflection;
}
</script>
<script id="fragment-orb" type="x-shader/x-fragment">
#ifdef GL_ES
precision highp float;
#endif
uniform vec2 resolution;
uniform vec2 mouse;
uniform float time;
float huetorgb(float v1, float v2, float vH)
{
float ret;
if ( vH < 0.0 )
vH += 1.0;
if ( vH > 1.0 )
vH -= 1.0;
if ( ( 6.0 * vH ) < 1.0 )
ret = ( v1 + ( v2 - v1 ) * 6.0 * vH );
else if ( ( 2.0 * vH ) < 1.0 )
ret = ( v2 );
else if ( ( 3.0 * vH ) < 2.0 )
ret = ( v1 + ( v2 - v1 ) * ( ( 2.0 / 3.0 ) - vH ) * 6.0 );
else
ret = v1;
return ret;
}
vec3 rgbtohsl(vec3 rgb)
{
float Cmax, Cmin;
float D;
float H, S, L;
float R, G, B;
R = rgb.r;
G = rgb.g;
B = rgb.b;
// convert to HSL
Cmax = max (R, max (G, B));
Cmin = min (R, min (G, B));
L = (Cmax + Cmin) / 2.0;
if (Cmax == Cmin) {
H = 0.0; // it's actually undefined
S = 0.0;
} else {
D = Cmax - Cmin; // we know D != 0 so we cas safely divide by it
// calculate Saturation
if (L < 0.5) {
S = D / (Cmax + Cmin);
} else {
S = D / (2.0 - (Cmax + Cmin));
}
// calculate Hue
if (R == Cmax) {
H = (G - B) / D;
} else {
if (G == Cmax) {
H = 2.0 + (B - R) /D;
} else {
H = 4.0 + (R - G) / D;
}
}
H = H / 6.0;
}
if (H < 0.0) {
H = H + 1.0;
}
H = clamp(H, 0.0, 1.0);
S = clamp(S, 0.0, 1.0);
L = clamp(L, 0.0, 1.0);
return vec3(H, S, L);
}
vec3 hsltorgb(vec3 hsl) {
float H = hsl.x;
float S = hsl.y;
float L = hsl.z;
float R, G, B;
float order, var_1;
if (S == 0.0) {
R = L;
G = L;
B = L;
} else {
if ( L < 0.5 ) {
order = L * ( 1.0 + S );
} else {
order = ( L + S ) - ( S * L );
}
var_1 = 2.0 * L - order;
R = huetorgb( var_1, order, H + ( 1.0 / 3.0 ) );
G = huetorgb( var_1, order, H );
B = huetorgb( var_1, order, H - ( 1.0 / 3.0 ) );
}
return vec3(R, G, B);
}
void main(void)
{
vec2 path;
path.x = cos(time) * 0.4;
path.y = sin(time*1.25) * 0.4;
vec2 orbit = (path + 1.0) * resolution.xy / 2.0;
vec2 frag = gl_FragCoord.xy;
vec2 flect = (mouse + 1.0) * resolution * 0.5;
flect.y = resolution.xy.y-flect.y;
vec2 obelisk = resolution.xy * 0.3;
vec3 colorOrbit = vec3(0.5, 1.0, 1.0);
vec3 colorMouse = vec3(1.0, 1.0, 1.0);
vec3 colorObelisk = vec3(0.0, 1.0, 1.0);
float radiusOrbit = sqrt(dot(frag - orbit, frag - orbit));
float radiusMouse = sqrt(dot(frag - flect, frag - flect));
float radiusObelisk = sqrt(dot(frag - obelisk, frag - obelisk));
float scale = 40.0;
float totalPortion = radiusOrbit + radiusMouse + radiusObelisk;
float portionOrbit = radiusOrbit / totalPortion;
float portionMouse = radiusMouse / totalPortion;
float portionObelisk = radiusObelisk / totalPortion;
float intensity = (1.0/radiusOrbit+1.0/radiusMouse+1.0/radiusObelisk)*scale;
intensity = clamp(intensity, 0.0, 0.7);
vec3 blend = colorOrbit*portionOrbit+colorMouse*portionMouse+colorObelisk*portionObelisk;
blend = blend*intensity;
vec3 rgb = hsltorgb(blend);
gl_FragColor = vec4(rgb, 1.0);
}
</script>