forked from google/swissgl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCubeDeform.js
36 lines (34 loc) · 1.24 KB
/
CubeDeform.js
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
/** @license
* Copyright 2023 Google LLC.
* SPDX-License-Identifier: Apache-2.0
*/
class CubeDeform {
static Tags = ['3d'];
frame(glsl, params) {
glsl({...params, Grid:[6,1], Mesh:[20, 20],
Aspect:'fit', DepthTest:1, Inc:`
varying vec3 color, normal, eyeDir;`, VP:`
vec3 surface_f(vec2 xy) {
vec3 pos = cubeVert(xy, ID.x);
pos += sin(pos*PI+time).zxy*0.2;
pos = mix(pos, normalize(pos)*1.5, sin(time)*0.8+0.2);
pos.xy *= rot2(PI/4.+time*0.2);
pos.yz *= rot2(PI/3.0);
return pos*0.4;
}
void vertex() {
color = cubeVert(vec2(0), ID.x)*0.5+0.5;
vec4 v = vec4(SURF(surface_f, XY, normal, 1e-3), 1.0);
eyeDir = cameraPos()-v.xyz;
VOut = wld2proj(v);
}`, FP:`
vec3 n = normalize(normal);
vec3 lightDir = normalize(vec3(0,1,1));
float diffuse = dot(n, lightDir)*0.5+0.5;
vec3 halfVec = normalize(lightDir+normalize(eyeDir));
float spec = smoothstep(0.998, 0.999, dot(halfVec, n));
FOut.rgb = color*diffuse + 0.3*spec;
vec2 m = UV*4.0;
FOut.rgb = mix(FOut.rgb, vec3(1.0), (isoline(m.x)+isoline(m.y))*0.25);`});
}
}