Author Topic: Flood Fill to also fill up non-closed spaces  (Read 4442 times)

How are you doing the gradients?
I'm not sure if this is any help, but my first thought is to mask islands touching the edges of the image by using your random mask, but with different values based on which edge is touched.

Than just first apply the gradients to the central cells. Offset the image horizontally, apply gradient to the value that's now in the center, and do this 2 more times for the top and the corners.
I can see this being an issue for very large cells though.

Another note: If you can just get 2 maps, one with horizontal, and the other with vertical gradients, you've got yourself some uv coordinates, which can be used to rotate gradients at any angle afterwards (Though perhaps not at different angles)

That was a great idea! Seems like it will support tiling, after all :)

Gradients are generated from pixel position in a map (UV coordinates), while random luminance mask controls gradient rotation matrix. Because of random luminance mask, the actual value that rotates the gradient is kept the same for each individual island in a mask — it's a corner stone in this implementation. So, as pixel position changes, so does the gradient value, but overall direction for a given island is preserved.

At first, I've tried to use Transform node to downscale the map, so islands located at the edges would move inside the map and gradient will be applied to them without wrapping around. Transform node scaled down at 50% and set as "Input +1" for resolution would allow to do this without resampling pixels, so no information will be lost. Then apply the gradient and use Transform node again with 200% scaling and Input -1 resolution to get back to original resolution. Unfortunately, this would limit the node tiling to 4k resolution, as you can't get over 8k in SD yet.

Then I've realized that indeed, with very long islands in the map, scaling down at 50% won't be enough. To make tiling work it should be scaled one more time, to 25%, and then vice versa. That would effectively limit the node to 2k resolution only, which is unacceptable.

I've decided to follow your great idea and leveraged Randomize Mask node to mark islands that are located at the edges of the map and in the corner, then flood fill those islands to make a map for them. Then I've figured that I can modify gradient function to warp around marked islands as necessary, so no actual map offset would be necessary (instead the gradient will offset). Also it became apparent that I don't need to mask islands that are located on both sides of the mask — just pick one side and make sure the gradient wraps correctly to the other side.

So, with wrapping islands masked, I've used them to put some additional parameters in gradient function. Islands marked as located at the left border of the map will get horizontal U offset of 1 unit, so the gradient would warp there exactly by one texture tile. Same for islands located at the top - mask them and offset gradient vertically on V by 1 unit. For corner island that touches both left and top borders of the map, offset both U and V by 1. Voila! — seamless gradient.

Now I have something like this almost ready (first image below): node that allows to apply random and variable direction gradient to individual islands in a mask, with support for donut-like shapes, adjustable and variable range for gradient, global gradient angle control and a pretty invert (!) button. :P

I wonder if there any use for an additional node that will mark islands that will wrap when the map will tile (second image below)? I have a feeling that it may come useful, but can't right away tell in which way. The map can be neatly packed in a RGBA with horizontally wrapping islands in R, vertically - in G, corner islands in B and general mask for all of them in A.
Last Edit: March 15, 2018, 12:42:04 pm

That's looking great!
Smart move, doing the offset inside the pixel processor!
And thanks for explaining how you did it, this really clears up some core concepts of image wrapping for me, as simple as it may have turned out to be (adding 1 to your u and v values for parts you want to wrap around :p)

I'm not sure if a lot of people would find a need for the edge-island mask, but I can see it be the sort of thing where you'd be very happy it exists in that oddball situation where you require it. So, worth the release, but maybe not worth flashing out much.