-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbox.html
173 lines (141 loc) · 6.69 KB
/
box.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
<!DOCTYPE html>
<html>
<head>
<meta charset=UTF-8 />
</head>
<body>
<script src="//cdnjs.cloudflare.com/ajax/libs/three.js/r126/three.min.js"></script>
<script src="OrbitControls.js"></script>
<script id="vertexShader" type="x-shader/x-vertex">
uniform vec2 resolution;
uniform vec2 posi;
uniform float operation;
varying vec3 vUv;
varying vec4 modelViewPosition;
varying vec3 vecNormal;
void main() {
float x;
float y;
if (operation == 0.) {
x = position[0] + posi.x;
y = position[1] + posi.y;
} else {
x = position[0] - posi.x;
y = position[1] - posi.y;
}
vUv = position;
vec4 modelViewPosition = modelViewMatrix * vec4(x, y, position.z, 1.0);
vecNormal = (modelViewMatrix * vec4(normal, 0.0)).xyz; //????????
gl_Position = projectionMatrix * modelViewPosition;
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
uniform vec2 resolution;
uniform vec2 posi;
uniform vec3 color;
void main() {
float x;
// float x = 1.; // mod(time + gl_FragCoord.x, 20.) < 10. ? 1. : 0.;
// float y = 1.; // mod(time + gl_FragCoord.y, 20.) < 10. ? 1. : 0.;
// float alpha = 0.; //gl_FragCoord.x * 0.0002;
gl_FragColor = vec4(color, 1.);
}
</script>
<script>
var container;
var camera, scene, renderer;
var uniforms, material, mesh;
var mouseX = 0, mouseY = 0,
lat = 0, lon = 0, phy = 0, theta = 0;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
var startTime;
function init() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(55, window.innerWidth / window.innerHeight, 45, 30000);
camera.position.set(-10500, 4500, 0);
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
let controls = new THREE.OrbitControls(camera);
controls.addEventListener('change', renderer);
controls.minDistance = 500;
controls.maxDistance = 1500;
let materialArray = [];
let texture_ft = new THREE.TextureLoader().load('images/blue_background.jpeg');
let texture_bk = new THREE.TextureLoader().load('images/blue_background.jpeg');
let texture_up = new THREE.TextureLoader().load('images/blue_background.jpeg');
let texture_dn = new THREE.TextureLoader().load('images/blue_background.jpeg');
let texture_rt = new THREE.TextureLoader().load('images/blue_background.jpeg');
let texture_lf = new THREE.TextureLoader().load('images/blue_background.jpeg');
materialArray.push(new THREE.MeshBasicMaterial({ map: texture_ft }));
materialArray.push(new THREE.MeshBasicMaterial({ map: texture_bk }));
materialArray.push(new THREE.MeshBasicMaterial({ map: texture_up }));
materialArray.push(new THREE.MeshBasicMaterial({ map: texture_dn }));
materialArray.push(new THREE.MeshBasicMaterial({ map: texture_rt }));
materialArray.push(new THREE.MeshBasicMaterial({ map: texture_lf }));
for (let i = 0; i < 6; i++)
materialArray[i].side = THREE.BackSide;
let skyboxGeo = new THREE.BoxGeometry(10000, 10000, 10000);
let skybox = new THREE.Mesh(skyboxGeo, materialArray);
scene.add(skybox);
// Code ------------------------------------------------------------------------
scene.add( new THREE.AmbientLight( 0x505050 ) );
const light = new THREE.SpotLight( 0xffffff, 1.5 );
light.position.set( 0, 500, 2000 );
light.angle = Math.PI / 9;
light.castShadow = true;
light.shadow.camera.near = 1000;
light.shadow.camera.far = 4000;
light.shadow.mapSize.width = 1024;
light.shadow.mapSize.height = 1024;
scene.add( light );
uniforms = {
time: { type: "f", value: 1.0 },
resolution: { type: "v2", value: new THREE.Vector2() },
posi: { type: "f", value: new THREE.Vector2() },
operation: { type: 'f', value: 0. },
color: {type: 'vec3', value: new THREE.Color(0xACB6E5)}
};
material = new THREE.ShaderMaterial({
uniforms: uniforms,
vertexShader: document.getElementById('vertexShader').textContent,
fragmentShader: document.getElementById('fragmentShader').textContent
});
const geometry = new THREE.BoxGeometry( 10, 10, 10 );
console.log( new Float32Array(72));
for ( let i = 0; i < 2000; i ++ ) {
const object = new THREE.Mesh( geometry, material);
object.position.x = Math.random() * 50000 - 10000;
object.position.y = Math.random() * 20000 - 10000;
object.position.z = Math.random() * 20000 - 10000;
object.rotation.x = Math.random() * 2 * Math.PI;
object.rotation.y = Math.random() * 2 * Math.PI;
object.rotation.z = Math.random() * 2 * Math.PI;
object.scale.x = Math.random() * 2 + 1;
object.scale.y = Math.random() * 2 + 1;
object.scale.z = Math.random() * 2 + 1;
object.castShadow = true;
object.receiveShadow = true;
scene.add( object );
}
renderer.setPixelRatio(window.devicePixelRatio ? window.devicePixelRatio : 1);
uniforms.resolution.value.x = window.innerWidth/2;
uniforms.resolution.value.y = window.innerHeight/2;
startTime = Date.now()
animate();
}
function animate() {
var elapsedMilliseconds = Date.now() - startTime;
var elapsedSeconds = elapsedMilliseconds / 1000.;
uniforms.posi.value.x = Math.random();
uniforms.posi.value.y = Math.random() * 60. * (elapsedSeconds % 30.);
// uniforms.color.value = new THREE.Color(Math.random() * 0xffffff);
uniforms.operation.value = Math.random() > 0.5 ? 0. : 1.;
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
init();
</script>
</body>
</html>