MB3D compatibilty (original formulas used)

  • 7 Replies
  • 352 Views

0 Members and 1 Guest are viewing this topic.

Offline Recursed

  • *
  • Fractal Freshman
  • *
  • Posts: 7
« on: February 20, 2020, 10:43:01 AM »
Hi Guys,

Recently I’ve gotten really into 3D-fractals, such as the beautiful ones created by Mandelbulb3D. I want to further study and implement the formulas there and perhaps experiment with the wealth of MB3D-files out there. Unfortunately, the raw formulas in MB3D are only available in machine code.

Mandelbulber 2 by forum member Buddhi looks like it’s using the same algorithm as MB3D, but I’ve not been able to get the output of the two programs to match. They seem to use different names (MandelBox vs AmazingBox/_AmazingBpx/_AmazingBoxSSE2) and in addition to that, the Mandelbulber formulas often have more variables.

Are there any plans to make Mandelbulber 2 compatible with MB3D-files? Does someone (perhaps the original creator) have documentation on what formula the machine code is actually implementing? If not, perhaps we could at least start documenting/reverse-engineering the formulas in MB3D (most of them should be pretty simple?), so it would be possible to say “with these parameters, this formula in Mandelbulber is identical to MB3D”.

I’ve been thinking of a new project, and creating those MB3D fractals on the GPU sounds pretty interesting. The main thing holding me back is the formulas being so hard to come by making cross-referencing difficult. Ideally IMO, a situation akin to flam3/JWildfire/etc. could arise, in which all variations/formulas are available and easy to examine or improve by everyone.

Linkback: https://fractalforums.org/mandelbulber/14/mb3d-compatibilty-original-formulas-used/3331/

Offline mclarekin

  • *
  • Fractal Freak
  • **
  • Posts: 777
« Reply #1 on: February 20, 2020, 12:01:17 PM »
Hi,

Some M3D formulas and parameters can currently be replicated in MandelbulberV2, but it is not easy to explain which ones  and how to do it.
If you have a specific formula,  i could try and help

Note M3D has a different function order with the rotation matrix.
We intend to implement a M3D rotation matrix in Mandelbulber to make it easier to import parameters.

We have a project to implement more M3D code, but after dissambling the machine language and figuring out the DE methods, we found that there is still a lot more work to do

Offline Recursed

  • *
  • Fractal Freshman
  • *
  • Posts: 7
« Reply #2 on: February 20, 2020, 12:51:24 PM »
Hi mclarekin, thanks for your quick reply!

Well, the end goal would be to be able to render MB3D fractals in other programs, so I would say eventually the majority of the formulas. I'm not sure if that is something you'd envision with Mandelbulber? Seeing the huge popularity of MB3D I can imagine other people being interested in the "raw" formulas, and thereby their original work, as well. There were also a couple efforts to restart/continue MB3D on this forum. Hence I'm suggesting a joint effort as this forum seems to be filled with people way more knowledgeable than me.

The first fractal I started with because it seems quite easy is this one (2 formulas, Amazing Box and Sierpinski3):
https://www.deviantart.com/phoenixkeyblack/art/Egyptian-Pottery-WTF-264941230

