Generating random blob / shape and creating a bitmap from it

Hi, I’m just wondering if there is a way of generating a random blob/shape and then storing it as a bitmap to use later.

Basically I want to be able to generate a random shape similar to this image:

Currently I have loads of these shapes that I have manually created. And my script selects one of them at random and then subtracts it from perlin noise which then results in something similar to an island shape.

I would rather not have a selection of ranom shapes to choose from but have a random shape generated.

The shape would need to have a fade/falloff from black to white around the edges as shown in the image.

Does anyone have any ideas on how I would go about doing this?
I have no idea where I would even start at tackling this.

Many thanks

If your goal is to simply generate islands why not use perlin noise directly with a step function?

Hi, thanks for getting back to me. would ou be able to elaborate on this slightly? I’m not sure what you mean with using perlin noise directly with a step function?

Thanks

Perlin noise looks like this:
8786653--1193539--upload_2023-2-6_21-39-27.png

After applying a step function to it, it looks like this:
8786653--1193545--upload_2023-2-6_21-39-54.png

This is a lot like the very islands you are looking for, no?

You can of course play with the scale of the noise, the threshold of the step function, the perlin noise sample offset etc, to varying results:
8786653--1193548--upload_2023-2-6_21-41-30.png

Just for illustration purposes I m

You can also use smoothstep to get that fuzzy falloff around the edges.

Hi, thanks for providing that detail, it will come in handy for my project for sure. I will need to figure out how to extract a single one of those shapes… another question for another time though after ive experimented…

However I’m not sure it will help for this specific purpose as there a more requirements that need to be met.

For example the shape that needs to be generated would need to be just under 256 X 512 with white around the edges.
Notice in the following images each shape is almost fits the entirety of the 256 x 512 boundry but doesn’t reach the edge of that boundry. All of the black blobs looks like variations of the same thing, they are similar in size, and they almost reach the corners of the boundry but not quite, and they all take up pretty much the same amount of space.
8787619--1193686--Shape_Long_0.png 8787619--1193689--Shape_Long_1.png 8787619--1193692--Shape_Long_2.png 8787619--1193695--Shape_Long_3.png

Is it possible to generate blobs/shapes similar to the above images and store in a bitmap for later use?

Thanks

It’s certainly possible, perhaps not super-easy, and the results perhaps won’t be as good as what you authored by hand above.

One way is to think small, like 10x20 pixels or something…

At the tiny pixel level, one approach is to start full white, pick a random pixel, set it black, then pick all subsequent random pixels to be adjacent to an existing black pixel, iterating until you have enough black vs white and keeping away from the immediate edge.

See this blown-up pixel thing I just ripped out:

8787853--1193746--tiny_2.png
Then just blit it with bilinear filtering on to make it larger:

EDIT: see also my post lower down about the blobozoan

8787853--1193752--bilinear.png
ALTERNATELY, building upon what @PraetorBlue said above, use Perlin noise to make your large island blobby shape by passing it through a simple boxy bounds container like this:

8787853--1193761--box.png

You might try an algorithm like this:

  • generate some perlin noise islands with a step filter
  • pick a random black (or white pixel) in the image
  • using a flood-fill algorithm (DFS or BFS), find all connected pixels of the same color
  • once you have all those pixels, you have now identified one “island”
  • optional: if the island is touching any of the borders of the image, try again until you find one that is not touching a border. (if you find none, start over with a new noise sample entirely). You can also use similar logic to reject other “undesirable” properties of the island such as being too small.
  • Check the bounds of the island and rescale it as necessary to fit into your desired oblong rectangular shape more nicely

I will add here,

you specifically want a bitmap but Unity has beautiful quick method for a png ! My fav.

All you gotta do is grab the first point and then do some adjacency math. X + -1 or 1, Y + -1 or 1 now a blobszoan will form. Once you’re in the for loop or algorithm; that generates points you can do a lot of experimenting for the perfect blob formula.

What an awesome term!! This is exactly the mechanism I have used in my MakeGeo project.

I think I prefer blobozoan… it kinda sounds more like protozoan that way. :slight_smile:

https://github.com/kurtdekker/makegeo/blob/master/makegeo/Assets/ProcGenStuff/MakeCreepingBlocksField/MakeCreepingBlocksField.cs

MakeGeo is presently hosted at these locations:

https://bitbucket.org/kurtdekker/makegeo

i think I typo’d it was meant to be blobazoan ^^

Sounds like a job for an intern :smile:

All of this is very helpfull. Thank you so much. Looks like I have alot of playing about to do.

Ahh I only mentioned bitmap as a generic term for picture. The format isn’t really that important as ill only be using the pixel value which will range from 0 to 1 using .GetPixel(x, y).grayscale
Because I’ll only be using the value of the pixel I can probably eventually do all of this without the need for an image, but while I’m developing it I want to be able to see it.

I’ll post back with any progress I make.

Thanks again.

Procgen of any kind basically means “lots of playing around”… it is one of my most favorite funnest things to do in gamedev… the feeling when you nail the effect and get what you want is pure gold. Stick with it.

And there are other examples in that MakeGeo project I linked above.

MakeGeo is presently hosted at these locations:

https://bitbucket.org/kurtdekker/makegeo

If you do get around to getting rid of the image, and/or using floodfills, adjacencies, etc, you should also have a look at the C# Job System in order to divy up your algorithm into small chunks & work and easily multithreading it across all available cores.
https://docs.unity3d.com/Manual/JobSystem.html
Docs aren’t great, but there’s loads of good tutorials for it.
https://nikolayk.medium.com/getting-started-with-unity-dots-part-2-c-job-system-6f316aa05437
https://www.undefinedgames.org/2019/10/22/unity-c-job-system-and-burst-compiler-dots-introduction/