Logo by Fiery - Contribute your own Logo!


it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Visit us on facebook
Welcome, Guest. Please login or register. September 28, 2021, 07:23:37 AM

Login with username, password and session length

The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!

Pages: [1]   Go Down
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: How to code a formula for M3D  (Read 1871 times)
0 Members and 1 Guest are viewing this topic.
M Benesi
Fractal Schemer
Posts: 1075

« on: December 03, 2015, 07:32:53 PM »

Quote from: Hidden
Could you tell the person who wants to study and create new 3d fractals for mb3d, where to begin learning, theory and practice?
 You're probably in the right place (Fractal Forums), if you don't have access to courses on the applied mathematical arts and programming at your school.  

  I learned by experimentation, asking questions, looking at things others did.  As you gain experience / knowledge, the things that others are talking about (raytracing, vectors, mathematical concepts, etc.) will begin to make more sense to you.

  But I think you just want to know how to code a formula for M3D so that it works, right?

  Thargor6 released a beta version with a JIT compiler, so you'll be able to write formulas in Delphi (I think there are examples in one thread- you can use the forum's search function to find it), I think the JIT compiler might be included with the new release that is coming out before Christmas.   Using the JIT would probably be a LOT easier than hard coding in assembly!  However, it's 1/2 as fast (rendering times) for whatever reason.  Andreas might or might not have fixed that.  We can always hard code any really cool fractals later.

  Otherwise, you'll need to do something like the following:

  1)  Download OllyDbg  http://www.ollydbg.de/ unless you use something else to disassemble and reassemble code
  2)   If your disassembler needs an executable file to work on, open one, if you don't have to open a file, don't bother doing it.  Open up an executable file in OllyDbg to use as a scratch pad (don't save whatever file you use as a scratch pad when you're done with it!  You don't want to corrupt the file!).  DarkBeam likes to use twunk32.exe (a file in the windows/system directory, I believe).  I assembled a "hello world.exe" in some compiler and use that.
  3)   open a simple formula (like _abs_3d.m3f) from the M3D formula's directory in Notepad or equivalent text editor
  4)   highlight and <Ctrl-c> copy the CODE portion of the formula
  5)   Highlight a bunch of zeros in OllyDbg, then binary paste (right click menu) the code of the formula
  6)  I like to paste the disassembled code into notepad to work on...
  7)  Match the math in the formula's description to the assembly code.  You can Google assembly commands.  Art of assembly is a good reference for 8086 assembly...
  cool  Change the assembly code and math to something else that makes sense (you can't write random characters... wink  

.Version = 2
.DEoption = -1
.Double Scale = 1.0    
.Double fixX = 0.0
.Double fixY = 0.0
.Double fixZ = 0.0
[C0DE]     // O replaced with 0 to keep it from.. mehh... ;)


x' = abs(x)
y' = abs(y)
z' = abs(z)

(x',y',z') *= Scale
(x',y',z') += fixVec

Disable Analytical DE to see the effect correctly.

00401033     55             PUSH EBP
00401034     8BEC           MOV EBP,ESP  
00401036     56             PUSH ESI
00401037     53             PUSH EBX
00401038     8B75 08        MOV ESI,DWORD PTR SS:[EBP+8]  
0040103B     8BD8           MOV EBX,EAX
0040103D     8B76 30        MOV ESI,DWORD PTR DS:[ESI+30]  
//before here is initialization- loading parameters, saving them for later,etc.

//the following does the abs (absolute value |-1| = 1, |1|=1) , scaling (*Scale), and translation (+fixVec)

00401040     DD03           FLD QWORD PTR DS:[EBX]   //  EBX is generally the x variable
00401042     D9E1           FABS
00401044     DC4E F0        FMUL QWORD PTR DS:[ESI-10]    // this particular formula
// uses the ESI register for user defined variables, some use EDI, etc.
// Variables start at -10, and for doubles (integers are shifted by 4 bytes), the next one will be
// -18, then the next -20, the -28....    10 is hexadecimal, which means it is actual 16,
// 18h=24d, 20h = 32d... etc.  

//  user defined [CONSTANTS] are also saved in ESI (or EDI, or wherever), but start at
//  ESI, then shift by the variable type size (so if the first one [ESI] is a double, the next will
// be 8 away  [ESI+8], if [ESI+8] is an integer (takes up 4 bytes), the next will be at [ESI+C]  
// (Ch=12d)

//  I'll have to find it, but there is a reference that lets you know offsets of various data in
// M3D... I'll post it in the thread I make.  which is this thread if you're reading this.  
// List is in next code block below.

00401047     DC46 E8        FADD QWORD PTR DS:[ESI-18]
0040104A     DD1B           FSTP QWORD PTR DS:[EBX]
0040104C     DD02           FLD QWORD PTR DS:[EDX]     //EDX is generally the y variable

// if you want to remove one absolute value from the code, delete a "D9E1" from the [c0de] block:
0040104E     D9E1           FABS    
00401050     DC4E F0        FMUL QWORD PTR DS:[ESI-10]
00401053     DC46 E0        FADD QWORD PTR DS:[ESI-20]
00401056     DD1A           FSTP QWORD PTR DS:[EDX]
00401058     DD01           FLD QWORD PTR DS:[ECX]    //  ECX is generally the z variable
0040105A     D9E1           FABS
0040105C     DC4E F0        FMUL QWORD PTR DS:[ESI-10]
0040105F     DC46 D8        FADD QWORD PTR DS:[ESI-28]
00401062     DD19           FSTP QWORD PTR DS:[ECX]

//after this, we restore the parameters we saved during initialization

00401064     8BC3           MOV EAX,EBX
00401066     5B             POP EBX
00401067     5E             POP ESI
00401068     5D             POP EBP
00401069     C2 0800        RETN 8

  The offsets below are in decimal, not hex!  -48d = -30h     You'll

   J4:         Double;     //-56   4d extension         FastMove(dJUx, It3Dex.J1, 168);
    Rold:       Double;     //-48   used by m3d, equals Rout
    RStopD:     Double;     //-40   used by m3d for sse2, not always a valid value in here, in IFS: absDEstop
    x:          Double;     //-32   vector to iterate   -120 in dIFS esi
    y:          Double;     //-24
    z:          Double;     //-16
    w:          Double;     //-8
    C1, C2, C3: Double;     //0     input start values before 4d rotation, C4 is 0.  Do Not Change!
    J1, J2, J3: Double;     //+24   julia start values or the pixelpos, these are the constants to add
    PVar:       Pointer;    //+48   pointer to the user input values (decreasing offset, -8 is always val 0.5)
//+ constants (incr. offset, 0 and above)
    SmoothItD:  Single;     //+52
    Rout:       Double;     //+56   the square of the current vector length, calced in m3d, in dIFS: rel DEout
    ItResultI:  Integer;    //+64   integer iteration count, increased by loop function in m3d
    maxIt:      Integer;    //+68
    RStop:      Single;     //+72   for dIFS: bool for insiderendering -> DEcomb with usual bulb needs RStop!!

« Last Edit: August 09, 2016, 11:55:26 PM by M Benesi » Logged

Global Moderator
Fractal Senior
Posts: 2512

Fragments of the fractal -like the tip of it

« Reply #1 on: December 03, 2015, 11:09:02 PM »

Ok Matthew moved it in tutorials section smiley
There are other threads here discussing this matter so people can read all smiley

No sweat, guardian of wisdom!
M Benesi
Fractal Schemer
Posts: 1075

« Reply #2 on: December 04, 2015, 05:29:35 AM »

k, thanks.  Edit the post if you feel like adding to it or fixing anything. 

Posts: 48

« Reply #3 on: December 04, 2015, 09:06:56 AM »


I thought you could write the formula as in Fragmentarium as a text file and save it as .mb3 so that MB3D could render it?
Is it possible to write the formula in Codelite and then use it and .mb3 formula?
Global Moderator
Fractal Senior
Posts: 2512

Fragments of the fractal -like the tip of it

« Reply #4 on: December 04, 2015, 10:57:01 AM »

You can code it in Pascal using the JIT experimental build.

No sweat, guardian of wisdom!
Pages: [1]   Go Down
Jump to:  

Related Topics
Subject Started by Replies Views Last post
some code Mandelbulb 3d Jesse 7 2256 Last post August 15, 2011, 10:27:15 PM
by Jesse
@jesse - save formula as new formula ?! feature request cKleinhuis 0 1428 Last post October 10, 2012, 05:43:14 PM
by cKleinhuis
How to program / compile a formula e.g. the code in Mandelbulb3D? Programming tyebillion 1 1371 Last post August 28, 2013, 05:44:28 PM
by cKleinhuis
Help ! what is this code ? Programming ker2x 2 247 Last post April 16, 2014, 08:50:29 PM
by ker2x
Code 9385dj8hg94j Mandelbulb3D Gallery FractalJam 0 352 Last post September 08, 2014, 05:21:16 PM
by FractalJam

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.115 seconds with 29 queries. (Pretty URLs adds 0.005s, 2q)