-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
154 lines (137 loc) · 3.89 KB
/
index.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
<html>
<head>
<title>WGSL sandbox</title>
<!-- until Mar 14, 2023 -->
<meta http-equiv="origin-trial" content="AuAJ9luQMUJskUGQV2N0/f4npVVeYTtnNk9Gq9hbYEr2cB9DYWTUSVK/HDkMaVP+HlXuHrlPFCTNsiKCbJAIFg8AAABTeyJvcmlnaW4iOiJodHRwczovL3Rha2FoaXJveC5naXRodWIuaW86NDQzIiwiZmVhdHVyZSI6IldlYkdQVSIsImV4cGlyeSI6MTY5MTcxMTk5OX0=">
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.63.1/codemirror.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.63.1/codemirror.min.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.63.1/theme/ayu-dark.min.css" />
<style>
body {
position: absolute;
margin: 0;
overflow: hidden;
background: #000;
color: #fff;
}
#info {
opacity: 0.8;
}
.CodeMirror {
position: absolute;
width: 98%;
height: 90vh;
margin: 5% 1% 1% 1%;
}
.CodeMirror-cursor {
border-left: 1px solid #fff !important;
}
.errorMark {
background: #660;
}
#controls {
position: absolute;
margin: 10px 0 0 5px;
width: 90%;
}
#statusSpan {
background: #fff;
padding: 5px;
margin: 5px;
}
#compiledStatus {
color: #0f0;
}
#errorStatus {
color: #f00;
}
#geometrySelect {
margin: 5px;
}
#cameraSelect {
margin: 5px;
}
#sourceLink {
position: absolute;
top: 5px;
right: 10px;
padding: 5px;
background: #000;
color: #fff;
}
</style>
</head>
<body>
<div id="info">
<div id="controls">
<span id="statusSpan">
<span id="compiledStatus" style="display: none;">Compiled</span>
<span id="errorStatus" style="display: none;">Error</span>
</span>
Geometry
<select id="geometrySelect">
<option value="plane" selected>Plane</option>
<option value="box">Box</option>
</select>
Camera
<select id="cameraSelect">
<option value="orthographic" selected>Orthographic</option>
<option value="perspective">Perspective</option>
</select>
Rotation
<input id="rotationCheckbox" type="checkbox">
</div>
<a id="sourceLink" href="https://github.com/takahirox/online-wgsl-editor" target="_blank">GitHub</a>
<textarea id="shaderTextarea" spellcheck="false"></textarea>
</div>
<script id="defaultShader" type="wgsl">
struct VertexOutput {
@builtin(position) position: vec4<f32>,
@location(1) normal: vec3<f32>,
@location(2) uv: vec2<f32>,
};
struct Uniform {
model_matrix: mat4x4<f32>,
view_matrix: mat4x4<f32>,
projection_matrix: mat4x4<f32>,
normal_matrix: mat3x3<f32>,
resolution: vec2<f32>,
elapsedTime: f32, // in seconds
};
@group(0) @binding(0)
var<uniform> unif: Uniform;
@vertex
fn vs_main(
@location(0) position: vec3<f32>,
@location(1) normal: vec3<f32>,
@location(2) uv: vec2<f32>,
) -> VertexOutput {
var out: VertexOutput;
out.position = unif.projection_matrix * unif.view_matrix * unif.model_matrix * vec4<f32>(position, 1.0);
out.normal = normalize(unif.normal_matrix * normal);
out.uv = uv;
return out;
}
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
return vec4<f32>(in.uv, pow(cos(unif.elapsedTime), 2.0), 1.0);
}
</script>
<script type="module">
import App, {UnsupportedWebGPUError} from './src/index.js';
const run = async () => {
let app;
try {
app = await App.create();
} catch (error) {
if (error instanceof UnsupportedWebGPUError) {
window.alert(error);
}
throw error;
}
app.start();
};
run();
</script>
</body>
</html>