Skip to content

Commit

Permalink
improve description
Browse files Browse the repository at this point in the history
  • Loading branch information
kainino0x committed Sep 21, 2024
1 parent ef1efc7 commit 90236b8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
27 changes: 12 additions & 15 deletions sample/alphaToCoverage/meta.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
export default {
name: 'Alpha-to-Coverage',
description: `
Visualizes how alpha-to-coverage translates alpha values into sample
coverage on your device. It draws two full-screen quads into a 4-sample
texture, with the configured color and alpha values. Then, it visualizes the
contents of that 4-sample texture: the circles show the 4 samples of each
pixel; the background checkerboard shows where the pixels are.
The algorithm that converts alpha to a coverage sample mask varies per
device. This results in different proportions between the black background,
the first draw, and the second draw.
Alpha-to-coverage is an alternative to alpha testing and alpha blending. See:
<https://bgolus.medium.com/anti-aliased-alpha-test-the-esoteric-alpha-to-coverage-8b177335ae4f>
Examples: Some devices use 1x1 patterns, others 2x2, others 4x4. Not all devices
guarantee that once a sample "pops in", it will stay there at higher alpha
values. Some devices "move" samples around at certain alpha thresholds even
without increasing the total sample count.
This sample visualizes how alpha-to-coverage translates alpha values into sample
coverage on your device. It draws two full-screen quads into a 4-sample
texture, each with the configured color and alpha value. Then, it visualizes the
contents of the resulting 4-sample texture: the circles show the 4 samples of
each texel; the background shows the "resolved" results (average of 4 samples).
More info on alpha-to-coverage:
<https://bgolus.medium.com/anti-aliased-alpha-test-the-esoteric-alpha-to-coverage-8b177335ae4f>
The algorithm that converts alpha to a coverage sample mask varies per device.
This results in different average "blending" proportions between the black
background, the first draw, and the second draw.
Device differences include different tile sizes (e.g. 1x1, 2x2, or 4x4),
"moving" samples (or not) around with in the tile as alpha increases, etc.
`,
filename: __DIRNAME__,
sources: [
Expand Down
2 changes: 1 addition & 1 deletion sample/alphaToCoverage/showMultisampleTexture.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn fmain(vary: Varying) -> @location(0) vec4f {
let xyFrac = xy % vec2f(1, 1);

// Show the visualization only if the resolution is large enough to see it
if (dpdx(xy.x) < kGridEdgeHalfWidth) & (dpdy(xy.y) < kGridEdgeHalfWidth) {
if (dpdx(xy.x) < kGridEdgeHalfWidth * 2) & (dpdy(xy.y) < kGridEdgeHalfWidth * 2) {
// Check if we're close to a sample; if so, visualize the sample value
for (var sampleIndex = 0; sampleIndex < kSampleCount; sampleIndex += 1) {
let distanceFromSample = distance(xyFrac, kSamplePositions[sampleIndex]);
Expand Down

0 comments on commit 90236b8

Please sign in to comment.