-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
136 lines (113 loc) · 3.16 KB
/
index.html
File metadata and controls
136 lines (113 loc) · 3.16 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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>WebGPU</title>
<style>
.debugTab {
position:absolute;
top: -21px;
height: 20px;
left: 0px;
display: flex;
flex-direction: row;
padding-left: 20px;
border: 1px solid white;
}
.debugTab div {
background-color: lightgray;
width:30px;
text-align: center;
margin:1px 1px 1px 0px;
}
</style>
</head>
<body style="background-color:#121c25">
<div>
<canvas width="720" height="480" style="border:1px solid white" id="cmain"></canvas>
</div>
<div id="debugWrapper"></div>
<script src="util/verbose.js"></script>
<script src="util/debugCanv.js"></script>
<script src="util/util.js"></script>
<script src="util/noise.js"></script>
<script src="modules/sky.js"></script>
<script src="passes/atm.js"></script>
<script src="passes/test.js"></script>
<script>
let canvasFormat = null;
let bgs={};
let objs={};
let wgsl={};
let vals={};
function start(callback){
const canvas = document.getElementById("cmain");
if (!navigator.gpu) {
throw new Error("WebGPU not supported on this browser.");
}
navigator.gpu.requestAdapter().then((adapter)=>{
if (!adapter) {
throw new Error("No appropriate GPUAdapter found.");
}
adapter.requestDevice().then((device)=>{
const context = canvas.getContext("webgpu");
canvasFormat = navigator.gpu.getPreferredCanvasFormat();
context.configure({
device: device,
format: canvasFormat,
});
objs.device=device;
callback(device, context, canvas);
});
});
}
function init(device, context, canvas){
const gSky = skyFn(device, true);
const camUnif = device.createBuffer({
label: "Camera Uniform",
size: 16*(4*2+1),
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
});
bgs.cam = c_bg(c_bgl(device, "camera bgl", [{r:"b"}]),
"camera bg", [{buffer:camUnif}]);
const noiseTex = gNoise(device, /*wgsl*/`
vec4f(
remap(grad3tf(c/32,d/32,vec3u(0,0,0),7),-1,1,
1-vorn3tf(c/32,d/32,vec3u(0,0,0)),1),
1-vorn3tf(c/32,d/32,vec3u(0,0,0)),
1-vorn3tf(c/16,d/16,vec3u(0,0,0)),
1-vorn3tf(c/8,d/8,vec3u(0,0,0)),
).xyzw
`, [128,128,128], "rgba8unorm");
//const tPipe = mTestPipe(device, context, canvas, noiseTex);
const mSky = mSkyPipe(device, context, canvas);
let frameInSec = 0;
let oldSec = Date.now();
vals.szen = 0.1;
const frame = ()=>{
frameInSec++;
if(Date.now()-oldSec>1000){
if(frameInSec<25) console.log(frameInSec);
frameInSec = 0;
oldSec = Date.now();
}
c_upd();
device.queue.writeBuffer(camUnif, 0, b_cc(
m4_pers(_cam),
m4_invpersl(_cam),
(Date.now()/10000)%1
));
setSunPos(device, Math.max(10,_cam.loc[1]),vals.szen??Date.now()/5000);
const encoder = device.createCommandEncoder();
gSky(encoder);
mSky(encoder);
device.queue.submit([encoder.finish()]);
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
}
start(init);
</script>
</body>
</html>
<!--Lineees-->