28
$\begingroup$

Is it possible to define a true mathematical fractal in Blender?

For example, would it be possible to use a script or a Blender addon to procedurally generate 3D fractal objects. This could be immensely useful for a number of natural objects that happen to be fractal in nature, such as snowflakes, broccoli, tree branches, ferns, coastlines, mountains, etc?

Fractal snowflake:

enter image description here

Fractal Romanesco broccoli:

enter image description here

My first thought was to use the Add 3D Function Surface addon, but that doesn't currently allow for recursive definitions. Using textures, combined with images of fractals could help with 2D objects (such as the snowflake), but this solution doesn't really allow for the generation of these fractals. So my question is, is it possible currently to recursively generate fractals in Blender, either with built in functionality or with an addon? If this functionality isn't yet available, would it be possible to write a script to do this?

$\endgroup$
4
  • $\begingroup$ Blender can edit images, so theres nothing stopping your from making a mandelbrot image and using as a texture -- even to update each frame is possible using a frame_change_post handler. But I suspect this isnt the answer your are looking for, so please write some more details in your question about how you intend to use this. $\endgroup$
    – ideasman42
    Jun 30, 2013 at 20:08
  • $\begingroup$ For broccoli see the golden spiral question. The snowflake could be done using the mirror modifier. $\endgroup$
    – Aldrik
    Jun 30, 2013 at 21:17
  • $\begingroup$ There is an addon to generate fractals here: github.com/NMEMine/BlenderFractals $\endgroup$
    – user1853
    Feb 22, 2016 at 15:47
  • $\begingroup$ Have look at incendia, which can export its results as 3D-objects. But be careful, these end up with millions of vertices. $\endgroup$
    – user31669
    Oct 19, 2016 at 6:27

8 Answers 8

11
$\begingroup$

This script will generate a 2D Mandelbrot set in Blender using OSL.

#include <stdosl.h>

shader node_fractal(
        float CenterX = 0.0,
        float CenterY = 0.0,
        point Vector = P,
        float Zoom = 1.0,
        int MaxIterations = 50,
        color Foreground = color(1.0),
        color Background = color(0.0),
        output float Fac = 0.0,
        output color Color = 0.0)
{
    point p = Vector / (2* Zoom);
    float auxiliar = 0.0;

    p[0] += CenterX;
    p[1] += CenterY;

    point pa = p;
    point pb = point(0.0);
    int i = 0;
    for(i=1; i<MaxIterations; i++)
    {
        pb[0] = pa[0]*pa[0] - pa[1]*pa[1];
        pb[1] = pa[0]*pa[1] + pa[1]*pa[0];
        pa = pb + p;
    }

    auxiliar = sqrt((pa[0]*pa[0]) + (pa[1]*pa[1]));

    Fac = clamp(auxiliar,0.0,1.0);

    if (Fac == 0.0)
        Color = Background;
    else
        Color = mix(Foreground, Background, Fac);
}

Result:

enter image description here

Source: http://elbrujodelatribu.blogspot.fr/2013/04/blender-cycles-osl-mandelbrot-fractal.html

$\endgroup$
5
  • $\begingroup$ This is a good read too.. Fun with instancing in Cycles $\endgroup$
    – iKlsR
    Jun 30, 2013 at 20:57
  • 1
    $\begingroup$ @Gwenn of course by right before, you mean nine minutes after. ;) $\endgroup$
    – Aldrik
    Jun 30, 2013 at 21:11
  • $\begingroup$ While this is a neat answer, the question is about modeling. $\endgroup$
    – ideasman42
    Jul 1, 2013 at 1:42
  • 1
    $\begingroup$ @ideasman42, see above comments, "rendering trick" was acceptable at the time of posting. $\endgroup$
    – Aldrik
    Jul 1, 2013 at 2:11
  • $\begingroup$ i put this code into the python console, but it just popped up with a bunch of "IndentationError: unexpected indent" errors on like every line. $\endgroup$ Apr 27 at 23:42
9
$\begingroup$

You can implement specific fractal equations and algorithms to generate objects. I did this once for Koch snowflake shapes, if you want to start somewhere.

You can get the script's code here.

Koch Snowflakes

As a basis for golden ratio based objects, you can use this other script that generates Fibonacci spirals.

Fib

$\endgroup$
1
  • $\begingroup$ for some reason when i pasted this script into the text editor, and ran it, it did absolutely nothing. could you have a reason why this happened? $\endgroup$ Apr 28 at 0:24
5
$\begingroup$

L-systems for Blender

When discussing 3d and fractals you might want to investigate L-systems (wikipedia link).

This video shows Romain Lopez using his implementation of L-systems with blender and python, unfortunately no links to code are provided. But L-systems are really cool and can make brain-bending complexity with minimal input.

Michael Anders has a tutorial for an L-system addon, which was posted on BlenderNation not so long ago.

$\endgroup$
1
  • $\begingroup$ Animation nodes has L-Systems too ;) $\endgroup$
    – Chris
    Apr 12, 2021 at 23:39
2
$\begingroup$

I'm also very interested in this. I found a video on Youtube where someone made a shader to render julia fractals as volumetrics. I then searched for julia mandelbulb and especialy mandelbox formulas and infos about distance estimation and raymarching but I couldn't understand it really. But I tried to put everything together and somehow it worked. The result is not a real mandelbox but I think never the less some interesting shapes came out of it. I then found also that it's possible to use the vertex displacment node with it but it's not working exactly as I would like. But It does something. Here are my results:

