Skip to content

Commit bc5a05e

Browse files
committed
chore: add a test for premultiplied alpha
1 parent b1c6b77 commit bc5a05e

File tree

7 files changed

+60
-0
lines changed

7 files changed

+60
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
import Layout from "../../layouts/Layout.astro";
3+
---
4+
5+
<script>
6+
import { useWebGLCanvas } from "usegl";
7+
import { incrementRenderCount } from "../../components/renderCount";
8+
9+
const glCanvas = useWebGLCanvas({
10+
canvas: "#glCanvas",
11+
fragment: /* glsl */ `
12+
varying vec2 uv;
13+
void main() {
14+
float circle = 1. - smoothstep(.2, .4, length(uv - vec2(0.5)));
15+
gl_FragColor = vec4(vec3(0,0,1), circle);
16+
}
17+
`,
18+
webglOptions: { premultipliedAlpha: false },
19+
});
20+
glCanvas.onAfterRender(incrementRenderCount);
21+
22+
const glCanvas2 = useWebGLCanvas({
23+
canvas: "#glCanvas2",
24+
fragment: /* glsl */ `
25+
varying vec2 uv;
26+
void main() {
27+
float circle = 1. - smoothstep(.2, .4, length(uv - vec2(0.5)));
28+
gl_FragColor = vec4(circle * vec3(0,0,1), circle);
29+
}
30+
`,
31+
// webglOptions: { premultipliedAlpha: true }, // default
32+
});
33+
glCanvas2.onAfterRender(incrementRenderCount);
34+
</script>
35+
36+
<Layout title="Alpha">
37+
<div class="container">
38+
<canvas width="15" height="15" id="glCanvas"></canvas>
39+
<canvas width="15" height="15" id="glCanvas2"></canvas>
40+
</div>
41+
</Layout>
42+
43+
<style>
44+
.container {
45+
display: flex;
46+
justify-content: center;
47+
width: min(80%, 700px);
48+
background: yellow;
49+
}
50+
51+
canvas {
52+
aspect-ratio: 1;
53+
border-radius: 0;
54+
width: min(50%, 350px);
55+
aspect-ratio: 1;
56+
border: 0;
57+
image-rendering: pixelated;
58+
}
59+
</style>
3.27 KB
Loading
3.52 KB
Loading
12.6 KB
Loading
4.7 KB
Loading
4.53 KB
Loading

lib/tests/screenshots.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const expectedRendersByDemo = {
1414
mipmap: /[1-3]/,
1515
texture: /1|2/,
1616
sepia: /1|2/,
17+
alpha: "2",
1718
};
1819

1920
for (const { section, route } of routesToTest) {

0 commit comments

Comments
 (0)