-
Notifications
You must be signed in to change notification settings - Fork 36
/
webgl2_buffergeometry_attributes_none.html
172 lines (119 loc) · 4.4 KB
/
webgl2_buffergeometry_attributes_none.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Verge3D WebGL 2 - buffergeometry - attributes - none</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="main.css">
</head>
<body>
<div id="info"><a href="https://www.soft8soft.com/verge3d" target="_blank" rel="noopener">Verge3D</a> WebGL 2 - buffergeometry - attributes - none</div>
<script id="vertexShader" type="x-shader/x-vertex">
uniform mat4 modelViewMatrix;
uniform mat4 projectionMatrix;
uniform float seed;
const uint ieeeMantissa = 0x007FFFFFu;
const uint ieeeOne = 0x3F800000u;
uint hash(uint x) {
x += (x << 10u);
x ^= (x >> 6u);
x += (x << 3u);
x ^= (x >> 11u);
x += (x << 15u);
return x;
}
uint hash(uvec2 v) { return hash(v.x ^ hash(v.y)); }
float hashNoise(vec2 xy) {
uint m = hash(floatBitsToUint(xy));
m &= ieeeMantissa;
m |= ieeeOne;
return uintBitsToFloat(m) -1.0;
}
float pseudoRandom(float lower, float delta, in vec2 xy) {
return lower + delta*hashNoise(xy);
}
vec3 pseudoRandomVec3(float lower, float upper, int index) {
float delta = upper - lower;
float x = pseudoRandom(lower, delta, vec2(index, 0));
float y = pseudoRandom(lower, delta, vec2(index, 1));
float z = pseudoRandom(lower, delta, vec2(index, 2));
return vec3(x, y, z);
}
out vec3 vColor;
void main() {
const float scale = 1.0/64.0;
vec3 position = pseudoRandomVec3(-1.0, +1.0, gl_VertexID/3) + scale * pseudoRandomVec3(-1.0, +1.0, gl_VertexID);
vec3 color = pseudoRandomVec3(0.25, 1.0, gl_VertexID/3);
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
vColor = color;
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
precision mediump float;
in vec3 vColor;
out vec4 fColor;
void main() {
fColor = vec4(vColor, 1);
}
</script>
<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/[email protected]/dist/es-module-shims.js"></script>
<script type="importmap">
{
"imports": {
"v3d": "../build/v3d.module.js",
"v3d/addons/": "./jsm/"
}
}
</script>
<script type="module">
import * as v3d from 'v3d';
import WebGL from 'v3d/addons/capabilities/WebGL.js';
if (WebGL.isWebGL2Available() === false) {
document.body.appendChild(WebGL.getWebGL2ErrorMessage());
}
let camera, scene, renderer, mesh;
init();
animate();
function init() {
camera = new v3d.PerspectiveCamera(27, window.innerWidth / window.innerHeight, 1, 3500);
camera.position.z = 4;
scene = new v3d.Scene();
scene.background = new v3d.Color(0x050505);
scene.fog = new v3d.Fog(0x050505, 2000, 3500);
// geometry
const triangleCount = 10000;
const vertexCountPerTriangle = 3;
const vertexCount = triangleCount * vertexCountPerTriangle;
const geometry = new v3d.BufferGeometry();
geometry.setDrawRange(0, vertexCount);
// material
const material = new v3d.RawShaderMaterial({
uniforms: {
seed: { value: 42 },
},
vertexShader: document.getElementById('vertexShader').textContent,
fragmentShader: document.getElementById('fragmentShader').textContent,
side: v3d.DoubleSide,
glslVersion: v3d.GLSL3
});
// mesh
mesh = new v3d.Mesh(geometry, material);
mesh.frustumCulled = false;
scene.add(mesh);
// renderer
renderer = new v3d.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
}
function animate(time) {
requestAnimationFrame(animate);
mesh.rotation.x = time / 1000.0 * 0.25;
mesh.rotation.y = time / 1000.0 * 0.50;
renderer.render(scene, camera);
}
</script>
</body>
</html>