Spark PlugKali's MandelboxTokamat
Kali's Mandelbox
Previous Image | Next Image
Description: based on: https://github.com/3Dickulus/FragM/blob/Development/Fragmentarium-Source/Examples/Kali's%20Creations/Kalibox.frag
Stats:
Views: 33
Total Favorities: 0 View Who Favorited
Filesize: 4.2MB
Height: 1011 Width: 2100
Keywords: Mandelbox 
Posted by: kosalos February 13, 2020, 09:00:40 AM

Rating: ***** by 1 members.
Total Likes: 1

Image Linking Codes
BB Thumbnail Image Code
BB Medium Image Code
Direct Link
0 Members and 1 Guest are viewing this picture.

Comments (1) rss

kosalos
Fractal Friar
*
Offline Offline

Posts: 116



View Profile
February 19, 2020, 09:03:43 PM
source code (OSX metal)

camera = SIMD3<Float>(-0.3408362, 0.15553184, -1.9804056)
viewVector =  SIMD3<Float>(0.0, 0.09950372, 0.9950372)
topVector =  SIMD3<Float>(-4.349444e-08, 0.9950368, -0.09950728)
sideVector =  SIMD3<Float>(-0.9999999, -4.327858e-08, 4.327858e-09)
control.cx = 1.7500008
control.cy = 0.15499973
control.cz = 0.0
control.cw = 0.0
control.dx = -1.0100006
control.dy = -3.6150007
control.dz = -0.39999986
control.juliaboxMode = 0
control.maxSteps = 20.0
control.angle1 = 3.5000005
control.angle2 = 0.0
control.julia = 0,0,0
control.absScalem1 = abs(c.cx - 1.0)
control.AbsScaleRaisedTo1mIters = pow(abs(c.cx), Float(1 - c.maxSteps))
control.n1 = simd_float3(c.dx,c.dy,c.dz)
control.mins = simd_float4(c.cx, c.cx, c.cx, abs(c.cx)) / c.cy

float DE(float3 pos,device Control &control,thread float4 &orbitTrap) {
    float4 p = float4(pos,1), p0 = float4(control.julia,1);  // p.w is the distance estimate
   
    float3 ot,trap = control.otFixed;
    if(int(control.orbitStyle + 0.5) == 2) trap -= pos;
   
    for (int i = 0; i < control.maxSteps;++i) {
       
        // p.xyz*=rot;
        p.xyz = rotatePosition(p.xyz,0,control.angle1);
        p.xyz = rotatePosition(p.xyz,1,control.angle1);

        p.xyz = abs(p.xyz) + control.n1;
        float r2 = dot(p.xyz, p.xyz);
        p *= clamp(max(control.cy/r2, control.cy), 0.0, 1.0);  // dp3,div,max.sat,mul
        p = p * control.mins + (control.juliaboxMode ? p0 : float4(0.0));
       
        ot = p.xyz;
        if(control.orbitStyle > 0) ot -= trap;
        orbitTrap = min(orbitTrap, float4(abs(ot), dot(ot,ot)));
    }
   
    return ((length(p.xyz) - control.absScalem1) / p.w - control.AbsScaleRaisedTo1mIters);
}

constant int MAX_MARCHING_STEPS = 255;
constant float MIN_DIST = 0.00002;
constant float MAX_DIST = 60;

float3 shortest_dist(float3 eye, float3 marchingDirection,device Control &control,thread float4 &orbitTrap) {
    float dist,hop = 0;
    float3 ans = float3(MIN_DIST,0,0);
    float secondSurface = control.secondSurface;
    int i = 0;
   
    for(; i < MAX_MARCHING_STEPS; ++i) {
        dist = DE(eye + ans.x * marchingDirection,control,orbitTrap);
        if(dist < MIN_DIST) {
            if(secondSurface == 0.0) break;     // secondSurface is disabled (equals 0), or has 2already been used
            ans.x += secondSurface;             // move along ray, and start looking for 2nd surface
            secondSurface = 0;                  // set to zero as 'already been used' marker
        }

        ans.x += dist;
        if(ans.x >= MAX_DIST) break;
       
        // don't let average distance be driven into the dirt
        if(dist >= 0.0001) hop = mix(hop,dist,0.95);
    }
   
    ans.y = float(i);
    ans.z = hop;
    return ans;
}

Return to Gallery


Powered by SMF Gallery Pro