Circle Packing - OSL shader

Anybody reading my other threads lately know that I have been researching a way to pack circles as dense as possible to achieve a procedural texture node able to make random patterns with images.

My initial goal was to make a procedural texture like this:


Background:
The above picture is harder to create than I initially thought. The best way to do it I have found out is to randomise spheres on a plane, starting large, and sequentially randomise smaller and smaller circles. Whenever a circle overlaps another, skip it. However, this method does not work with a OSL shader, since the shader needs to be calculated for every pixel over a surface. Also this method required collision detection on all circles whenever a new one is sampled.
An optimal outcome would be something like this:



(Handmade “random” circles made by artist Yayoi Kusama)

Instead I have experimentet with voronoi-distributions, where you only have to “re-create” a part of the texture close to the point you are sampling. So for example If the point you are sampling is close to the top left border, you only have to create the circles covering that area, and so on. This becomes a problem though, because all circles should touch, a random sized circle in the bottom left corner could potentially alter a position of a circle in the top right corner (!).

Also, im not rendering textures, but rather vectors as colors. This enables me to use any texture for a circle or as in my sample a 10x10 texture sample, that will use each square for a unique circle.

I will keep this thread as to present my results.
So far this is what I got


(after two weeks of research, this is a voronoi distribution, where any overlapping is adjusted by shrinking the circle)

As one can see this is not as dense as Kusama’s circles. Lots of gaps. I will post my findings here. Any suggestions (except “stop trying” or do it outside the OSL-shader) is welcome.

Ok, made some progress by using a appollonian math to calculate circle tangents. So far:



Still have a few overlappings due to special cases where more than 5 circles overlap. …


So still quite far from the original.

Looks great! Is it game engine related?
I think you posted in the wrong forum thread…

If I wanted to create an effect like this in the game engine I’d put all the circles in the middle and then use a collision detection algorithm to move them apart until they are no longer touching. But I don’t know how you’d do it as a shader.

This is posted on the wrong thread, sorry to mention. (these are for games only even if it’s game engine related, this thread is for games.)
Good job on this, though. Glad to see you made progress.

  • Sorry all.
    Wrong thread. Ill kill it and just open it somewhere else, or can a mod move it?

I wonder how many on this forum are color blind and can’t see the number. :slight_smile:

what number?

I’m not sure if you’re serious or just joking.

I think Moderators can move it, though, I am not sure where to find them. I am sure one will come to you and move it.

Thought it was funnier without a smilie :slight_smile:

Did you ever get this working? I’ve been trying to accomplish the same thing and keep hitting walls. Would you be willing to share your nodes?

@StephenNewport
This is an OSL shader, it isn’t node based (it’s C++/GL code)
Also, the best approach to circle packing is to use hexagons.

Ahh, thanks for the reply. Guess I’m too much of an amateur to know what that is. If you had any leads/links on how to accomplish with nodes I’d appreciate it