Welcome to Fractal Forums

Fractal Software => Programming => Topic started by: tryptophan on May 09, 2013, 12:11:21 PM




Title: Another discontinous function
Post by: tryptophan on May 09, 2013, 12:11:21 PM
I've got another function that is pretty noisy. It makes some really cool shapes though and I was wondering if someone might have an idea how to make it more solid. Basically it's really noisy no matter what settings I set. Here's the code:

Code:
float DE(in vec3 p )
{
float d = 0;
float fat = Fatness;
orbitTrap = vec4(1000.0);

for( int i=0; i<Iterations;i++ )
{
p = abs(p);
float r2 = dot(p,p);
if (i <= ColorIterations) orbitTrap = min( orbitTrap, vec4(abs(p)*12,r2) );
               
float k = max(Scale/r2,0.1);
p     *= k;
fat *= k;
p *= Julia+1.0;
p += Offset;
p *= rot1;
                        d = 0.25*abs(p.y)/fat;
                        return d;
                }

the settings Scale = 1, Fatness = 1, and Offset -1.08,-1.2,-0.9 with the rest at 0 are a pretty cool zone. If anyone has and idea on how to reduce the noise that would be amazing.

cheers
Keith


Title: Re: Another discontinous function
Post by: cKleinhuis on May 09, 2013, 12:35:56 PM
an example image ???


Title: Re: Another discontinous function
Post by: eiffie on May 09, 2013, 05:42:58 PM
yikes it doesn't make sense (perhaps you copied it wrong??)
It bails out and returns d on the first loop. I am guessing there was a } after /fat;

In that case the offending line is z*=Julia+1.0; (not sure what you were trying for there?)


Title: Re: Another discontinous function
Post by: tryptophan on May 09, 2013, 08:04:18 PM
Sorry my bad I did copy it wrong. I have what I'm calling Input(loop) and Output (distance calc) modes/switches so I missed a bracket. Yeah the so called julia doesn't do much in that mode in another though with small values it has a flowering effect. Just rendering some images for you guys to check out I've come to realize its my DE engine. I've just started writing my own ray marcher the other day. (I have to admit hacked together by referring to marchers written by, Syntopia, IQ, Effie your global Illumination is the next thing I'm going to look at) but I have written every line and have implemented a few of my own ideas, mostly for coloring, and lighting. Once I get it a little further along I'll make a Fragmentarium version and post it in a new thread.

The original formula I got from an IQ post on ShaderToy called Apollonian. I then made 3 different iteration modes and 6 different output modes which includes the original. All this gave me an idea this morning to make a system for combining formulas together outside of the shader which I think will increase the shaders speed, but that is for a later date. I'll post the full formula and a few images:

Code:
float DE(in vec3 p )
{
float d = 0;
float fat = Fatness;
orbitTrap = vec4(1000.0);

if (InputMode == 0)
{
for( int i=0; i<Iterations;i++ )
{
p = -1.0 + 2.0*fract(0.5*p+0.5);

float r2 = dot(p,p);
if (i <= ColorIterations) orbitTrap = min( orbitTrap, vec4(abs(p)*12,r2) );

float k = max(Scale/r2,0.1);
p     *= k;
fat *= k;
p *= Julia+1.0;
p += Offset;
p *= rot1;
}
}

else if (InputMode == 1)
{
for( int i=0; i<Iterations;i++ )
{
p = -1.0 + 2.0*fract(0.5*p+0.5);
if (p.x+p.y < 0.0) p.xy = -p.xy;
if (p.x+p.z < 0.0) p.xz = -p.xz;
if (p.y+p.z < 0.0) p.yz = -p.yz;
float r2 = dot(p,p);
if (i <= ColorIterations) orbitTrap = min( orbitTrap, vec4(abs(p)*12,r2) );
                
float k = max(Scale/r2,0.1);
p     *= k;
fat *= k;
p *= Julia+1.0;
p += Offset;
p *= rot1;
}
}

else if (InputMode == 2)
{
for( int i=0; i<Iterations;i++ )
{
p = abs(p);
float r2 = dot(p,p);
if (i <= ColorIterations) orbitTrap = min( orbitTrap, vec4(abs(p)*12,r2) );
                
float k = max(Scale/r2,0.1);
p     *= k;
fat *= k;
p *= Julia+1.0;
p += Offset;
p *= rot1;
}
}

else
{
for( int i=0; i<Iterations;i++ )
{
p = abs(Tile.xyz-mod(p,2.0*Tile.xyz));
float r2 = dot(p,p);
if (i <= ColorIterations) orbitTrap = min( orbitTrap, vec4(abs(p)*12,r2) );
                
float k = max(Scale/r2,0.1);
p     *= k;
fat *= k;
p *= Julia+1.0;
p += Offset;
p *= rot1;
}
}

if (OutputMode == 0)
{
d = 0.25*length(p.xyz)/fat;
}
else if (OutputMode == 1)
{
d = 0.25*abs(p.y)/fat;///length(Offset);
}
else if (OutputMode == 2)
{
d = min(0.25*length(p.xyz),sdBox(normalize(p*CubeJulia+CubeOffset),CubeScale))/fat;
}
else if (OutputMode == 3)
{
d = min(0.25*abs(p.y),sdBox(normalize(p*CubeJulia+CubeOffset),CubeScale))/fat;
}
else if (OutputMode == 4)
{
d =max(0.25*length(p.xyz),sdBox(normalize(p*CubeJulia+CubeOffset),CubeScale))/fat;
}
else if (OutputMode == 5)
{
d = max(0.25*abs(p.y),sdBox(normalize(p*CubeJulia+CubeOffset),CubeScale))/fat;
}


orbitTrap = orbitTrap * ColorScale + ColorOffset;

return d;
}

The first one has the noise I was talking about as well as another on the next post.


Title: Re: Another discontinous function
Post by: tryptophan on May 09, 2013, 08:08:29 PM
here a couple more


Title: Re: Another discontinous function
Post by: KRAFTWERK on May 09, 2013, 08:42:11 PM
I like some of those images, interesting!


Title: Re: Another discontinous function
Post by: eiffie on May 09, 2013, 11:18:48 PM
OK if julia is a vector (i assume) then you need to multiply "fat" by the larger of julia.x,y or z.

When you multiply "p" by something you also need to multiply your variable "fat" by the same but since "fat" is just a scalar you need to take the worst case.

There is a more accurate way but I really can't explain it - look at IQ's ellipse sample on ShaderToy. https://www.shadertoy.com/view/MdfGWn (https://www.shadertoy.com/view/MdfGWn)


Title: Re: Another discontinous function
Post by: tryptophan on May 09, 2013, 11:40:53 PM
Thanks Effie that makes total sense. I figured I would have to do something to balance the formula. I just wasn't sure what. I've just checked out IQ's maintain a constant distance to boundary and that looks like it would be really helpful. Thanks again for the help.

Ps next time I'll post the uniform declarations as well so it obvious what is a vector or scalar. - julia is a vector in the above example

cheers
Keith


Title: Re: Another discontinous function
Post by: tryptophan on May 10, 2013, 01:02:21 AM
Quote
I like some of those images, interesting!

Thanks Kraftwerk I thought so also.


Title: Re: Another discontinous function
Post by: cKleinhuis on May 10, 2013, 03:59:01 AM
lol,  @tryptophan, stop coding, start produciiiiiiiiiiiiiiiiiiing!


Title: Re: Another discontinous function
Post by: tryptophan on May 10, 2013, 04:03:01 AM
I know I know but there are just so many combinations!!!  :D . Actually I have been though but just short loops for live visuals.