(Question) What is wrong with my amazing surf distance estimator?

  • 4 Replies

0 Members and 1 Guest are viewing this topic.

Offline NLIBS

  • *
  • Fractal Freshman
  • *
  • Posts: 3
« on: June 11, 2019, 05:03:39 AM »
Hi everyone.

This is my first post on this forum so I hope I'm at the right place.

I'm currently trying to make a game themed on fractals in opengl. What I have so far is a renderer that works just fine and I know this because I have used it other fractals (mandelbox,mixpinski4ex).
My issue is that I just recently tried to implement a distance estimator for the amazing surf formula (the original without mods) and it appears to have a very low quality and accuracy.

I have attached two files so you can understand what i'm talking about. "coneMarch.frag" is the shader that includes the distance estimator (not commented, just ask and i'll clarify). "problem.png" is an image which shows a sphere that should be touching the fractals surface because its radius is equal to the output of the distance estimator.

The effects such as ambient occlusion are completely broken due to this and im getting way less fps with this broken DE. As a side note I'm also wondering why the amazing surface needs so many iterations and if this is only the case in my implementation.

Cheers, NLIBS.

Offline mclarekin

  • *
  • Fractal Frogurt
  • ******
  • Posts: 492
« Reply #1 on: June 11, 2019, 10:13:38 AM »
I can not really help you your raymarching, but here is some random information

1)  On the "side note" this is statistics from MandelbulberV2 Asurf.  using default bailout  r = 100 ( or rr = 100 * 100), probably larger than required

scale 2              13 fractal iterations
scale 1.1            78 fractal iterations

2)  This is my most recent Fragmentarium asurf

To  convert this back to a more standard Asurf  replace maxRR with 1, and remove the cylindrical fold
you should use MinRR rather than sqrt(minR)
note the way the addition of constant is implemented at the end of the iteration, this creates a lot more variations at little cost.
vary scale method is more flexible with two parameters
sphere fold has been rearranged just for the purposes of grabbing some color, not normally coded this way.
generally for asurf color i  use  the original points p.z value  to produce some vertical color gradient

You can use this kind of code for finding a game terrain then hardcode out the slider variables. It could be interesting running your code in Fragmentarium to compare render time

Code: [Select]
// Output generated from file: C:/Users/graeme/Downloads/Fragmentarium-2.5.0-181027-winex/Fragmentarium-2.5.0-181027.winex/Examples/mclarekin/abox4.frag
// Created: Tue Feb 26 01:53:51 2019
#info Mandelbox Distance Estimator
#define providesInit
#include "MathUtils.frag"
#include "DE-Raytracer.frag"
#group Asurf2

The distance estimator below was originalled devised by Buddhi.
This is a generic abox type
with two similar varable scale functioms added .
and a iteration based color tweak. mclarekin 25-02-2019

// Number of fractal iterations.
uniform int Iterations;  slider[0,60,300]
uniform float Bailout;  slider[0,100,1000]
uniform int ColorIterations;  slider[0,16,300]

// box fold
uniform vec3 boxLimit; slider[(-5.0,-5.0,-5.0),(1.0,1.0,1.0),(5.0,5.0,5.0)]

// sphere fold, including forceCylindricalFold
uniform float minRR;  slider[0,0.25,2.0]
uniform float maxRR;  slider[0,1.0,2.0]
uniform vec3 offsetSph; slider[(-5.0,-5.0,-5.0),(0.0,0.0,0.0),(5.0,5.0,5.0)]

uniform bool forceCylFold; checkbox[false]
uniform int startIters; slider[0,0,100]
uniform int stopIters; slider[0,1,100]
uniform float scaleCylFold; slider[-5.0,1.0,5.0]

// scale controls
uniform float Scale;  slider[-5.0,2.0,5.0]
uniform float scaleVary; slider[-2.00,0.0,2.00]
uniform float scaleOffset; slider[-5.00,0.0,5.00]
uniform bool varyMode2; checkbox[false]

// precomputed constants
uniform vec3 Rotation; slider[(-180,-180,-180),(0,0,0),(180,180,180)]

// addition constants
uniform vec3 OrigPtOffset; slider[(-10.0,-10.0,-10.0),(1.0,1.0,1.0),(10.0,10.0,10.0)]
uniform vec3 c3Julia; slider[(-100.0,-100.0,-100.0),(0.0,0.0,0.0),(100.0,100.0,100.0)]