When I look at other formulas in the MB3D repository (e.g. https://github.com/thargor6/mb3d/blob/66c45c98eb666e1cb0ccb8aaf36bccbb3fc574d2/M3Formulas/MengerHyper.m3f), some of them have little clues such as old forum posts. But if you're leaving notes, why not also mention the exact formula you're implementing instead of just some bytecode?? [/rant]. Maybe some of the original implementers still have some documentation they'd be willing to share?

Which rotation matrix do you mean? The camera one, or is there another one in the "fractal loop"?

Offline buddhi

  • *
  • Fractal Feline
  • **
  • Posts: 157
    • Mandelbulber GitHub repository
« Reply #3 on: February 20, 2020, 10:39:36 PM »
Reverse engineering of MB3D formulas is more difficult that in it looks like. Even after using good disassember the code is still difficult to understand. Formulas were compiled using Delphi so the code sometimes looks very strange.
Example of disassembly of abox formula to python:
Code: [Select]
    global z.x;
    v0_8 = z.x;
    v4_f = z.x;
    v2_15 = fabsl(v4_f - 1.0) # bp+15;
    v4_1f = fabsl(v4_f + 1.0) - (v2_15 + v4_f);
    v2_27 = fabsl(z.y - 1.0) # bp+27;
    v4_31 = fabsl(z.y + 1.0) - (v2_27 + z.y) # bp+31;
    v2_39 = fabsl(z.z - 1.0) # bp+39;
    v4_43 = fabsl(z.z + 1.0) - (v2_39 + z.z) # bp+43;
    st3_global_2d_to_2d_local = v4_1f * v4_1f + v4_31 * v4_31 + v4_43 * v4_43 # st3;
    v1_58 = __asm_fnstsw(fpsw_global_2d_to_2d_local) # bp+58;
    z.x = z.x & -0x10000 | v1_58 & -0xff01 | v1_58 / 2 & 0x7f00;
    if v1_58 & 256 == 0:;
        v1_69 = __asm_fnstsw(fpsw_global_2d_to_2d_local) # bp+69;
        z.x = z.x & -0x10000 | v1_69 & -0xff01 | v1_69 / 2 & 0x7f00;
        if v1_69 & 256 == 0:;
            pass;
    else:;
        # 0x5e;
        st3_global_2d_to_2d_local = *((arg1[48] - 24));
    v3_7b = z.z + 8;
    *v3_7b = st3_global_2d_to_2d_local * *v3_7b;
    *z.z = st3_global_2d_to_2d_local * v4_43;
    *z.y = st3_global_2d_to_2d_local * v4_31;
    *v0_8 = v4_1f * st3_global_2d_to_2d_local;
    z.x = v0_8;
    return v0_8;

Assembly code looks even worse. Even if you know this formula very well it is still difficult to understand it. I'm familiar with x86 assembly code, but this is mix of CPU and FPU code.
As you see there are some challenges:
- to understand assembly code or dissaseblmed code to c or python which still has some strange FPU flags or registers
- to figure out meaning of each data offset (data parsing to formula code is not so obvious)

We cannot use binary code from formulas directly, because it was compiled for 32-bit platforms. Mandelbulber is dedicated for 64-bit platforms like amd64, x86-64 or arm64.

Offline mclarekin

  • *
  • Fractal Freak
  • **
  • Posts: 777
« Reply #4 on: February 21, 2020, 12:54:52 AM »
rotation axis sequence in the formula is different
camera orientation is different (mandelbulber looks down the y axis at default setting)

Amazing Box and Sierpinski3 combo should be possible to convert parameters to Mandelbulber.

It is easier if there are no rotations used, or just one axis, (as an example:  last night i was replicating M3D Mandalay-Kifs in Mandelbulber, with a single X-rotation)

BTW, Fragmentarium is an excellant program for learning a lot about the formulas.  I


Offline Recursed

  • *
  • Fractal Freshman
  • *
  • Posts: 7
« Reply #5 on: February 22, 2020, 11:36:14 AM »
Ah, that is Python code? I found the decompiled files somewhere deep in the guts of Mandelbulber and was very confused by the Syntax, which, despite the file extension, didn’t look like C at all. It is not pretty indeed.

From what I’ve understood, the formulas operate on the struct mentioned here http://www.fractalforums.com/tutorials/re-blobby-reknighty/, where I expect the majority of the formulas altering only a few of these. The parameters of a formula are referenced, so they could not be altered during the formula (at most in between iterations). The most interesting (and least documented part?) is probably the distance estimation and derivation within the formulas. From the decompilation it should at least be possible to figure out which parts of the struct are altered right?

I’m aware of Fragmentarium, it’s actually the reason I signed up for this site, as the current version isn’t working for me. You seem to have a good understanding of the way MB3D is implemented, would you be willing to make an example of the fractal mentioned above (or share another MB3D-fractal) in Fragmentarium? I think if I would have at least one working reference implementation I could start working from there, but I’ve not been able to make one as I have so many uncertainties atm.

I’ve also found this, which seems to implement a few of the same formulas as MB3D (and it's from the same person who carried MB3D for a while). https://github.com/thargor6/FFVectron/tree/master/fractals

Offline mclarekin

  • *
  • Fractal Freak
  • **
  • Posts: 777
« Reply #6 on: February 23, 2020, 05:58:12 AM »
Distance estimation. I think some of M3D works with a vec4 where z.w is used for the DE
These are my old incomplete  notes on M3D DE
Quote
default  has none, assume  a form of deltaDE
.DEoption = -1 no analytic DE within the transform
.DEoption = 0  found one so far , genintpow, maybe an early version of log analytic?
.DEoption = 1 transform analytic
.DEoption = 2 general linear analytic and some transforms
.DEoption = 4  general log analytic  and some transforms 
.DEoption = 5 transform analytic 4D scale
.DEoption = 6 mixpinski
.DEoption = 11  AtetraVS
.DEoption = 20 most  difs &  jos leys i.e menus1 & 2
.DEoption = 21 menu 3 of dIFS

Fragmentarium.  I have not tried the latest updates, i am currently using Fragmentarium-2.5.0-190913-winex, without any problems.
If you look at the Fragmentarium section of FractalForums, you will find some M3D formulas ported to Fragmentarium GLSL. i also have some examples of replicating some M3D formula parameters  in Mandelbulber. but that may take some time to find

Octane Vectron ). https://github.com/thargor6/FFVectron/tree/master/fractals
Last time i looked there they were all fragmentarium formulas converted for vectron



Offline mclarekin

  • *
  • Fractal Freak
  • **
  • Posts: 777
« Reply #7 on: February 24, 2020, 11:08:33 AM »
example : asurf   m3d parameters to mandelbulber
z.x * -1 on first iteration
and reverse rotation order to gamma beta alpha

Code: [Select]
Mandelbulb3Dv18{
g.....c....s/...w....26...Ei0LyJ5weE.HFUnsLm/O5EwkTE/1E7yz9QkSGcPqX5.LPAUnYIHg0E
................................CiONQX56oy1........B./..................y.2...wD
...Uz6....E1..../M.1/.....U21...l2....E3......U5V3mAsKuD/..........m/dkpXm1.Teee
y.E8QxMD12../2............................................U0.....y1...sD...../..
.z1...kDRy9YVFgfZyXJxvVlFeVKz4B.BJ22gvpDXgfwmivdhwX1bKeLMvQczcsiCxg5SXtDhVkaz7U7
YxvFFD6Wi0Bazi.xO4OC65uDU.....29..............sD.6....sD..G.....................
.............oAnAt1...sD....z...........................................w....k1.
.....83iyz1.......kz.wzzz1.U..6.P....U5...EB....m....c3....F....6/...I1.....SF52
...U.qFG9yzb2zzzRYoWzz7lz16.pc..zXCc..kvrEtMc7xD6ocyFE0ujz1..........2.28.kFrA0.
.Ub96aAIVz9.1se7Umvxz0........../EU0.wzzz1...........s/...................E.2c..
zzzz.............0...................2./8.kzzzD............8....................
/EU0.wzzz1...................................2CcN/UvNPcveeWCNq0.yRiibHJJUk1f..XR
SvBmx3CcN/UvNPcvQsLsUa3.ibhVi1bTV1OK.sSq4uCly3CcN/UvNPcvMwLsUa3.ibhVinqTV1OK.sSq
4uCkz3CcN/UvNPcv..EsUa3feeWCNqGQIJ36wk8EwyLsUa3f................................
E....2..F2E.....I....U....EEh3aSdtqNUAJRmN4...........................k/.MU/4.U.
..........UNaNaNaN4xz.........yDOaNaNaNa3.2.......c3.1......kC2E.......k9/2.....
................................................................................
........................}
{Titel: mb3dsurfsample}

Code: [Select]
# Mandelbulber settings file
# version 2.20
# only modified parameters
[main_parameters]
ambient_occlusion_enabled true;
ambient_occlusion_mode 1;
background_3_colors_enable false;
background_color_1 aa00 ff00 ff00;
camera -8.392917910413614e-16 -19.99999999999999 34.64101615137756;
camera_distance_to_target 40;
camera_rotation 0 -60.00000000000004 0;
camera_top 0 0.8660254037844389 0.4999999999999995;
check_for_bailout_2 false;
constant_DE_threshold true;
DE_factor 0.5;
DE_thresh 0.005;
delta_DE_function 1;
detail_level 1.666666666666667;
dont_add_c_constant_2 true;
flight_last_to_render 0;
fog_color_1 ff00 ff00 ff00;
fog_color_2 ff00 ff00 ff00;
fog_color_3 ff00 ff00 ff00;
formula_1 1022;
formula_2 186;
formula_3 1002;
formula_4 1059;
formula_stop_iteration_1 1;
formula_stop_iteration_4 10;
fractal_enable_4 false;
glow_enabled false;
hdr true;
hybrid_fractal_enable true;
image_height 480;
image_proportion 2;
image_width 640;
keyframe_last_to_render 0;
main_light_alpha 0;
main_light_beta 0;
mat1_coloring_speed 0.0625;
mat1_is_defined true;
mat1_specular_metallic 0.5;
mat1_specular_plastic_enable false;
mat1_surface_color_gradient 0 005500 1000 250b8d 2000 0b5e87 3000 0f89c2 4000 0b5e87 5000 c68876 6000 a51c64 7000 3b9fee 8000 d4ffd4 9000 aba53c;
N 2000;
raytraced_reflections true;
textured_background_map_type 2;
view_distance_max 240.3707503734783;
volumetric_light_DE_Factor 0.25;
[fractal_1]
transf_addition_constant_111 2.7 2.7 1;
transf_function_enabledx_false true;
transf_rotation -5.625 0 0;
transf_rotation2 0 39.375 0;
transf_rotation2_enabled_false true;
transf_scale_2 1.275;
[fractal_2]
boxfold_bulbpow2_z_factor 99;
transf_addition_constant_111 2.7 2.7 1;
transf_function_enabledD_false true;
transf_maxR2_1 2;
transf_offset_100 0.9 0 -0.6;
transf_rotation 0 0 55.5;
transf_rotation2 0 39.375 0;
transf_rotation2_enabled_false true;
transf_scale 0.5;
transf_scale_2 1.275;
transf_scaleB_1 6.2;
transf_start_iterations_A 7;
transf_start_iterations_B 8;
transf_start_iterations_C 44;
transf_start_iterations_D 8;
transf_start_iterations_S 384;
transf_stop_iterations_A 9;
transf_stop_iterations_B 9;
transf_stop_iterations_D 9;
[fractal_3]
transf_rotation -5.625 0 0;


xx
MB3D formulas

Started by HalTenny on Mandelbulb3d

10 Replies
1493 Views
Last post October 11, 2018, 03:23:23 PM
by Alef
xx
Original Point Color

Started by mclarekin on Color Snippets

0 Replies
113 Views
Last post March 21, 2019, 08:12:34 AM
by mclarekin
clip
New to MB3D

Started by Don Casteel on Noob's Corner

5 Replies
226 Views
Last post April 10, 2020, 09:31:23 AM
by Sabine62
xx
Is this possible? With Mb3D?

Started by i.AM.A.i on Noob's Corner

2 Replies
428 Views
Last post June 01, 2019, 03:41:13 AM
by mclarekin
clip
What MB3D Is.

Started by i.AM.A.i on Mandelbulb Maniacs

0 Replies
359 Views
Last post July 24, 2019, 02:51:26 AM
by i.AM.A.i