-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·78 lines (61 loc) · 1.56 KB
/
app.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
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
var container;
var camera, scene, renderer;
var uniforms;
init();
animate();
function init() {
container = document.getElementById( 'container' );
camera = new THREE.Camera();
camera.position.z = 1;
scene = new THREE.Scene();
var geometry = new THREE.PlaneBufferGeometry( 2, 2 );
uniforms = {
time: {
type: "f",
value: 1.0
},
resolution: {
type: "v2",
value: new THREE.Vector2()
},
mouse: {
type: "v2",
value: new THREE.Vector2()
}
};
var fragment =document.getElementById( 'fragmentShader' ).textContent;
fragment = frag;
console.log(frag);
var vertex = document.getElementById( 'vertexShader' ).textContent;
vertex = vert;
console.log(vert);
var material = new THREE.ShaderMaterial({
uniforms: uniforms,
vertexShader: vertex,
fragmentShader: fragment
});
var mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
container.appendChild( renderer.domElement );
onWindowResize();
window.addEventListener( 'resize', onWindowResize, false );
document.onmousemove = function(e){
uniforms.mouse.value.x = e.pageX
uniforms.mouse.value.y = e.pageY
};
}
function onWindowResize( event ) {
renderer.setSize( window.innerWidth, window.innerHeight );
uniforms.resolution.value.x = renderer.domElement.width;
uniforms.resolution.value.y = renderer.domElement.height;
}
function animate() {
requestAnimationFrame( animate );
render();
}
function render() {
uniforms.time.value += 0.05;
renderer.render( scene, camera );
}