-
After read lessons/webgpu-multiple-canvases and lessons/webgpu-multisampling I encountered some confusion while using MRT and MSAA. When a triangle rotates, aliasing occurs, and I began to try using MSAA for anti-aliasing. (In my case, I used MRT to implement the object selection feature, which determines whether an object is selected by reading the pixel color.) I found that when a pipeline sets the multisample.count to 4, all textures must have a sampleCount of 4. Therefore, I now have to set the pickingObjectTexture to 4 as well. I have the following questions:
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
You can use
I honestly don't know what state of the art is. There's a ton of techniques. They each have strengths and weaknesses. Sorry I don't have an answer. see https://www.google.com/search?q=gpu+antialiasing+methods btw: there's a picking example here. It is not anti-aliased though, nor is it using MRT. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
well, there's the smoothstep circle @fragment fn fs(vin: VSOut) -> @location(0) vec4f {
//
// inner outer border fade
// center radius radius radius radius
// V V V V V
// | <--- circle ---> | <- blend -> | <- border -> | <- anti-alias -> |
// | color | to border | color | blend to 0 |
const innerRadius = 0.2;
const outerRadius = 0.3;
const borderRadius = 0.4;
const fadeRadius = 0.5;
let distance = length(vin.uv - 0.5);
let innerMix = smoothstep(innerRadius, outerRadius, distance);
let outerMix = smoothstep(borderRadius, fadeRadius, distance);
let circleColor = vec4f(1, 0, 0, 1);
let borderColor = vec4f(1, 1, 0, 1);
let edgeColor = vec4f(0, 0, 0, 0);
let color = mix(
mix(circleColor, borderColor, innerMix),
edgeColor,
outerMix);
// premultiply
return vec4f(color.rgb * color.a, color.a);
} you'll need to choose radii that fit the current resolution the quad is being rendered, or use I think this works.
|
Beta Was this translation helpful? Give feedback.
-
It has an effect, but it only improved a little bit. const transparentColor = vec4f(0.0, 0.0, 0.0, 0.0);
const center = vec2f(0.0, 0.0);
const feather = 0.01;
// quad_position.xy range is (-1,1)
@fragment
fn fragmentShader(input: VertexOutput) -> FragmentOutput {
var uv = vec2((input.quad_position.x + 1 ) / 2, 1 - (input.quad_position.y + 1 ) / 2); // (-1,1) to (0,1)
var color = transparentColor;
let fw = fwidth(uv);
let dist = distance(input.quad_position, center);
let alpha = smoothstep(circleRange - (fw.x + feather), circleRange + (fw.x + feather), dist);
color = mix(input.color, transparentColor, alpha);
color = vec4f(color.rgb * color.a, color.a);
return FragmentOutput(color, input.idColor);
} |
Beta Was this translation helpful? Give feedback.
-
Yes, you are absolutely right. This indeed fixes the gray edges issue. However, my concern is that it still looks somewhat blurry. Compared to the following case, I am trying to upscale the canvas by 2x and then scale it back down to 1x using CSS to resolve the blurriness. Is this the correct approach? |
Beta Was this translation helpful? Give feedback.
seems to work.