renancaraujo / omesh

O'Mesh is a fast and highly customizable vector animated Mesh Gradients implementation.
https://omesh-flutter.renan.gg
Mozilla Public License 2.0
86 stars 4 forks source link

Impeller renderer hairlines are caused by math error maybe (off by one? floating point precision?). #19

Closed jonahwilliams closed 2 days ago

jonahwilliams commented 2 months ago

Bug Description

Part of the mesh gradient shader appears to have some sort of either floating point or off by one error that occurs if the gradient is not perfectly aligned with physical pixel coordinates. Specifically this line that applies a color clamp:

  vec2 uvInSquare = (uv - uv00) / (uv11 - uv00);

  if (uvInSquare.x < 0.0 || uvInSquare.x > 1.0 || uvInSquare.y < 0.0 ||
      uvInSquare.y > 1.0) {
    color = vec4(0.0);
    return;
  }

Will fire for all of the edge pixels of an anti-aliased shape. I don't think its a floating point precision error, a much more likely explaination is that the bounds computed is slightly off. In fact, to misfire for a single pixel it really only needs to be ever so slightly off.

I'm not sure what this line is intended to do. It looks like the position of the mesh gradient, as determined by the vertex positions, is already correctly computed. But there may be other examples besides the repo ones where this becomes imporant?

I've found that if I just remove this line from the shader, everything with impeller renders fine without the workaround.

image

Reproduction Steps

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected Behavior

No response

Screenshots

No response

Additional context

No response

renancaraujo commented 1 week ago

I added the compat mode because of https://github.com/flutter/flutter/issues/153964, now it seems to be all fine. Removing all of the compat mode.

renancaraujo commented 2 days ago

The bug should not happen on. v0.4.2 since all of. that "compatibility mode" code was removed