Electric DoilySpark PlugKali's Mandelbox
Spark Plug
Previous Image | Next Image
Description: Gold fractal + spherical inversion

based on: https://www.shadertoy.com/view/XdGXRV
Stats:
Views: 30
Total Favorities: 0 View Who Favorited
Filesize: 4.12MB
Height: 1011 Width: 2100
Keywords: Gold Fractal 
Posted by: kosalos February 16, 2020, 08:08:34 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: 118



View Profile
February 19, 2020, 08:55:06 PM
source code (OSX metal)

camera = SIMD3<Float>(0.054930024, 0.012822651, -0.3099327)
viewVector =  SIMD3<Float>(-0.13605243, 0.5401283, 0.8305125)
topVector =  SIMD3<Float>(-0.20285998, 0.80535424, -0.55700296)
sideVector =  SIMD3<Float>(-0.9697098, -0.24425934, 1.490116e-08)
control.cx = -0.1500191
control.cy = 0.43999988
control.cz = 1.1899992
control.cw = 0.8200002
control.dx = 7.450581e-09
control.dy = 1.4499997
control.dz = -0.24999999
control.maxSteps = 15.0
control.InvCenter =  0.04 , 0.1 , -0.142
control.InvRadius =  0.16999996
control.InvAngle =  -0.22999994
control.orbitStyle = 0
control.secondSurface = 0

float DE_GOLD(float3 p,device Control &control,thread float4 &orbitTrap) {
    p.xz = mod(p.xz + 1.0, 2.0) - 1.0;
    float4 q = float4(p, 1);
    float3 offset1 = float3(control.cx, control.cy, control.cz);
    float4 offset2 = float4(control.cw, control.dx, control.dy, control.dz);

    float3 ot,trap = control.otFixed;
    if(int(control.orbitStyle + 0.5) == 2) trap -= p;
   
    for(int n = 0; n < control.maxSteps; ++n) {
        q.xyz = abs(q.xyz) - offset1;
        q = 2.0*q/clamp(dot(q.xyz, q.xyz), 0.4, 1.0) - offset2;
       
        ot = q.xyz;
        if(control.orbitStyle > 0) ot -= trap;
        orbitTrap = min(orbitTrap, float4(abs(ot), dot(ot,ot)));
    }
   
    return length(q.xyz)/q.w;
}

float DE(float3 pos,device Control &control,thread float4 &orbitTrap) {
    if(control.doInversion) {
        pos = pos - control.InvCenter;
        float r = length(pos);
        float r2 = r*r;
        pos = (control.InvRadius * control.InvRadius / r2 ) * pos + control.InvCenter;
       
        float an = atan2(pos.y,pos.x) + control.InvAngle;
        float ra = sqrt(pos.y * pos.y + pos.x * pos.x);
        pos.x = cos(an)*ra;
        pos.y = sin(an)*ra;
        float de = DE_GOLD(pos,control,orbitTrap);
        de = r2 * de / (control.InvRadius * control.InvRadius + r * de);
        return de;
    }
   
    return DE_GOLD(pos,control,orbitTrap);
}

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