//uniform vec3 IterColorTweak; slider[(-0.2,-0.2,-0.2),(0.0,0.0,0.0),(0.2,0.2,0.2)]
uniform vec3 sphereColorTweak; slider[(-1.0,-1.0,-0.01),(0.0,0.0,0.0),(1.0,1.0,0.01)]

mat3 rot;

void init() {

 rot = rotationMatrixXYZ(Rotation);

// Compute the distance from `pos` to the Mandelbox.
float DE(vec3 pos) {
vec3 p3 = pos;
vec3 OrigPoint = pos * OrigPtOffset;
float Dd = 1.0;
float rr;
float radiusFactor = maxRR/minRR;
float useScale = 1.0;
float addScale = 0.0;
vec3 addColor = vec3(0.0);

for (int i=0; i<Iterations; i++) {

// box fold
// p3 = clamp(p3, -boxLimit, boxLimit) * 2.0 - p3;
p3.xy = clamp(p3.xy, -boxLimit.xy, boxLimit.xy) * 2.0 - p3.xy;

// spherical fold

rr = dot(p3,p3);

// force cylinder fold
if (forceCylFold && i >= startIters && i < stopIters)
rr -= p3.z * p3.z * scaleCylFold; // fold weight

p3 += offsetSph;

float temp1 = rr - minRR;
float temp2 = rr - maxRR;
if (temp1 < 0.0)
p3 *=  radiusFactor;
Dd *=  radiusFactor;
//addColor.x += sphereColorTweak.x;
addColor.x += sphereColorTweak.x * temp1 * float(i);

else if (temp2 < 0.0)
float tglad_factor2 =  maxRR / rr;
p3 *= tglad_factor2;
Dd *= tglad_factor2;
//addColor.y += sphereColorTweak.y;
addColor.y += sphereColorTweak.y * temp2 * float(i);
temp1 = rr - maxRR;
addColor.z += sphereColorTweak.z * temp1 * float(i);

p3 -= offsetSph;

// scale
useScale = addScale + Scale;
p3 *= useScale;
Dd = Dd * abs(useScale) + 1.0;

// update addScale for next iteration
float vary = scaleVary * (abs(addScale) + scaleOffset);
if (varyMode2) addScale = vary;
else addScale += vary;

p3 *= rot;

// add constants
p3 += OrigPoint + c3Julia;

rr = dot(p3,p3);

//orbitTrap += vec4(addColor,0.0);

if (i<ColorIterations) orbitTrap = min(orbitTrap, abs(vec4(p3,rr)));

orbitTrap += vec4(addColor,rr);

    if ( rr>Bailout) break;

return sqrt(rr) / abs(Dd) ;

Offline NLIBS

  • *
  • Fractal Freshman
  • *
  • Posts: 3
« Reply #2 on: June 11, 2019, 12:11:44 PM »
Great help, thanks very much.

It's funny because I don't recall finding the Asurf script in fragmentarium.

It would be good to know where it can be found since then I could do that speed comparison you suggested.

Offline Sabine62

  • *
  • Fractal Frankfurter
  • *
  • Posts: 616
  • It's just a jump to the left...
    • sabine62.deviantart.com
« Reply #3 on: June 11, 2019, 12:23:26 PM »
You can find the original asurf under Examples\Kali's Creations  ;)
To thine own self be true

Offline NLIBS

  • *
  • Fractal Freshman
  • *
  • Posts: 3
« Reply #4 on: June 12, 2019, 10:02:02 AM »
Ohhh, it's because I couldn't find the newest version of fragmentarium, well thanks for the response.

"Time Span"

Started by cricke49 on Fractal Image Gallery

0 Replies
Last post August 02, 2018, 07:05:21 AM
by cricke49
Amazing Surf 2 panels

Started by 1bryan1 on Fractal Image Gallery

0 Replies
Last post April 13, 2018, 08:49:40 AM
by 1bryan1
Distance estimator

Started by gerrit on UltraFractal

0 Replies
Last post May 14, 2018, 11:18:59 PM
by gerrit
Fundamental enigma: pythagoras tree, duckies and amazing surf

Started by Alef on Fractal Institute

5 Replies
Last post May 15, 2018, 12:07:20 PM
by Alef
Kali's Amazing Surface

Started by 3DickUlus on Fractal Image Gallery

0 Replies
Last post April 06, 2018, 02:07:41 AM
by 3DickUlus