The Unreasonable Power of Wiggling Just a Little

john's Avatar

john

19 Jan, 2025 10:52 PM

Nodebox is a pure vector program. But, sooner or later, in order to be visible on a computer screen, those vectors will be rendered into pixels. And sometimes, for certain rare and perverse curves, strange things can happen.

I already have a node, clean, in my Cartan Node Library, that eliminates spikes that sometimes appear when paths contain duplicate points. But recently I came across a more subtle problem that clean couldn't fix.

I was trying to make an animation which involved meta-branching: using my new branches node to place branched regions inside larger branched regions. Some of those parent regions were weirdly shaped, not at all the clean, convex shapes branches is designed to work with.

And sometimes, just sometimes, hairlines would jump out from the corners of some of the subregions. This would happen, seemingly at random, every now and then, and only for a single frame of the movie. But they were visible and, because they appeared and disappeared so quickly, caused a flashing effect that was distracting.

And they were hard to find because, as I said, there was nothing wrong with the vectors. This was a post-Nodebox issue. They were hard to even reproduce within Nodebox. But you could sometimes see them at certain magnifications. I don't mean scaling with the scale node. I mean manually zooming in and out in the render pane. These sudden hairlines would appear only when I zoomed in on a particular area in a specific frame just the right amount.

Maddening!

I was finally able to isolate a particular Bézier curve segment within a certain path on a certain frame of the animation that was producing this effect. And once again, it involved duplicate pixels: two adjoining pixels with exactly the same x and y values. The reason clean couldn't catch them is that the first was the starting point of the curve and the second was a bezier control point. Removing either one would cause the curve to collapse.

What to do? I considered adding a bunch of code to disassemble every segment of every curve on every path to look for this rare occurrence and scoot the control point just a bit. I used my very cool adjust_point node to verify this would work. But what a pain! And it would slow my rendering. Surely there must be an easier way.

That's when I tried wiggling it.

I added a standard Nodebox wiggle node after every region path produced by my branches node. But just a little. Only one one-hundredth of one pixel in both the x and y directions, at random. Not enough to cause any visible difference.

It worked! All the little momentarily flashing hairlines disappeared. All done with a single node that caused no noticeable increase in render time.

I need to test this some more to make sure it has no ill effects on normal branching regions. If so, I will probably add it in to the branches node so that no one else ever has to see these annoying little defects.

But it makes me uneasy. It's a bit of a kludge. And, because it is random, it is not guaranteed to work every time. It is wildly unlikely, but still possible, that with whatever random seed I use in the wiggle node, the already rare occurrence of two consecutive points in a perverse curve segment could both wiggle in exactly the same way.

Still, it may be a reasonable compromise. When you get to the very edges of computation these things happen. And if you have to choose between a perfect solution that would require a hairball of added complexity, which slows everything down and which itself increases the risk of triggering some other unrelated issue, and an extremely fast and simple solution that works 99.999999% of the time, embracing the kludge might be the sensible choice.

  1. Support Staff 1 Posted by john on 22 Jan, 2025 11:42 PM

    john's Avatar

    UPDATE

    I did some careful testing with a modified version of the branches node that included micro-wiggling built in. I verified that it corrected the rendering issue in some situations, but caused new problems in others.

    My conclusion is to leave the branches node as it is. But if this issue recurs in a future project, I will try adding a wiggle node on a case by case basis. Another tool in the toolbox.

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

06 Feb, 2025 01:37 AM
04 Feb, 2025 06:32 AM
04 Feb, 2025 05:04 AM
30 Jan, 2025 09:31 AM
30 Jan, 2025 09:08 AM

 

30 Jan, 2025 08:40 AM
24 Jan, 2025 07:50 AM
22 Jan, 2025 11:42 PM
21 Jan, 2025 09:43 AM
21 Jan, 2025 09:41 AM
21 Jan, 2025 09:36 AM