-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
170 lines (122 loc) · 4.32 KB
/
Copy pathindex.js
File metadata and controls
170 lines (122 loc) · 4.32 KB
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
import * as THREE from 'three';
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass.js';
import { AfterimagePass } from 'three/examples/jsm/postprocessing/AfterimagePass.js';
import { FilmPass } from 'three/examples/jsm/postprocessing/FilmPass.js';
import DistortedSphere from './src/utilities/DistortedSphere.js';
import ParticleManager from './src/utilities/particleManager.js';
import Glow from './src/utilities/glow.js';
import Stars from './src/utilities/stars.js';
import {cssInit, showText} from './src/index_css.js';
require('normalize.css/normalize.css');
require('./src/index.css');
__webpack_public_path__ = window.myDynamicPublicPath;
let scene, camera, renderer, container, start = Date.now(), particleManager, sphere, glow, stars, composer;
window.onload = function () {
showText();
cssInit();
initScene();
// this is really important stops obects rendering on top of each other
initClearPlane();
initPostProcessing();
initObjects();
addEventListeners();
animate();
}
function initScene() {
scene = new THREE.Scene();
//scene.fog = new THREE.Fog( 0x000000, 1, 1000 );
container = document.getElementById('canvas');
var width = container.offsetWidth;
var height = container.offsetHeight;
camera = new THREE.PerspectiveCamera(
75,
width / height,
0.1,
1000
);
camera.position.set(0, -30, 8);
camera.lookAt(new THREE.Vector3(0, 0, 0));
renderer = new THREE.WebGLRenderer({
//preserveDrawingBuffer: true,
alpha: true,
//antialias: true,
});
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize(width, height);
container.appendChild(renderer.domElement);
}
function initClearPlane() {
var clearPlane = new THREE.Mesh(
new THREE.PlaneGeometry(2700, 2700),
new THREE.MeshBasicMaterial({
transparent: true,
color: 0x000000,
opacity: 0.1,
})
);
clearPlane.position.z = 0;
scene.add(clearPlane);
}
function initPostProcessing() {
// post-processing
composer = new EffectComposer(renderer);
composer.addPass(new RenderPass(scene, camera));
var afterimagePass = new AfterimagePass();
afterimagePass.uniforms['damp'].value = 0.95;
composer.addPass(afterimagePass);
const filmPass = new FilmPass(
0.35, // noise intensity
0.025, // scanline intensity
648, // scanline count
false, // grayscale
);
filmPass.renderToScreen = true;
composer.addPass(filmPass);
}
function initObjects() {
// inits disorted sphere
// radius, speed, color, density, strength, frequency, amplitude, offset
sphere = new DistortedSphere(5, 0.1, 0, 10, 0.4, 2, 1, 0);
scene.add(sphere);
// inits particles
particleManager = new ParticleManager(3000);
scene.add(particleManager.points);
// glow under effect
glow = new Glow();
scene.add(glow);
stars = new Stars(3000).stars;
scene.add(stars);
}
function animate() {
requestAnimationFrame(animate);
// animates distorted sphere
// updates the shaders time allowing for animation
sphere.material.uniforms.uTime.value = 0.001 * (Date.now() - start)
// animate orbiting particles
particleManager.particles.forEach((particle, i) => {
particle.updateVelocity();
particle.updatePosition();
particleManager.positions.set([particle.pos.x, particle.pos.y, 0], i * 3);
});
particleManager.geometry.attributes.position.needsUpdate = true;
//animate stars
stars.rotation.y += -0.0002;
//renderer.render(scene, camera);
composer.render();
}
// below here contains event listeners init
function addEventListeners() {
window.addEventListener('resize', onWindowResize, false);
}
function onWindowResize() {
container = document.getElementById('canvas');
var width = container.offsetWidth;
var height = container.offsetHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize(width, height);
composer.setPixelRatio( window.devicePixelRatio );
composer.setSize(width, height);
}