-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathtest1.html
156 lines (126 loc) · 4.87 KB
/
test1.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
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Fathom - simple website analytics - https://github.com/usefathom/fathom -->
<script>
(function(f, a, t, h, o, m){
a[h]=a[h]||function(){
(a[h].q=a[h].q||[]).push(arguments)
};
o=f.createElement('script'),
m=f.getElementsByTagName('script')[0];
o.async=1; o.src=t; o.id='fathom-script';
m.parentNode.insertBefore(o,m)
})(document, window, '//stats.josh.earth/tracker.js', 'fathom');
fathom('set', 'siteId', 'GISNV');
fathom('trackPageview');
</script>
<!-- / Fathom -->
<meta charset="UTF-8">
<title>Title</title>
<style type="text/css">
html, body {
padding:0;
margin:0;
}
</style>
<script src="./node_modules/three/build/three.min.js"></script>
</head>
<body>
<script type="x-shader/x-vertex" id="vertexShader">
attribute float vertexDisplacement; //defined by the attribute, one per vertex
uniform float delta; //constant supplied by the render method
varying float vOpacity; //output for the fragment shader
varying vec3 vUv; //output for the fragment shader
void main()
{
//displace the position based on the vertex displacement
vec3 p = position;
// p.x += sin(delta) * vertexDisplacement;
// p.y += cos(delta) * vertexDisplacement;
// p.x += vertexDisplacement * 1.0;
// p.y += vertexDisplacement * 1.0;
//calculate the final vertex position
vec4 modelViewPosition = modelViewMatrix * vec4(p, 1.0);
gl_Position = projectionMatrix * modelViewPosition;
//pass these through to the fragment shader
vUv = position;
vOpacity = vertexDisplacement;
}
</script>
<script type="x-shader/x-fragment" id="fragmentShader">
uniform float delta; //constant supplied by the render method
varying float vOpacity; //input from the vertex shader
varying vec3 vUv; //input from the vertex shader
void main() {
float r = 1.0;// + cos(vUv.x * delta);
float g = 0.0;// + sin(delta) * 0.5;
float b = sin((vOpacity+delta*2.0)*10.0);
vec3 rgb = vec3(r, g, b);
gl_FragColor = vec4(rgb, 1.0);
}
</script>
<script type="module">
let scene, camera, renderer
let dodeca_mesh
function init() {
//setup canvas
const container = document.createElement( 'div' );
document.body.appendChild( container );
//setup scene and cameras
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x000000 );
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 50 );
//setup light
var light = new THREE.DirectionalLight( 0xffffff, 0.5 );
light.position.set( 1, 1, 1 ).normalize();
scene.add( light );
//setup renderer
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
container.appendChild( renderer.domElement );
//setup events
window.addEventListener( 'resize', ()=>{
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
},false);
//setup the geometry
// const dodeca_geo = new THREE.BoxGeometry(1,1,1)
//extra detail so we can see lots of lines
const dodecad = new THREE.DodecahedronBufferGeometry(2,0)
const dodeca_geo = new THREE.EdgesGeometry(dodecad)
var vertexDisplacement = new Float32Array(dodeca_geo.attributes.position.count);
for (var i = 0; i < vertexDisplacement.length; i ++) {
vertexDisplacement[i] = i//Math.sin(i)
}
dodeca_geo.addAttribute('vertexDisplacement', new THREE.BufferAttribute(vertexDisplacement, 1));
// const dodeca_mat = new THREE.MeshLambertMaterial({color:0xff0000})
// const dodeca_mat = new THREE.LineBasicMaterial({color:0x0000FF})
//setup the shader material
var customUniforms = {
delta: {value: 0}
};
var dodeca_mat = new THREE.ShaderMaterial({
uniforms: customUniforms,
vertexShader: document.getElementById( 'vertexShader' ).textContent,
fragmentShader: document.getElementById( 'fragmentShader' ).textContent
});
//combine into a line loop
dodeca_mesh = new THREE.LineSegments(dodeca_geo, dodeca_mat)
dodeca_mesh.position.z = -5
scene.add(dodeca_mesh)
}
var delta = 0;
function render(time) {
delta += 0.1;
dodeca_mesh.material.uniforms.delta.value = 0.5 + Math.sin(delta) * 0.5;
dodeca_mesh.rotation.y += 0.001
renderer.render( scene, camera );
}
init();
renderer.setAnimationLoop( render );
</script>
</body>
</html>