-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvs.js
58 lines (41 loc) · 1.16 KB
/
vs.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
const shader = `
precision highp float;
#define SPHERES 200
attribute vec3 position;
attribute vec3 normal;
varying vec3 vPosition;
varying float occlusion;
uniform mat4 modelMatrix;
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform vec3 positions[ SPHERES ];
uniform float scales[ SPHERES ];
uniform float theme;
void main() {
vPosition = ( modelMatrix * vec4( position, 1. ) ).xyz;
gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1. );
vec3 on = normalize( mat3( modelMatrix[0].xyz, modelMatrix[1].xyz, modelMatrix[2].xyz ) * normal );
occlusion = 0.;
float l;
float t;
for( int i = 0; i < SPHERES; i++ ) {
vec3 dir = positions[ i ] - vPosition;
float l = dir.x * dir.x + dir.y * dir.y + dir.z * dir.z;
float t = 1. - max( 0., dot( on, dir / sqrt( l ) ) ) * scales[ i ] / l;
occlusion += t;
}
occlusion /= float( SPHERES );
if(theme == 0.) {
// light
occlusion *= 4.;
occlusion -= 3.;
occlusion = clamp( occlusion, 0., 1. );
} else {
// dark
occlusion = clamp( occlusion, 0., 1. );
occlusion = 1.-occlusion;
occlusion *= 20.;
occlusion += .25;
}
}`;
export { shader };