Thanks I am using an intersection now but I'm trying to figure out a way not to. Ah thanks Effie I was just typing my formula now. Here is the formula:

par int ColorIterations 2 100 20 val

par int ColoringType 0 4 0 val

par float ColorScale 0.0 2.0 1.0 val

par float ColorOffset -2.0 2.0 0.0 val

par int sIterations 0 100 20 val

par vec3 sOffset -10 10 0 val

par float sZoom 0 4 1 val

par float sScale 0 6 1 val

par float sFatness 0 10 2 val

par vec3 sJulia -10 10 -1 val

par vec2 sJulia2MinMax -1 100 -1 val

par vec3 sJulia2 -10 10 0 val

par float sMoonSize 0 4 1 val

par int kIterations 0 100 20 val

par float kScale 0 6 2 val

par float kFatness 0 5 0 val

par vec3 kOffset -10 10 .5 val

par vec3 kFold -4 4 0 val

par vec3 kJulia -4 4 0 val

par vec3 kJulia2 -4 4 0 val

par vec2 kJulia2MinMax -1 100 -1 val

par vec3 Rotate -360 360 0 val

par vec2 RotMinMax -1 100 -1 val

par float OutputMode 0 1 0 val

par float OrbitSK 0 1 0 val

par vec3 kRotate2 -360 360 0 val

float r;

int n = 0;

mat3 rot;

mat3 rot2;

void init()

{

rot = rotationAngleMatrixXYZ(Rotate);

rot2 = rotationAngleMatrixXYZ(kRotate2);

}

float sminPoly( float a, float b, float k )

{

float h = clamp( 0.5+0.5*(b-a)/k, 0.0, 1.0 );

return mix( b, a, h ) - k*h*(1.0-h);

}

float absScalem1 = abs(kScale - 1.0);

float AbsScaleRaisedTo1mIters = pow(abs(kScale), float(1-kIterations));

float absScale = abs(kScale);

float DE(vec3 p)

