-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcanvas.html
49 lines (45 loc) · 1.43 KB
/
canvas.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGPU Example</title>
<script src="canvas.js"></script>
</head>
<body>
<h1>WebGPU Example</h1>
<div>
If your browser supports <a href="https://webkit.org/blog/7380/next-generation-3d-graphics-on-the-web/">WebGPU</a>, a triangle should be rendered below.
</div>
<canvas id="mycanvas" width="320" height="240" style="border: solid 3px #000;"></canvas>
<script id="library" type="x-shader/x-metal">
using namespace metal;
// Rec 709 LUMA values for grayscale image conversion
constant float3 kRec709Luma = float3(0.2126, 0.7152, 0.0722);
struct Vertex {
float4 position [[position]];
float4 color;
};
vertex Vertex vertex_main(constant Vertex *vertices [[buffer(0)]],
uint vid [[vertex_id]]) {
return vertices[vid];
}
fragment float4 fragment_main(Vertex vert [[stage_in]]) {
float3 inColor = float3(vert.color.x, vert.color.y, vert.color.z);
half gray = dot(kRec709Luma, inColor);
float4 outColor = float4(gray, gray, gray, 1);
return outColor;
}
</script>
<div>
based on
<ul>
<li>https://webkit.org/blog/7380/next-generation-3d-graphics-on-the-web/</li>
<li>https://www.gaprot.jp/pickup/tips/metalkit</li>
</ul>
</div>
<hr>
<div>
<a href="https://github.com/milhidaka/webgpu-example">https://github.com/milhidaka/webgpu-example</a>
</div>
</body>
</html>