Hello,
Two GIFs of the problem (second is most pronounced):
https://giphy.com/gifs/5x2iJK0wxEGjWR8RUS
https://giphy.com/gifs/N3aqlCIs1fSrbQowPS
I am pulling my hair out over an issue that I believe is related to single float precision in Unity shader.
I adapted this shadertoy (Shader - Shadertoy BETA) into my unity project (converting glsl to hlsl) and everything worked fine at first. The shader creates a shape, filled with color, defined by a closed loop of bezier curves. I pass the float2 positions of the bezier control points into shader via a buffer. Fine.
However, a problem arises when I move the control points (and thus redefine the shape) at runtime by interpolating between different values for the control point positions. At certain positions, the fill-rule suddenly breaks and I get streaks of pixels across the UV x-axis (which is the direction that the shader sends ‘rays’ in to perform the intersection test to determine if a pixel is inside the shape, for fill color). The shape also becomes oddly pixelated. These streaks occur at the positions of bezier segment start and end points.
The relevant lines in the shadertoy start at line 188 where the “intersection count” function sends out rays from each pixel to see how many times the ray crosses a segment that defines the shape. If it intersects the shape border an even number of times, the pixel is outside the shape, if odd, inside the shape. This even-odd rule is common in SVG program: https://en.wikipedia.org/wiki/Even–odd_rule
Line 203 defines an epsilon, which I believe is to take into account single-float precision issues when comparing float values. THE PROBLEM is that while this epsilon works in shadertoy just fine, it is not sufficient inside my unity project to prevent artifacts. In the shadertoy, change eps to 1e-2 for an example of the problem I am having. There appears to be no value for epsilon small enough to prevent these artifacts in Unity project, however.
Is there ANY possible way I can overcome this precision limitation and prevent these completely unacceptable artifacts? I was thinking about using structured buffers to pass double precision into shader, however this would likely prevent me from using node-based graphs for shader.
Thanks for any guidance!