{

vec3 p2 = p;

orbitTrap = vec4(1000.0);

float fat = sFatness;

vec3 sP = p * sZoom - sOffset;

vec4 sOrbitTrap = orbitTrap;

vec4 kOrbitTrap = orbitTrap;

float dr = 1.0;

int n = 0;

float l = 0;

float prevl = 0;

for( int i=0; i<sIterations;i++ )

{

// Spherical

prevl = l;

sP = abs(sP);

float sR = dot(sP,sP);

if (i <= ColorIterations)

{

if (ColoringType==0) sOrbitTrap = min(sOrbitTrap, vec4((1/sP),sR) );

if (ColoringType==1) sOrbitTrap = min(sOrbitTrap, abs(vec4(sP.xyz,0)));

if (ColoringType==2) sOrbitTrap = min(sOrbitTrap, vec4((1/sP),sR));

if (ColoringType==3) sOrbitTrap = min(sOrbitTrap, vec4((1/sP),sR));

//if (ColoringType==2) sOrbitTrap += exp(-1/abs(l+prevl+ColorOffset));

//if (ColoringType==3) sOrbitTrap+=abs(l-prevl+ColorOffset);

}

l = length(sP);

float k = max(sScale/sR,0.1);

sP *= k;

fat *= k;

sP += sJulia;

if (i >= int(sJulia2MinMax.x) && i <= int(sJulia2MinMax.y)) sP += sJulia2;

//if (i >= int(RotMinMax.x) && i <= int(RotMinMax.y)) sP *= rot;

}

l = 0.0;

prevl =0.0;

p *= rot2;

//IFS

while (n < kIterations)

{

prevl = l;

p-= 2.0 * min(0.0, dot(p, vec3(-0.5, 0.309017, 0.809017))) * vec3(-0.5, 0.309017, 0.809017);

p-= 2.0 * min(0.0, dot(p, vec3(0.309017, 0.809017, -0.5))) * vec3(0.309017, 0.809017, -0.5);

p-= 2.0 * min(0.0, dot(p, vec3(0.809017, -0.5, 0.309017))) * vec3(0.809017, -0.5, 0.309017);

p-= 2.0 * min(0.0, dot(p, vec3(-0.5, 0.309017, 0.809017))) * vec3(-0.5, 0.309017, 0.809017);

p-= 2.0 * min(0.0, dot(p, vec3(0.309017, 0.809017, -0.5))) * vec3(0.309017, 0.809017, -0.5);

p-= 2.0 * min(0.0, dot(p, vec3(0.809017, -0.5, 0.309017))) * vec3(0.809017, -0.5, 0.309017);

p-= 2.0 * min(0.0, dot(p, vec3(-0.5, 0.309017, 0.809017))) * vec3(-0.5, 0.309017, 0.809017);

p-= 2.0 * min(0.0, dot(p, vec3(0.309017, 0.809017, -0.5))) * vec3(0.309017, 0.809017, -0.5);

p-= 2.0 * min(0.0, dot(p, vec3(0.809017, -0.5, 0.309017))) * vec3(0.809017, -0.5, 0.309017);

if (p.x<p.y) p.xy = p.yx;

if (p.x<p.z) p.xz = p.zx;

if (p.y<p.z) p.yz = p.zy;

p -= kJulia;

p = abs(p+kFold)-kFold;

p = p*kScale - kOffset*(kScale-1.0);

float kR = dot(p, p);

if (n <= ColorIterations)

{

if (ColoringType==0) kOrbitTrap = min(kOrbitTrap, vec4(p,kR) );

if (ColoringType==1) kOrbitTrap = min(kOrbitTrap, abs(vec4(p.xyz,0)));

if (ColoringType==2) kOrbitTrap = min(min(kOrbitTrap, vec4(p,kR)),sOrbitTrap);

if (ColoringType==3) kOrbitTrap = min(min(kOrbitTrap, vec4(p,kR)),sOrbitTrap);

//if (ColoringType==2) kOrbitTrap += exp(-1/abs(l-prevl+ColorOffset));

//if (ColoringType==3) kOrbitTrap += abs(l-prevl+ColorOffset);

}

//if (n <= ColorIterations) kOrbitTrap = min(kOrbitTrap, vec4((p),kR) );

dr *= absScale;

if (n >= int(kJulia2MinMax.x) && n <= int(kJulia2MinMax.y)) p -= kJulia2;

if (n >= int(RotMinMax.x) && n <= int(RotMinMax.y)) p *= rot;

l = length(p);

n++;

}

orbitTrap = mix(sOrbitTrap,kOrbitTrap,OrbitSK)* ColorScale + ColorOffset;

//if (ColoringType==3) orbitTrap/=ColorIterations;

//orbitTrap = min(sOrbitTrap,kOrbitTrap);

float d;

d = max(sdSphere(p2,sMoonSize),0.25*length(sP.xyz)/fat);

//float da = length(p) * pow(kScale, -float(n))-(kFatness * 0.001);

float db = ((length(p) - absScalem1) / dr - AbsScaleRaisedTo1mIters)-(kFatness * 0.001);

//float mn = min(d,db);

float mn = sminPoly(d,db,OutputMode);

return mn;

}

void main() { RayMarchMain(); }

This formula basically blends two formulas an infinitely repeating spherical formula and an IFS but in the line:

d = max(sdSphere(p2,sMoonSize),0.25*length(sP.xyz)/fat);

A boolean intersection is done on the "Spherical" formula with a sphere so only globe of the "Spherical" formula appears.

What I would like to do is modify the "Spherical" formula so it stops at a certain radius rather than use a boolean. I've tried something like:

float dist = length(p);

if (dist > sMoonSize) break;

in the beginning of the "Spherical" iteration and it does work and does stop the formula from continuing beyond a set size but it doesn't draw properly. I'm not sure...