Getting ready for some of that "bad apple" action.

#niri #wayland

If anybody has any insight about the state of the art for managing properly smooth vector fields towards the interior of a shape without having any ridges (while still being efficient for a GPU) like we can see on the square here, I'm all ears.
@calops sounds like a math problem @nea89 would be delighted to think about
@zimward @calops @nea89 and me (it has GPUs and math!)
Include me in the thread too :3

@tranquillity @zimward @nea89

Very well, have at it. Let me illustrate.

On the left is a "perfect" vector field in a square, generated analytically. All vectors point directly towards the center of the square (or rather, the intersection of the closest Voronoi boundaries).

On the right is my own heuristic attempting to produce a similar vector field on an arbitrarily shaped region, from a pixel mask input. As you can see, the Voronoi boundaries are still visible despite my best attempts.

@calops @zimward @nea89 what's expensive about a fragment shader that generates vectors pointing towards a point? That's one instruction and branchless
Are you computing a vector field from random points (aka voronoi) and thus have to compute the distance to several points and find the min?
I'm having trouble what you're optimizing here for

@tranquillity @zimward @nea89

Ah but that's the thing, I don't have that point. All I have is a matrix of 1s and 0s defining "regions". The square here is a special case that I'm trying to have render properly, but the goal is to support any arbitrary shape (as shown in the video above).

The spec for the vector field is just "point towards the interior", with a loose definition of "interior". The left square does what you suggest: a very cheap "point towards that point" vector generation.

@tranquillity @zimward @nea89

I guess an interesting approach would be to find a strategy to define some kind of centroids towards which vectors should point. If we can do that, we can generate the vector field with the easy and cheap analytical version once again.

No idea if that's a good direction to explore.

@calops @tranquillity @zimward unsure if this has been proposed somewhere else in this thread (currently on the train), but this feels like something that could be done by instead calculating an SDF and then using that as a reference instead of a gradient field. an SDF can also be calculated quicker than a gradient field directly since it can be done in two steps (first columns, then rows). (excuse my uneducated ramblings, ill look at it in a bit)

@nea89 @zimward @tranquillity

SDF is pretty much what I'm doing in the left square already. But it' requires analytical knowledge of the boundaries of your region. Here we don't even have the concept of a region, just a plain binary mask.

@calops @zimward @tranquillity you can calculate a SDF from a binary mask either in one frame by first running gpu threads for each row, then gpu threads for each column, or by using an algorithm across frames (which might actually look fine as a bit of an animation) something like the jump flooding algorithm where you have a fixed workload per pixel per frame (god damn you firefox for making my right click not work)

@nea89 @zimward @tranquillity

JFA is already what I use as the first step of my heuristic. It produces a smooth distance field, but that's just distances. To derive the vectors from that I need to follow the gradient of that field and that's how you get these Voronoi artifacts in the first place. Even after a bunch of blur passes, it's not smooth enough.

@calops @nea89 @tranquillity what if you add some random noise to it to make it less apparent? (no idea if that would look better)

@zimward @nea89 @tranquillity

It would give some kind of texture to the glass but the overall shape of the effect wouldn't change. It's exacerbated by the fact that there's a dynamic light source casting highlights and shadows in there (yes I know).