Just different sized Cubes with adaptive subdivision: Just different sized Cubes with adaptive subdivision Use of the Distance Value with a Color Ramp to mix Glas and Metalshaders: Use of the Distance Value with a Color Ramp to mix Glas and Metalshaders Cube with subdivision and edgesplit modifier applied then scaled the faces by 0.5: Cube with subdivision and edgesplit modifier applied then scaled the faces by 0.5 The Distance Value can also used to define density of volumetric scattering and absorption with a colorramp: The Distance Value can also used to define density of volumetric scattering and absorption with a colorramp I hope I'll find a way to improve the vertexdisplacment thing. There is a demo where one made something like this in unity engine but very improved and also realtime.

Here is a link to the blend-file on googledrive: https://drive.google.com/open?id=1OHEbTSi0fQuVkUER5bKxa2Jf-FRq8fzS

Some more links:

Mandelbox Volumetric Shader OSL Script

A Realtime Fractal in Unity Engine by Okan Koese

Julia Fractal Shader for Blender Youtube Tutorial

$\endgroup$
1
  • $\begingroup$ Added the link. $\endgroup$
    – Bluebone
    Jul 10, 2018 at 17:26
1
$\begingroup$

I think the answer to your question would be No, but you can get useful results by generating triangles based on a mathematically defined surface.

This is a very open ended question, even though you ask about fractals, the question applies to any mathematically generated shapes.

The bottom line is that Blender only supports polygonal geometry (so no mathematically defined surfaces, nurbs, metaballs etc) - It all gets converted into triangles before displaying in the view-port or rendering.

Contrast this to Povray which can render math based surfaces. *

So you can write some script to generate geometry, but its limited in that the output must be polygonal geometry.

I have seen an example where a developer was able to automatically adjust the detail to match the camera - this way you can fake having infinite detail, so perhaps this can be a solution for you.

This can work simply by using a Python script which regenerates a mesh on a frame-change handler, taking the Camera's view-point (and any other changing parameters) into account.

However the question is so general that its not clear what your intention is exactly once you have some generated geometry rendering.


*Note, that Blender has povray integration which can use custom defined math surfaces

$\endgroup$
1
$\begingroup$

I think the answer is NO. Blender can not make 3D fractals. You can make 2D fractals using OSL or python (as other answers explain).

3D fractal softwares use voxel data to create volumetric shapes through certain number of iterations. I think it is not a question of making surfaces or vertices with code or addons.

I don't know how BI works with voxel data but in Cycles it is a future project. There is some recent work made by blender developers but the future is the integration with OpenVDB library. Before this milestone won't be possible to create a proper 3D fractal.

$\endgroup$
1
  • $\begingroup$ 7 years later, this answer is incorrect. You can now use geometry nodes to build voxels ~ mandelbulb example: youtube.com/watch?v=xuLIJ-FNkSI $\endgroup$
    – BurnsBA
    Oct 2, 2022 at 21:52
1
$\begingroup$

Fractals in blender can be imitated however, using image tracking software like "123D Catch". You can use a script to analyze point locations to reverse engineer a fractal somehow for polygonal simplification, but doubt it would do any better than Mandelbulber for speed no matter what you do. I've been looking into using strafed jpegs around objects in Mandelbulber for generating terrain which can then we weathered, and or given many other types of mods for use in Unigine or Unity. It might be useful for a terrain generator to be built into Mandelbulber itself. Take on a non-standard grid using 5 (or variable divisible into 360 evenly) of perspectives to simplify the voxels by merging the points onto the perspective grid using fuzzy logic to figure which planes to stick to. I've seen a blender image catcher outside of 123D but haven't had time to compare the two. 123D is out of beta testing, so she's really good for this.

$\endgroup$
1
$\begingroup$

Fractals in Geometry Nodes

There are various strategies. One is to just chain "Instance on Points" node:

Another example: How to create a Sierpinski Dodecahedron fractal

It works by spawning input geometry on itself, then the resulting geo is spawned again on the input geo to create 2nd iteration, which is spawned again on input geo to create 3rd iteration…

Unfortunately if there's more than 6 levels of instances - an instance (1) within an instance (2) within an instance (3) within an instance (4) within an instance (5) within an instance (6) - Blender will fail to display them:

Can I change recursive depth limit of instance ownership?

The solution is to use "Realize Instances" node, preferably as early as possible to still use the maximum limit of instance depth - to the left of the 6th Instance on Points node counting from the right.

Another strategy would be to only instance cheap points, and store attributes on them such as scale or rotation if needed. Then use just a single depth of instances:

My tests show the latter strategy is significantly worse, at least in case of the Sierpiński Triangle. No wonder, the strength of instances is to avoid repeating geometry, but if each instance is just one triangle, it's hardly an optimization. I thought maybe combining the two solutions could lead better results, but from my tests there was no performance difference when moving geometry to an instance…

So while I get stable 25 FPS for this setup:

I get ~ 9.5 FPS for those setups (the GIF shows less and more change between setups, which is probably caused by the fact of recording interfering with the measurement):

Finally, rather than instancing, you can just chain custom groups which transform geometry like in this answer of mine:

How to invert / change direction of the edges of an object using geometry nodes

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .