Tree fractal

By: Gijs Bellaard

Tree fractal


The Tree fractal


//The amount of iterations
const int ITERATIONS = 10;

//The scaling factor between iterations
const float SCALE = 1.5;

//The angle the branches make
const vec3 ANGLE = vec3(0,0,0.1);

//The size of a section
const vec3 SECTION = vec3(.1,1,.1);

const vec3 m = getRotationMatrix(ANGLE);
const vec3 g = m*vec3(0,1,0);
const vec3 n = normalize(vec3(g.x,0,g.z));

float distanceTree(vec3 p){
    float s = 1.;
    float dis = 1e20;
    for(int i=0; i<ITERATIONS; i++){
        //Distance to a box
        dis = min(dis, distanceBox(p,SECTION)/s);

        p -= 2.*min(0.,dot(p,n))*n;
        p.y -= SECTION.y;
        p *= SCALE;
        s *= SCALE;
        p -= g*SECTION.y;
        p *= m;

    return dis;