Logo by Cyclops - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

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 the official fractalforums.com Youtube Channel
 
*
Welcome, Guest. Please login or register. February 21, 2019, 05:58:11 PM


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
  Print  
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: Crazy ... working code; Simplex3D noise escapetime.  (Read 821 times)
Description: Now it works see latest posts
0 Members and 1 Guest are viewing this topic.
DarkBeam
Global Moderator
Fractal Senior
******
Posts: 2512


Fragments of the fractal -like the tip of it


« on: December 01, 2016, 06:55:41 PM »

I tried to apply Jessie & Knighty's old suggestion to use gcc, after years, to get the monster to work; generate Perlin noise

Simplex looks better than Perlin so... smiley

Code:
#include <math.h>

__CRT_INLINE void Rho(double* u, double* v, int* op);
void __attribute__((fastcall)) Formula(
             double* x,      // [eax]
             double* y,      // [edx]
             double* arg,    // [ebp+8], points to TIteration3Dext.C1
             void* dummy     // so we end w/ ret 8 as delphi expects
             );

          
__attribute__((packed)) struct TIteration3Dext {
double Cw,Rold,RStopD,x,y,z,w; // use with neg indizes before C1. w is also used for 3d ifs and abox analytic DE
double Px, Py, Pz;             //      actual position, never change these!  Can be used as input.
double Cx, Cy, Cz;             //+24   these are the constants for adding. Pxyz or the julia seed.  Cw is @-56 (begin of struct)
void*  PVar;                   //+48   the actual formulas adress of constants and vars, constants at offset 0 increasing, user vars below -8
float  SmoothItD;              //+52
double Rout;                   //+56   the square of the vector length, can be used as input
int    ItResultI;              //+64
int    maxIt;                  //+68
float  RStop;                  //+72
int    nHybrid[6];             //+76   all formulas iteration counts or single weights in interpol-hybrid
void*  fHPVar[6];              //+100  all formulas pointer to constants+vars, PVars-8=0.5, use PVar for the actual formula
void*  fHybrid[6];             //+124  the formulas adresses
int    CalcSIT;                //+148
int    DoJulia;                //+152
float  LNRStop;                //+156
int    DEoption;               //+160
float  fHln[6];                //+164  for SmoothIts
int    iRepeatFrom;            //+188
double OTrap;                  //+192
double VaryScale;              //+200  to use in vary by its
int    bFirstIt;               //+208  used also as iteration count, is set to 0 on it-start
int    bTmp;                   //+212  tmpBuf, free of use.
double Dfree1;                 //+216
double Dfree2;                 //+224
double Deriv1;                 //+232  for 4D first deriv or as full derivs
double Deriv2;                 //+240
double Deriv3;                 //+248
float  SMatrix4[4][4];         //+256  for 4d rotation, used like most other values only by the programs iteration loop procedure
};

__CRT_INLINE double __cdecl Hypot(double x,double y) ;
__CRT_INLINE double __cdecl length2(double x,double y,double z);
__CRT_INLINE double __cdecl length(double x,double y,double z);
__CRT_INLINE double __cdecl recip (long double _x);
__CRT_INLINE double __cdecl step (double edge, double _x);
__CRT_INLINE int __cdecl istep (double edge, double _x);
__CRT_INLINE int __cdecl storeint (double _x);
__CRT_INLINE int floori(double x);
__CRT_INLINE double __cdecl fracz (double _x);
__CRT_INLINE double __cdecl max (double _a, double _b);
__CRT_INLINE double __cdecl min (double _a, double _b);
__CRT_INLINE int wang_hash(int seed);

__CRT_INLINE double __cdecl loadz (void) // uses constants, assembly required :o)
{
  double res;
  __asm__ ("fldz": "=t" (res));
  return res;
}

__CRT_INLINE double __cdecl load1 (void) // uses constants, assembly required :o)
{
  double res;
  __asm__ ("fld1": "=t" (res));
  return res;
}

__CRT_INLINE double __cdecl Hypot(double x,double y) { return sqrt(x*x+y*y); }

__CRT_INLINE double __cdecl length2(double x,double y,double z) { return (x*x+y*y+z*z); }

__CRT_INLINE double __cdecl length(double x,double y,double z) { return sqrt(length2(x,y,z)); }

__CRT_INLINE double __cdecl recip (long double _x) // uses constants, assembly required :o)
{
  double res;
  __asm__ ("fld1
"
   "fdivp": "=t" (res) : "0" (_x));
  return res;
}

__CRT_INLINE double __cdecl step (double edge, double _x) // uses constants, assembly required :o)
{
  double res;
  double xs = _x-edge;
  __asm__ ("ftst
"
   "fstsw %%ax
"
        "shr %%ah
"
        "jb _nb%=
"
        "fldz
"
        "jmp _end%=
"
        "_nb%=:
"
        "fld1
"
        "_end%=:
"
        "fstp %%st(1)"
        :"=t"(res) // out
        :"0"(xs)   // in
        :"%eax"    // modify EAX (clobbered)
        );
  return res;
}

__CRT_INLINE int __cdecl istep (double edge, double _x)
{
  int res;
  double xs = _x-edge;
  __asm__ ("fldl %1
"
        "ftst
"
   "fstsw %%ax
"
        "shr %%ah
"
        "jna _inb%=
"
        "movl $1,%0
"
        "jmp _iend%=
" // http://stackoverflow.com/questions/3898435/labels-in-gcc-inline-assembly yayz
        "_inb%=:
"
        "movl $0,%0
"
        "_iend%=:
"
        "fstp %%st"
        :"=r"(res) // out REGISTER
        :"m"(xs)   // in MEMORY
        :"%eax"    // modify EAX (clobbered)
        );
  return res;
}

__CRT_INLINE int __cdecl storeint (double _x)
{
  int res;
  __asm__ ("fldl %1
"
        "fistpl %0
"
        :"=m"(res) // out MEMORY
        :"m"(_x)   // in MEMORY
        // (nothing clobbered) :P
        );
  return res;
}

__CRT_INLINE int floori(double x) { // emulates perfectly
    int xi = storeint(x);
    if ( x<(double)xi) xi--;
    return xi;
}

__CRT_INLINE double __cdecl fmod1(double _x, double _half) // emulates perfectly
{
  double xnr = _x-((_x>loadz() )?_half:-_half);
  return _x- storeint(xnr);
}

__CRT_INLINE double __cdecl fmodB(double _x, double _half, double B) // emulates perfectly
{
  return fmod1(_x/B,_half)*B;
}

__CRT_INLINE double __cdecl max (double _a, double _b)
{
  return (_a>_b)?_a:_b;
}

__CRT_INLINE double __cdecl min (double _a, double _b)
{
  return (_a<_b)?_a:_b;
}

__CRT_INLINE int wang_hash(int seed)
{
    seed = (seed ^ 61) ^ (seed >> 16);
    seed = seed*9 - 1; // a liiiittle changed
    seed = seed ^ (seed >> 4);
    // seed = seed * 668265261;
    seed = seed * 159833; // I think it overflows less, still a large prime
    seed = seed ^ (seed >> 15);
    return seed;
}

void random3(int r0, int u0, int v0, double* r, double* u, double* v,
 double rf, double n_05, double n_512, double n_0125)
{
    // why I use wang_hash instead of sine? better randomness
unsigned int rez = wang_hash(127 - 129*r0 + 285*u0 + 513*v0);
// copypasta of original; but the magic constants can be safely changed... well except n_05
//double j = rf*((double)(rez & 0x3FFFFFFF)); // 30 bit
double j = rf*((double)(rez & 0xFFFFF)); // even less, to avoid weird things
// ??? why thee fmod()? ridiculously slow but that's it
*v = fmod1(n_512*j,-n_05)+n_05;
j *= n_0125;
*r = fmod1(n_512*j,-n_05)+n_05;
j *= n_0125;
*u = fmod1(n_512*j,-n_05)+n_05;
return;
}

// fastcall is not quite delphi fastcall.
// first two args are ok, third is in ecx in delphi, on stack here.
void __attribute__((fastcall)) Formula(
             double* Xx,      // [eax] = x
             double* Yy,      // [edx] = y
             double* arg,    // [ebp+8], points to TIteration3Dext.C1
             void* dummy     // so we end w/ ret 8 as delphi expects
             ) {
  // Compute ptr to proper start of TIteration3Dext struct.
  struct TIteration3Dext* cfg = (struct TIteration3Dext*)(arg-7);
  double* Cns = (double*)(cfg->PVar);
  double* UserV = (double*)(cfg->PVar-0X10);
//  FAILED attempt to replicate Simplex Noise by Nikita Miropolskiy
//  <www.shadertoy.com/view/XsX3zB>
//  too bad I absolutely do NOT understand this code and it is really sensible
// to minimal errors (like, don't try to replace a floor() with a roundint() ).
// for an unintelligible reason this code compiles but it gives a discontinue DE
// I hope someone is able to fix.
  // Cns[0] = const float F3 =  0.3333333;
  // Cns[1] = const float G3 =  0.1666667;
  // Cns[2] = const float (3*G3-1.) =  -.5;
  // Cns[3] = const float =  +.6;
  // Cns[4] = const float =  1./(0x3FFFFFFF) = 9.313225754828403e-10
  // Cns[5] = const float =  +512.;
  // Cns[6] = const float =  +0.125;
  // Cns[7] = const float =  +0.125;
  // 1st part, it should be easy. I am using ints for ints though :P
  // so I can use wang hash instead of a dumb sin()
  // -------------------------------------------------------------------
  
  double x[3], x1[3], x2[3], x3[3], w[4], d[4];
  double tx,ty,tz, Zero = 0.;
  int s[3], e[3], i1[3], i2[3];
  // vec3 s = floor(p + dot(p, vec3(F3)));
  // skewed
  x1[0] = (cfg->x+ cfg->y+ cfg->z)*Cns[0];
  s[0] = floori(cfg->x + x1[0]);
  s[1] = floori(cfg->y + x1[0]);
  s[2] = floori(cfg->z + x1[0]);
  // vec3 x = p - s + dot(s, vec3(G3));
  // unskewed
  x1[0] = ((double)(s[0]+ s[1]+ s[2]))*Cns[1];
  x[0] = cfg->x - (double)s[0] + x1[0];
  x[1] = cfg->y - (double)s[1] + x1[0];
  x[2] = cfg->z - (double)s[2] + x1[0];
  // calculate i1 and i2
  // vec3 e = step(vec3(0.0), x - x.yzx);
  // but step(0.,a-b) = step(b,a) so:
  e[0] = istep(x[1],x[0]);
  e[1] = istep(x[2],x[1]);
  e[2] = istep(x[0],x[2]);
  // vec3 i1 = e*(1.0 - e.zxy);
  i1[0] = e[0] * (1-e[2]);
  i1[1] = e[1] * (1-e[0]);
  i1[2] = e[2] * (1-e[1]);
  // vec3 i2 = 1.0 - e.zxy*(1.0 - e);
  i2[0] = 1 - e[2] * (1-e[0]);
  i2[1] = 1 - e[0] * (1-e[1]);
  i2[2] = 1 - e[1] * (1-e[2]);
  // vec3 x1 = x - i1 + G3;
  x1[0] = x[0] - (double)i1[0] + Cns[1];
  x1[1] = x[1] - (double)i1[1] + Cns[1];
  x1[2] = x[2] - (double)i1[2] + Cns[1];
  // vec3 x2 = x - i2 + 2.0*G3; 2.0*G3 =  F3 :
  x2[0] = x[0] - (double)i2[0] + Cns[0];
  x2[1] = x[1] - (double)i2[1] + Cns[0];
  x2[2] = x[2] - (double)i2[2] + Cns[0];
  // vec3 x3 = x - 1.0 + 3.0*G3 = -.5;
  x3[0] = x[0] + Cns[2];
  x3[1] = x[1] + Cns[2];
  x3[2] = x[2] + Cns[2];
  // calculate surflet weights
  // w.x = dot(x, x);
  w[0] = x[0]*x[0]+x[1]*x[1]+x[2]*x[2];
  // w.y = dot(x1, x1);
  w[1] = x1[0]*x1[0]+x1[1]*x1[1]+x1[2]*x1[2];
  // w.z = dot(x2, x2);
  w[2] = x2[0]*x2[0]+x2[1]*x2[1]+x2[2]*x2[2];
  // w.w = dot(x3, x3);
  w[3] = x3[0]*x3[0]+x3[1]*x3[1]+x3[2]*x3[2];
  // the last part really gave me nightmares. nasty stuff.
  // Had to change something to avoid crashing of MB for unk reasons
  // Regrouped, and avoid to do all those calcs for multiplying by 0.
  // But it does not work well, even if does not crash. let's see
  // -------------------------------------------------------------------
  // w fades from 0.6 at the center of the surflet to 0.0 at the margin
  // w = max(0.6 - w, 0.0);
  // Do w^4
  w[0] =Cns[3]-w[0];
  if (w[0] > Zero ) {
     w[0] = w[0]*w[0]; w[0] = w[0]*w[0];
     // d.x = dot(random3(s), x);
     random3(s[0], s[1], s[2], // input = s
                &tx ,&ty, &tz, // output
                Cns[4], Cns[2], Cns[5], Cns[6] ); // just constants
     d[0] = w[0]*(tx*x[0] + ty*x[1] + tz*x[2]);
     //d[0] *= w[0];   // multiply d by w^4
  } else d[0] = Zero;
  w[1] = Cns[3]-w[1];
  if (w[1] > Zero ) {
     w[1] = w[1]*w[1]; w[1] = w[1]*w[1];
     // d.x = dot(random3(s), x);
     random3(s[0]+i1[0], s[1]+i1[1], s[2]+i1[2],
                &tx ,&ty, &tz,
                Cns[4], Cns[2], Cns[5], Cns[6] );
     d[1] = w[1]*(tx*x1[0] + ty*x1[1] + tz*x1[2]);
     //d[0] *= w[0];   // multiply d by w^4
  } else d[1] =Zero;
  w[2] = Cns[3]-w[2];
  if (w[2] > Zero ) {
     w[2] = w[2]*w[2]; w[2] = w[2]*w[2];
     // d.x = dot(random3(s), x);
     random3(s[0]+i2[0], s[1]+i2[1], s[2]+i2[2],
                &tx ,&ty, &tz,
                Cns[4], Cns[2], Cns[5], Cns[6] );
     d[2] = w[2]*(tx*x2[0] + ty*x2[1] + tz*x2[2]);
     //d[0] *= w[0];   // multiply d by w^4
  } else d[2] = Zero;
  w[3] = Cns[3]-w[3];
  if (w[3] > Zero ) {
     w[3] = w[3]*w[3]; w[3] = w[3]*w[3];
     // d.x = dot(random3(s), x);
     random3(s[0]+1, s[1]+1, s[2]+1,
                &tx ,&ty, &tz,
                Cns[4], Cns[2], Cns[5], Cns[6] );
     d[3] = w[3]*(tx*x3[0] + ty*x3[1] + tz*x3[2]);
     //d[0] *= w[0];   // multiply d by w^4
  } else d[3] = Zero;
  //tx = (d[0]+d[1]+d[2])*UserV[0];
  // YOU MUST! sum all four components or you get discontinuities
  tx = (d[0]+d[1]+d[2]+d[3])*UserV[0];
  cfg->x += tx;
  cfg->y += tx;
  cfg->z += tx;
  // cfg->x += Cns[4]*rt[0];
  // cfg->y += rt[0];
  // cfg->z += rt[0];
}
// orig code:

/*
uint wang_hash(uint seed)
{
    seed = (seed ^ 61) ^ (seed >> 16);
    seed *= 9;
    seed = seed ^ (seed >> 4);
    seed *= 668265261;
    seed = seed ^ (seed >> 15);
    return seed;
}

//  <www.shadertoy.com/view/XsX3zB>
//  by Nikita Miropolskiy

// discontinuous pseudorandom uniformly distributed in [-0.5, +0.5]^3
vec3 random3(vec3 c) {
float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0)));
vec3 r;
r.z = fract(512.0*j);
j *= .125;
r.x = fract(512.0*j);
j *= .125;
r.y = fract(512.0*j);
return r-0.5;
}

// skew constants for 3d simplex functions
const float F3 =  0.3333333;
const float G3 =  0.1666667;

// 3d simplex noise
float simplex3d(vec3 p) {
// 1. find current tetrahedron T and it's four vertices
// s, s+i1, s+i2, s+1.0 - absolute skewed (integer) coordinates of T vertices
// x, x1, x2, x3 - unskewed coordinates of p relative to each of T vertices

// calculate s and x
vec3 s = floor(p + dot(p, vec3(F3)));
vec3 x = p - s + dot(s, vec3(G3));

// calculate i1 and i2
vec3 e = step(x.yzx, (x));
vec3 i1 = e*(1.0 - e.zxy);
vec3 i2 = 1.0 - e.zxy*(1.0 - e);

// x1, x2, x3
vec3 x1 = x - i1 + G3;
vec3 x2 = x - i2 + F3;
vec3 x3 = x - .5;

// 2. find four surflets and store them in d
vec4 w, d;

// calculate surflet weights
w.x = dot(x, x);
w.y = dot(x1, x1);
w.z = dot(x2, x2);
w.w = dot(x3, x3);

// w fades from 0.6 at the center of the surflet to 0.0 at the margin
w = max(0.6 - w, 0.0);

// calculate surflet components
d.x = dot(random3(s), x);
d.y = dot(random3(s + i1), x1);
d.z = dot(random3(s + i2), x2);
d.w = dot(random3(s + 1.0), x3);

// multiply d by w^4
w *= w;
w *= w;
d *= w;

// 3. return the sum of the four surflets
return dot(d, vec4(52.0));
}

float simplex3d_fractal(vec3 m) {
    return   0.5333333*simplex3d(m)
+0.2666667*simplex3d(2.0*m)
+0.1333333*simplex3d(4.0*m)
+0.0666667*simplex3d(8.0*m);
}

*/

After you compile, an abomination pops out. This:

Code:
[OPTIONS]
.Version = 2
.DEoption = -1
.Double Intensity = 1
[CONSTANTS]
Double = 0.33333333333333333333333333333333
Double = 0.16666666666666666666666666666667
Double = -.5
Double = .6
Double = 1.0e-4
Double = 15.
Double = 0.25
Double = 10.
[CODE]
5589E557565381EC1C0300008B750883EE388B7E68DD4620DD4618D9C989BDC0
FDFFFF8B9DC0FDFFFF83EF10DD9DF0FCFFFFD9C0DC85F0FCFFFFD9C9DD9DF8FC
FFFFDD4628DD85F8FCFFFFD9CA89B5C4FDFFFFD8C1D9C9DD9D08FDFFFFDC0B89
BDBCFDFFFFDCC1DD55A8D9C9DD95D8FEFFFFDD85D8FEFFFFDB9DE4FEFFFF8B8D
E4FEFFFF51DB0424D9C9DED9DFE0DD85F0FCFFFF9E83D900898DECFCFFFFD8C1
898D18FFFFFFDD95C8FEFFFFDD85C8FEFFFFDB9DD4FEFFFF8B95D4FEFFFF8914
24DB0424D9C983C404DED9DFE0DD8508FDFFFF9E83DA008995E8FCFFFFDEC189
951CFFFFFFDD95B8FEFFFFDD85B8FEFFFFDB9DC4FEFFFF8B95C4FEFFFF8995B8
FDFFFFDB85B8FDFFFFD8D1DFE0DDD99E760FDDD84A8995B8FDFFFFDB85B8FDFF
FFDB85ECFCFFFF8B95E8FCFFFF8B85ECFCFFFFDD85F8FCFFFF8B9DB8FDFFFF01
D0DD85F0FCFFFFD9C901D88B8DC0FDFFFF50DEE2DB85E8FCFFFFDB0424DC4908
899D20FFFFFFDD8508FDFFFFDEE5D9CADEE1D9C9DD55A8DCC2DCC1DEC3D9C1D8
E1D9CADD55C8D9C1DD55D0D9CBDD9DB0FEFFFFD9C2D8E4D9CCDD85B0FEFFFFD9
E49BDFE0D0EC7607BB01000000EB05BB00000000DDD8DD55D8D9CC899D08FFFF
FFDD9DA8FEFFFFD9C3D8E1DD85A8FEFFFFD9E49BDFE0D0EC7607B901000000EB
05B900000000DDD8898D0CFFFFFFDD9DA0FEFFFFDD85A0FEFFFFD9E49BDFE0D0
EC7607BA01000000EB05BA00000000DDD8899510FFFFFFB80100000089C729DF
89C629D689BDE4FCFFFF0FAFF989B5B4FDFFFF0FAFF389BDACFDFFFF89BDFCFE
FFFF89C729CF89B5B0FDFFFF0FAFDF89B5F8FEFFFF89D60FAFF789C729DF89B5
A8FDFFFF89B500FFFFFF8BB5E4FCFFFF89BDECFEFFFF8B9DB4FDFFFFDB85B0FD
FFFF0FAFD689C60FAFCB29D68B95C0FDFFFF89B5A4FDFFFFD8E989B5E8FEFFFF
89C629CEDC420889B5F0FEFFFFDD55A8DD9D98FDFFFFDB85ACFDFFFFD8EBDC42
08DD55B0DD9D90FDFFFFDB85A8FDFFFFD8ECDC4208893C24DD55B8DD9D88FDFF
FFDB0424D8EBDC02893424DD5590DD9D80FDFFFFDB042483C404D8ECDC02DD55
98DD9D78FDFFFFD9C0DC4210DD9568FFFFFFD9CADC4210D9CADD9D70FDFFFFD9
C3D9CADD9568FDFFFFDD9D70FFFFFFD9C0D8C9D9CADC4210DD9560FDFFFFDD9D
78FFFFFFD9C2D8CBDEC2D9C3D8CCDEC2DD8598FDFFFFD8C8D9CADD9548FFFFFF
D9CADD9D58FDFFFFDD8590FDFFFFD8C8DC8558FDFFFFDD9D58FDFFFFDD8588FD
FFFFD8C8DC8558FDFFFFDD9550FFFFFFDD9D58FDFFFFDD4588DD9500FDFFFFD8
C8DD9D50FDFFFFDD8580FDFFFFD8C8DC8550FDFFFFDD9D50FDFFFFDD8578FDFF
FFD8C8DC8550FDFFFFDD9558FFFFFFDD9D50FDFFFFDD8570FDFFFFD8C8DD9D48
FDFFFFDD8568FDFFFFD8C8DC8548FDFFFFDD9D48FDFFFFDD8560FDFFFFD8C8DC
8548FDFFFFDD9560FFFFFFDD9D48FDFFFFDD4218DEE2D9EED8DADFE09E0F838D
040000D9C9D8C88B8DC0FDFFFF8B85ECFCFFFF8B95ECFCFFFF8B9DB8FDFFFFC1
E007D8C801D0DD9548FFFFFFDD9D40FDFFFFDD4110DD4128D9C9DD9D38FDFFFF
DD4130D9C9698DE8FCFFFF1D010000DD9530FDFFFFDD8538FDFFFFD9CADD9D28
FDFFFFD9EED9CAD9E029C18B85B8FDFFFFC1E00901D88D54017F89D1C1F91031
D183F13D31D28D44C9FF5289C3C1FB0431D869D85970020089D9C1F90F31CB81
E3FFFF0F00538B8DC0FDFFFFDF2C2483C408DC4920DCCAD9C2D9CCD8DBDFE0D9
CB9ED8C10F8206080000DDD9DD9D78FEFFFFDD8578FEFFFFDB9D84FEFFFFDB85
84FEFFFFDD8528FDFFFFDD8538FDFFFFD9C9DECCD9E0D9CADEE1D9EED9C9DC85
38FDFFFFDD9D88FEFFFFDD8530FDFFFFD8CBD9C0D9CAD8D9DFE0D9C99ED8C20F
83C2070000DDD8D9C0DEE2D9C9DD9D68FEFFFFDD8568FEFFFFDB9D74FEFFFFDB
8574FEFFFFDD8538FDFFFFD9E0D9CADEE1D9EED9C9DC8538FDFFFFDD9D98FEFF
FFDD8528FDFFFFDECBD9CADC8D30FDFFFFD9C0D8C2D9CBD8D9DFE09E0F835E07
0000DDDAD9C1DEE1D9C9D9C9DD9D58FEFFFFDD8558FEFFFFDB9D64FEFFFFDB85
64FEFFFFD9CA8B8DC0FDFFFFDC8D98FEFFFFD9CCDC8D88FEFFFFD9C9DEE2DD85
58FDFFFFD9CADC8538FDFFFFDCCBDD9D90FEFFFFD9EED9CCDEC3DEC2D9C9DC8D
40FDFFFFDD9528FFFFFFD9C9DC6918D9C9DD9D40FDFFFFD8D1DFE0DDD99E0F86
C8020000D9C08B95B0FDFFFFDEC98B8DECFCFFFF8B9DACFDFFFF8B85A8FDFFFF
01D18B95E8FCFFFFD8C801DA8B9DB8FDFFFFDD9550FFFFFF01C38B85C0FDFFFF
DD4030DD4010DD4028D9CA89C8C1E007DD9D20FDFFFF01C8D9EE69CA1D010000
D9C2D9C2D9E029C189D8C1E00901D88D54017F89D3C1FB1031D383F33D31D28D
44DBFF5289C1C1F90431C869C85970020089CBC1FB0F31D981E1FFFF0F00518B
9DC0FDFFFFDF2C2483C408DC4B20DCCAD9C2D9CCD8DBDFE0D9CB9ED8C10F82ED
050000DDD9DD9D48FEFFFFD9C2DD8548FEFFFFDB9D54FEFFFFDB8554FEFFFFDD
8520FDFFFFD9CAD9E0D9CADECCDEEAD9EED9CAD8C4DD9D88FEFFFFD9C4D8CBD8
D2DFE0DDDAD9C19ED8C10F86F7050000DDD8D9C1DEE1DD9D38FEFFFFDD8538FE
FFFFDB9D44FEFFFFDB8544FEFFFFD9C3D9E0D9CADEE1D9EED9C9D8C4DD9D98FE
FFFFDD8520FDFFFFDECBD9CADECCD9C9D8DBDFE0D9C29ED8C10F83A1050000DD
D8D9C2DEE1DD9D28FEFFFFDD8528FEFFFFDB9D34FEFFFFDB8534FEFFFF8B95C0
FDFFFFDEEADD8598FDFFFFDC8D98FEFFFFD9CADEC1DD9D90FEFFFFDD8590FDFF
FFDC8D90FEFFFFDEC1DD9D98FDFFFFDD8588FDFFFFDC8D88FEFFFFDD8598FDFF
FFDEC1DD8550FDFFFFD9CADEC9D9EED9C9DD9D30FFFFFFD9C9DC6A18D8D1DFE0
DDD99E0F8719010000DD9D58FFFFFF8B95C0FDFFFF31FF89BD38FFFFFF31DBDD
8548FDFFFFD9EED9C9899D3CFFFFFFDC6A18D8D1DFE0DDD99E0F87BC020000DD
9D60FFFFFF31F631C989B540FFFFFF898D44FFFFFFDD8530FFFFFF8B9DBCFDFF
FF8B95C4FDFFFFDC8528FFFFFFDD85F8FCFFFFD9C9DC8538FFFFFFDC8540FFFF
FFDC0BDCC1D9C9DD5A18DD85F0FCFFFFD8C1D9C9DC8508FDFFFFD9C9DD5A20DD
5A2881C41C0300005B5E5F5DC2080090DDD8DDD9DDD9DD9D48FFFFFF8B8DC0FD
FFFF31D2899528FFFFFF31DBDD8558FDFFFFD9EED9C9899D2CFFFFFFDC6918D8
D1DFE0DDD99E0F8738FDFFFFDD9D50FFFFFF8B95C0FDFFFF31DB899D30FFFFFF
31C9DD8550FDFFFFD9EED9C9898D34FFFFFFDC6A18D8D1DFE0DDD99E0F86E7FE
FFFFD9C08B85A4FDFFFFDEC98B8DECFCFFFF8B95E8FCFFFF8B9DB8FDFFFF01C1
01FAD8C889CF01F3C1E70701CF69CA1D0100008BB5C0FDFFFF89D8C1E00901D8
DD9558FFFFFF29F9DD4630DD4610DD4628D9CA8D74017F89F7DD9D18FDFFFF31
C9D9EE51C1FF1031F783F73DD9C28D44FFFF89C28BBDC0FDFFFFD9C2D9E0C1FA
0431D069F05970020089F3C1FB0F31DE81E6FFFF0F0056DF2C2483C408DC4F20
DCCAD9C2D9CCD8DBDFE0D9CB9ED8C10F820B030000DDD9DD9D18FEFFFFD9C2DD
8518FEFFFFDB9D24FEFFFFDB8524FEFFFFDD8518FDFFFFD9CAD9E0D9CADECCDE
EAD9EED9CAD8C4DD9D88FEFFFFD9C4D8CBD8D2DFE0DDDAD9C19ED8C10F86F502
0000DDD8D9C1DEE1DD9D08FEFFFFDD8508FEFFFFDB9D14FEFFFFDB8514FEFFFF
D9C3D9E0D9CADEE1D9EED9C9D8C4DD9D98FEFFFFDD8518FDFFFFDECBD9CADECC
D9C9D8DBDFE0D9C29ED8C10F839F020000DDD8D9C2DEE1DD9DF8FDFFFFDD85F8
FDFFFFDB9D04FEFFFFDB8504FEFFFF8B95C0FDFFFFDEEADD8500FDFFFFDC8D98
FEFFFFD9CADEC1DD9D90FEFFFFDD8580FDFFFFDC8D90FEFFFFDEC1DD9D00FDFF
FFDD8578FDFFFFDC8D88FEFFFFDD8500FDFFFFDEC1DD8548FDFFFFD9CADEC9D9
EED9C9DD9D38FFFFFFD9C9DC6A18D8D1DFE0DDD99E0F8644FDFFFFD9C08B95E8
FCFFFFDEC98B9DECFCFFFF8B85C0FDFFFF428BBDECFCFFFFC1E3078B8DB8FDFF
FFD8C88DB43B8100000069DA1D010000DD9560FFFFFF29F3DD4030DD4010DD40
288B85B8FDFFFFD9C1D9E0D9CBC1E0098DBC0801020000DD9D10FDFFFFD9EE8D
743B7F31DB89F153C1F91031F183F13DD9C18D44C9FF89C28B8DC0FDFFFFC1FA
0431D069F05970020089F7C1FF0F31FE81E6FFFF0F0056DF2C2483C408DC4920
DCC9D9C1D9CBD8DADFE0D9CA9ED8C50F820B010000DDDDD9CCDD9DE8FDFFFFD9
C2DD85E8FDFFFFDB9DF4FDFFFFDB85F4FDFFFFDD8510FDFFFFD9CAD9E0D9CADE
CBDEEDD9EED9CDD8C4DD9D88FEFFFFD9C2D8CAD8D5DFE0DDDDD9C49ED8C10F86
33010000DDD8D9C4DEE1DD9DD8FDFFFFDD85D8FDFFFFDB9DE4FDFFFFDB85E4FD
FFFFD9C3D9E0D9CDDEE1D9EED9C9D8C4DD9D98FEFFFFDD8510FDFFFFDECAD9C9
DECAD8D9DFE0D9C09ED8C30F83DF000000DDD8D9C0DEE3D9CADD9DC8FDFFFFDD
85C8FDFFFFDB9DD4FDFFFFDB85D4FDFFFFDEEADD8570FDFFFFDC8D98FEFFFFD9
CADEC1DD9D90FEFFFFDD8568FDFFFFDC8D90FEFFFFDEC1DD9D70FDFFFFDD8560
FDFFFFDC8D88FEFFFFDD8570FDFFFFDEC1DEC9DD9D40FFFFFFE997FBFFFF89F6
DDD8D9C0DEE5E9ECFEFFFF908D742600DDD8D9C1DEE1E90AFAFFFF908D742600
DDD8D9C1DEE1E9ECFCFFFF908D742600DDD8D9C1DEE1E9F1F7FFFF908D742600
DDD9E9A3F8FFFFDDDAE93DF8FFFF89F6DDD9E960FDFFFFDDD9E90AFDFFFF89F6
DDD9E95EFAFFFFDDD9E908FAFFFF89F6DDDBE920FFFFFFDDD9E9CCFEFFFF
[END]

Description:

www.shadertoy.com/view/XsX3zB
by Nikita Miropolskiy, attempt failed for MB3D.

It gives nice randomish deformations. The problem is, the cuts should not be there cry

Hopefully, someone will be able to tell me why it is flawed, and where I must adjust? embarrass[/code]
« Last Edit: December 08, 2016, 02:56:56 PM by DarkBeam, Reason: Now it workz » Logged

No sweat, guardian of wisdom!
knighty
Fractal Iambus
***
Posts: 819


« Reply #1 on: December 01, 2016, 08:10:36 PM »

Well! it is so complicated that there must be a bug somewhere.
Crap! I havent thought about not using math library at all in order to avoid constants... But it is a lot of work! grin
Could you try with a (much) simplier example?
Logged
knighty
Fractal Iambus
***
Posts: 819


« Reply #2 on: December 01, 2016, 08:14:02 PM »

BTW! what does __CRT_INLINE do?
Logged
DarkBeam
Global Moderator
Fractal Senior
******
Posts: 2512


Fragments of the fractal -like the tip of it


« Reply #3 on: December 01, 2016, 08:53:10 PM »

Thanks for even looking at this as always kiss
Well I just copied (mindlessly) the template used in math.h itself just because it says "inline" hahah, it should force the compiler to inline?  grin lol
Logged

No sweat, guardian of wisdom!
DarkBeam
Global Moderator
Fractal Senior
******
Posts: 2512


Fragments of the fractal -like the tip of it


« Reply #4 on: December 02, 2016, 08:35:55 PM »

Okay. The problem here is that I am just converting way too much from int() to double() and since every single one brings in a nice (random and indeterminable) error ... I need to use just doubles and carefully rewrite sad soon I will complete this.
Logged

No sweat, guardian of wisdom!
KRAFTWERK
Global Moderator
Fractal Senior
******
Posts: 1439


Virtual Surreality


WWW
« Reply #5 on: December 03, 2016, 02:04:53 PM »

Okay. The problem here is that I am just converting way too much from int() to double() and since every single one brings in a nice (random and indeterminable) error ... I need to use just doubles and carefully rewrite sad soon I will complete this.

horsie riding
Logged

DarkBeam
Global Moderator
Fractal Senior
******
Posts: 2512


Fragments of the fractal -like the tip of it


« Reply #6 on: December 03, 2016, 04:55:54 PM »

Lol Johan it is still unfinished, the situation is way more regular after the segregation of ints but still not as the proggy likes it, still cuts around. sad
Logged

No sweat, guardian of wisdom!
DarkBeam
Global Moderator
Fractal Senior
******
Posts: 2512


Fragments of the fractal -like the tip of it


« Reply #7 on: December 08, 2016, 12:59:58 PM »

Finally! wink Orwell C++ FTW!!!

Code:
#include <math.h>
//  <www.shadertoy.com/view/XsX3zB>
//  by Nikita Miropolskiy initial inspiration
// way extended and optimized

typedef unsigned short  WORD; // 2bytes

void __attribute__((fastcall)) Formula(
             double* x,      // [eax]
             double* y,      // [edx]
             double* arg,    // [ebp+8], points to TIteration3Dext.C1
             void* dummy     // so we end w/ ret 8 as delphi expects
             );

void random3(int r0, int u0, int v0, double* r, double* u, double* v,
double* r2, double* u2, double* v2,
double* r3, double* u3, double* v3,
 double rf, double n_05);
         
__attribute__((packed)) struct TIteration3Dext {
double Cw,Rold,RStopD,x,y,z,w; // use with neg indizes before C1. w is also used for 3d ifs and abox analytic DE
double Px, Py, Pz;             //      actual position, never change these!  Can be used as input.
double Cx, Cy, Cz;             //+24   these are the constants for adding. Pxyz or the julia seed.  Cw is @-56 (begin of struct)
void*  PVar;                   //+48   the actual formulas adress of constants and vars, constants at offset 0 increasing, user vars below -8
float  SmoothItD;              //+52
double Rout;                   //+56   the square of the vector length, can be used as input
int    ItResultI;              //+64
int    maxIt;                  //+68
float  RStop;                  //+72
int    nHybrid[6];             //+76   all formulas iteration counts or single weights in interpol-hybrid
void*  fHPVar[6];              //+100  all formulas pointer to constants+vars, PVars-8=0.5, use PVar for the actual formula
void*  fHybrid[6];             //+124  the formulas adresses
int    CalcSIT;                //+148
int    DoJulia;                //+152
float  LNRStop;                //+156
int    DEoption;               //+160
float  fHln[6];                //+164  for SmoothIts
int    iRepeatFrom;            //+188
double OTrap;                  //+192
double VaryScale;              //+200  to use in vary by its
int    bFirstIt;               //+208  used also as iteration count, is set to 0 on it-start
int    bTmp;                   //+212  tmpBuf, free of use.
double Dfree1;                 //+216
double Dfree2;                 //+224
double Deriv1;                 //+232  for 4D first deriv or as full derivs
double Deriv2;                 //+240
double Deriv3;                 //+248
float  SMatrix4[4][4];         //+256  for 4d rotation, used like most other values only by the programs iteration loop procedure
};

__CRT_INLINE double __cdecl Hypot(double x,double y) ;
__CRT_INLINE double __cdecl length2(double x,double y,double z);
__CRT_INLINE double __cdecl length(double x,double y,double z);
__CRT_INLINE double __cdecl recip (long double _x);
__CRT_INLINE double __cdecl step (double edge, double _x);
__CRT_INLINE int __cdecl istep (double edge, double _x);
__CRT_INLINE int __cdecl storeint (double _x);
__CRT_INLINE int floori(double x);
__CRT_INLINE double __cdecl fracz (double _x);
__CRT_INLINE double __cdecl max (double _a, double _b);
__CRT_INLINE double __cdecl min (double _a, double _b);
__CRT_INLINE int wang_hash(int seed);

__CRT_INLINE double __cdecl loadz (void) // uses constants, assembly required :o)
{
  double res;
  __asm__ ("fldz": "=t" (res));
  return res;
}

__CRT_INLINE double __cdecl load1 (void) // uses constants, assembly required :o)
{
  double res;
  __asm__ ("fld1": "=t" (res));
  return res;
}

__CRT_INLINE double __cdecl Hypot(double x,double y) { return sqrt(x*x+y*y); }

__CRT_INLINE double __cdecl length2(double x,double y,double z) { return (x*x+y*y+z*z); }

__CRT_INLINE double __cdecl length(double x,double y,double z) { return sqrt(length2(x,y,z)); }

__CRT_INLINE double __cdecl recip (long double _x) // uses constants, assembly required :o)
{
  double res;
  __asm__ ("fld1
"
    "fdivp": "=t" (res) : "0" (_x));
  return res;
}

__CRT_INLINE double __cdecl step (double edge, double _x) // uses constants, assembly required :o)
{
  double res;
  double xs = _x-edge;
  __asm__ ("ftst
"
    "fstsw %%ax
"
        "shr %%ah
"
        "jb _nb%=
"
        "fldz
"
        "jmp _end%=
"
        "_nb%=:
"
        "fld1
"
        "_end%=:
"
        "fstp %%st(1)"
        :"=t"(res) // out
        :"0"(xs)   // in
        :"%eax"    // modify EAX (clobbered)
        );
  return res;
}

/*
__CRT_INLINE int __cdecl istep (double edge, double _x)
{
  int res;
  double xs = _x-edge;
  __asm__ ("fldl %1
"
        "ftst
"
    "fstsw %%ax
"
        "shr %%ah
"
        "jb _inb%=
"
        "movl $1,%0
"
        "jmp _iend%=
" // http://stackoverflow.com/questions/3898435/labels-in-gcc-inline-assembly yayz
        "_inb%=:
"
        "movl $0,%0
"
        "_iend%=:
"
        "fstp %%st"
        :"=r"(res) // out REGISTER
        :"m"(xs)   // in MEMORY
        :"%eax"    // modify EAX (clobbered)
        );
  return res;
}
*/

__CRT_INLINE int __cdecl istep (double edge, double _x)
{
  return (_x<=edge?0:1);
}

__CRT_INLINE int __cdecl storeint (double _x)
{
  int res;
  __asm__ ("fldl %1
"
        "fistpl %0
"
        :"=m"(res) // out MEMORY
        :"m"(_x)   // in MEMORY
        // (nothing clobbered) :P
        );
  return res;
}

__CRT_INLINE WORD __cdecl fegetround () // rounding mode to correct value
{
  WORD ncw;
  WORD ocw;
  __asm__ ("fstcw %0
"
        "mov %0, %%ax
"
        // "or $0x0C,%%ah
" // FE_TOWARDZERO -> round()
        "or $0x04,%%ah
" // FE_DOWNWARD -> floor()
        "mov %%ax,%1
"
        "fldcw %1
"
        :"=m"(ocw),"=m"(ncw) // out MEMORY
        :   // in nothing
        :"%eax"    // modify EAX (clobbered)
        );
  return ocw;
}

__CRT_INLINE void __cdecl fesetround (WORD ocw) // rounding mode reset
{
  __asm__ ("fldcw %0
"
        :// out nothing
        :"m"(ocw) // in MEMORY   
        );
  return;
}

__CRT_INLINE int floori(double x) { // emulates perfectly
    //int xi = storeint(x); // fast but unsafe
    // int xi = (int)(x); // control word is reset; slow but safe
    int xi = storeint(x); // control word is reset; slow but safe
    if ( x<(double)xi) xi--;
    return xi;
}

/*
__CRT_INLINE int floori2(double x,double* xid) { // emulates perfectly
    //int xi = storeint(x);
    if ( x>0 ){
    int xi = storeint(x); // fast but unsafe
    *xid = (double)xi;
    return xi;
    }
    int xi = storeint(-x); // fast but unsafe
xi = -xi-1;
*xid = (double)xi;
return xi;
}
*/

__CRT_INLINE int floori2(double x,double* xid) { // works only if rounding mode is correctly set to FE_DOWNWARD -> floor()
    //int xi = storeint(x);
    int xi = storeint(x); // fast but unsafe
*xid = (double)xi;
return xi;
}

__CRT_INLINE double __cdecl fmod1(double _x, double _half) // emulates perfectly
{
  double xnr = _x-((_x>loadz() )?_half:-_half);
  return _x- storeint(xnr);
}

__CRT_INLINE double __cdecl fmodB(double _x, double _half, double B) // emulates perfectly
{
  return fmod1(_x/B,_half)*B;
}

__CRT_INLINE double __cdecl max (double _a, double _b)
{
  return (_a>_b)?_a:_b;
}

__CRT_INLINE double __cdecl min (double _a, double _b)
{
  return (_a<_b)?_a:_b;
}

// fastcall is not quite delphi fastcall.
// first two args are ok, third is in ecx in delphi, on stack here.
void __attribute__((fastcall)) Formula(
             double* Xx,      // [eax] = x
             double* Yy,      // [edx] = y
             double* arg,    // [ebp+8], points to TIteration3Dext.C1
             void* dummy     // so we end w/ ret 8 as delphi expects
             ) {
  // Compute ptr to proper start of TIteration3Dext struct.
  double tp, Zero;
  struct TIteration3Dext* cfg = (struct TIteration3Dext*)(arg-7);
  double* Cns = (double*)(cfg->PVar);
  double* UserV = (double*)(cfg->PVar-0X10); 
  double x[3], x1[3], x2[3], x3[3], w[4], d[4];
  double tf1, tf2, tf3,final;
  int t,u,v,ztep;
  int s[3], e[3], i1[3], i2[3];
//  FAILED attempt to replicate Simplex Noise by Nikita Miropolskiy
//  <www.shadertoy.com/view/XsX3zB>
//  too bad I absolutely do NOT understand this code and it is really sensible
// to minimal errors (like, don't try to replace a floor() with a roundint() ).
// for an unintelligible reason this code compiles but it gives a discontinue DE
// I hope someone is able to fix.
  // Cns[0] = const float F3 =  0.3333333;
  // Cns[1] = const float G3 =  0.1666667;
  // Cns[2] = const float (3*G3-1.) =  -.5;
  // Cns[3] = const float =  +.6;
  // Cns[4] = const float =  1./(0x3FFFFFFF) = 9.3132257548284025442119711490459e-10
  // Cns[5] = const float =  +512.;
  // Cns[6] = const float =  +0.125;
  // Cns[7] = const float =  +0.125;
  // 1st part, it should be easy. I am using ints for ints though :P
  // so I can use wang hash instead of a dumb sin()
  // -------------------------------------------------------------------
  __asm__ ("fnop");
  int oldcw;
  // preparation of x,y,z:
  x[0] = cfg->x*UserV[-1]-UserV[-2];
  x[1] = cfg->y*UserV[-1]-UserV[-3];
  x[2] = cfg->z*UserV[-1]-UserV[-4];
 
  // vec3 s = floor(p + dot(p, vec3(F3)));
  // skewed
  tp = (x[0]+ x[1]+ x[2])*Cns[0];
  oldcw = fegetround(); // (int) = (floor) to avoid branching and slow stuff
  // If we use default rounding mode we get in trouble here
  s[0] = floori2(x[0] + tp, &tf1);
  s[1] = floori2(x[1] + tp, &tf2);
  s[2] = floori2(x[2] + tp, &tf3);
  fesetround(oldcw); // (int) = (roundint) ... or the default mode
  // vec3 x = p - s + dot(s, vec3(G3));
  // unskewed
  tp = (tf1+tf2+tf3)*Cns[1];
  x[0] = x[0] - tf1 + tp;
  x[1] = x[1] - tf2 + tp;
  x[2] = x[2] - tf3 + tp;
  // calculate i1 and i2
  // vec3 e = step(vec3(0.0), x - x.yzx);
  // but step(0.,a-b) = step(b,a) so:
  e[0] = istep(x[1],x[0]); // can only be 0 or 1
  e[1] = istep(x[2],x[1]); // can only be 0 or 1
  e[2] = istep(x[0],x[2]); // can only be 0 or 1
  // vec3 i1 = e*(1.0 - e.zxy);
  i1[0] = e[0] * (1-e[2]); // can only be 0 or 1
  i1[1] = e[1] * (1-e[0]); // can only be 0 or 1
  i1[2] = e[2] * (1-e[1]); // can only be 0 or 1
  // vec3 i2 = 1.0 - e.zxy*(1.0 - e);
  i2[0] = 1 - e[2] * (1-e[0]); // can only be 0 or 1
  i2[1] = 1 - e[0] * (1-e[1]); // can only be 0 or 1
  i2[2] = 1 - e[1] * (1-e[2]); // can only be 0 or 1
  // vec3 x1 = x - i1 + G3;
  // vec3 x2 = x - i2 + 2.0*G3; 2.0*G3 =  F3
  Zero = load1(); // for binary sub of 1
  x1[0] = x[0] + Cns[1]; if (i1[0] != 0) x1[0] -= Zero;
  x1[1] = x[1] + Cns[1]; if (i1[1] != 0) x1[1] -= Zero;
  x1[2] = x[2] + Cns[1]; if (i1[2] != 0) x1[2] -= Zero;
  x2[0] = x[0] + Cns[0]; if (i2[0] != 0) x2[0] -= Zero;
  x2[1] = x[1] + Cns[0]; if (i2[1] != 0) x2[1] -= Zero;
  x2[2] = x[2] + Cns[0]; if (i2[2] != 0) x2[2] -= Zero;
  Zero = loadz();
  // vec3 x3 = x - 1.0 + 3.0*G3 = -.5;
  x3[0] = x[0] + Cns[2];
  x3[1] = x[1] + Cns[2];
  x3[2] = x[2] + Cns[2];
  // calculate surflet weights
  // w.x = dot(x, x);
  w[0] = Cns[3]-length2(x[0],x[1],x[2]);
  // w.y = dot(x1, x1);
  w[1] = Cns[3]-length2(x1[0],x1[1],x1[2]);
  // w.z = dot(x2, x2);
  w[2] = Cns[3]-length2(x2[0],x2[1],x2[2]);
  // w.w = dot(x3, x3);
  w[3] = Cns[3]-length2(x3[0],x3[1],x3[2]);
  // the last part really gave me nightmares. nasty stuff.
  // Had to change something to avoid crashing of MB for unk reasons
  // Regrouped, and avoid to do all those calcs for multiplying by 0.
  // But it does not work well, even if does not crash. let's see
  // -------------------------------------------------------------------
  // w fades from 0.6 at the center of the surflet to 0.0 at the margin
  // w = max(0.6 - w, 0.0);
  // Do w^4
  d[0] = Zero;  d[1] = Zero;  d[2] = Zero;  d[3] = Zero; 
  t=s[0];u=s[1];v=s[2]; ztep = 0;
RANDOMXYZ: 
  if (w[0] > Zero ) {
     double tx,ty,tz;
     double tx2,ty2,tz2;
     double tx3,ty3,tz3;
     
     // w[0] = w[0]*w[0]; w[0] = w[0]*w[0]; // multiply d by w^4... or any other waveform :P
     w[0] = w[0]*w[0]*(UserV[-5]+UserV[-6]*w[0]); // multiply d by w^3... or any other waveform :P
     // d.x = dot(random3(s), x);
     random3(t, u, v, // input = s
                &tx ,&ty, &tz, // output
                &tx2 ,&ty2, &tz2, // output
                &tx3 ,&ty3, &tz3, // output
                Cns[4], Cns[2]); // just constants
     d[0] += w[0]*(tx2*x[0] + ty*x[1]  + tz3*x[2]);
     d[1] += w[0]*(tx3*x[0] + ty2*x[1] + tz*x[2]);
     d[2] += w[0]*(tx*x[0]  + ty3*x[1] + tz2*x[2]);
  }
  // CLOSE YOUR EYES, simply horrible 3x
  // GOTO but had to compress the size of binary :|
  if (ztep == 0) {
  ztep++;
  w[0] = w[1];
  t=s[0]+i1[0],u=s[1]+i1[1],v=s[2]+i1[2];
  x[0]=x1[0];x[1]=x1[1];x[2]=x1[2];
  goto RANDOMXYZ;
  } else if (ztep == 1) {
  ztep++;
  w[0] = w[2];
  t=s[0]+i2[0],u=s[1]+i2[1],v=s[2]+i2[2];
  x[0]=x2[0];x[1]=x2[1];x[2]=x2[2];
  goto RANDOMXYZ;
  } else if (ztep == 2) {
  ztep++;
  w[0] = w[3];
  t=s[0]+1,u=s[1]+1,v=s[2]+1;
  x[0]=x3[0];x[1]=x3[1];x[2]=x3[2];
  goto RANDOMXYZ;
  }
 
  //tx = (d[0]+d[1]+d[2])*UserV[0];
  // YOU MUST! sum all four components or you get discontinuities
  //final = (d[0]+d[1]+d[2]+d[3])*UserV[0];
  cfg->x += d[0]*UserV[0];
  cfg->y += d[1]*UserV[0];
  cfg->z += d[2]*UserV[0];
  // cfg->x += Cns[4]*rt[0];
  // cfg->y += rt[0];
  // cfg->z += rt[0];
}

void random3(int r0, int u0, int v0, double* r, double* u, double* v,
double* r2, double* u2, double* v2,
double* r3, double* u3, double* v3,
 double rf, double n_05)
{
    // Sort of hash-randomization using ints,
// should be fast, very random and portable unlike sin() :P
    int a=2,b=7,c=11,t;
    a = (a+15359*u0 + 16069*v0) ^ 0x5A5A;
    b = (b+16069*u0 + 15359*r0) ^ 0x5A5A;
    c = (c+15359*v0 + 16069*r0) ^ 0x5A5A;
    t = c;
    c = (c - b)*77773;
    b = (b - a)*77773;
    a = (a - t)*77773;
    *v = (rf*((double)(a & 1073741823)))+n_05;
    *r = (rf*((double)(b & 1073741823)))+n_05;
    *u = (rf*((double)(c & 1073741823)))+n_05;
    // fast stuff, even if we lose data :|
    a = a << 4; b = b << 4; c = c << 4;
    *v2 = (rf*((double)(a & 1073741823)))+n_05;
    *r2 = (rf*((double)(b & 1073741823)))+n_05;
    *u2 = (rf*((double)(c & 1073741823)))+n_05;
    a = a << 4; b = b << 4; c = c << 4;
    *v3 = (rf*((double)(a & 1073741823)))+n_05;
    *r3 = (rf*((double)(b & 1073741823)))+n_05;
    *u3 = (rf*((double)(c & 1073741823)))+n_05;
return;
}

/*
uint wang_hash(uint seed)
{
    seed = (seed ^ 61) ^ (seed >> 16);
    seed *= 9;
    seed = seed ^ (seed >> 4);
    seed *= 668265261;
    seed = seed ^ (seed >> 15);
    return seed;
}

//  <www.shadertoy.com/view/XsX3zB>
//  by Nikita Miropolskiy

// discontinuous pseudorandom uniformly distributed in [-0.5, +0.5]^3
vec3 random3(vec3 c) {
float j = 4096.0*sin(dot(c,vec3(17.0, 59.4, 15.0)));
vec3 r;
r.z = fract(512.0*j);
j *= .125;
r.x = fract(512.0*j);
j *= .125;
r.y = fract(512.0*j);
return r-0.5;
}

// skew constants for 3d simplex functions
const float F3 =  0.3333333;
const float G3 =  0.1666667;

// 3d simplex noise
float simplex3d(vec3 p) {
// 1. find current tetrahedron T and it's four vertices
// s, s+i1, s+i2, s+1.0 - absolute skewed (integer) coordinates of T vertices
// x, x1, x2, x3 - unskewed coordinates of p relative to each of T vertices

// calculate s and x
vec3 s = floor(p + dot(p, vec3(F3)));
vec3 x = p - s + dot(s, vec3(G3));

// calculate i1 and i2
vec3 e = step(x.yzx, (x));
vec3 i1 = e*(1.0 - e.zxy);
vec3 i2 = 1.0 - e.zxy*(1.0 - e);

// x1, x2, x3
vec3 x1 = x - i1 + G3;
vec3 x2 = x - i2 + F3;
vec3 x3 = x - .5;

// 2. find four surflets and store them in d
vec4 w, d;

// calculate surflet weights
w.x = dot(x, x);
w.y = dot(x1, x1);
w.z = dot(x2, x2);
w.w = dot(x3, x3);

// w fades from 0.6 at the center of the surflet to 0.0 at the margin
w = max(0.6 - w, 0.0);

// calculate surflet components
d.x = dot(random3(s), x);
d.y = dot(random3(s + i1), x1);
d.z = dot(random3(s + i2), x2);
d.w = dot(random3(s + 1.0), x3);

// multiply d by w^4
w *= w;
w *= w;
d *= w;

// 3. return the sum of the four surflets
return dot(d, vec4(52.0));
}

float simplex3d_fractal(vec3 m) {
    return   0.5333333*simplex3d(m)
+0.2666667*simplex3d(2.0*m)
+0.1333333*simplex3d(4.0*m)
+0.0666667*simplex3d(8.0*m);
}

*/


* meng4.jpg (199.36 KB, 549x595 - viewed 71 times.)
Logged

No sweat, guardian of wisdom!
LMarkoya
Strange Attractor
***
Posts: 282



« Reply #8 on: December 08, 2016, 05:28:56 PM »

That is cool
Logged
DarkBeam
Global Moderator
Fractal Senior
******
Posts: 2512


Fragments of the fractal -like the tip of it


« Reply #9 on: December 09, 2016, 11:14:26 AM »

Thanks! I am sure Dalý would have loved such a toy  angel
Logged

No sweat, guardian of wisdom!
knighty
Fractal Iambus
***
Posts: 819


« Reply #10 on: December 09, 2016, 04:09:32 PM »

Me too! grin  tease
Tremendous work!
BTW Good to know that Devcpp is still alive. Orvell have nothing to do with the results. It is just an IDE. It is the compiler, more specifically its optimizer, that does all the work and all those (constant and such) problems.
Logged
DarkBeam
Global Moderator
Fractal Senior
******
Posts: 2512


Fragments of the fractal -like the tip of it


« Reply #11 on: December 09, 2016, 06:09:42 PM »

Idk exactly, the underlying compiler is marvellous as it produces the same code I wrote by hand automatically and is updated to c++11 cheesy
The old DevCpp I had , with the same exact code, produced assembly that upsetted MB3D a lot (why? shocked )
Too bad the fenv stuff does not work in this project maybe coz I enabled intrinsics ?... but I rewrote all by hand
 grin I am crazy you know buddy
Logged

No sweat, guardian of wisdom!
KRAFTWERK
Global Moderator
Fractal Senior
******
Posts: 1439


Virtual Surreality


WWW
« Reply #12 on: December 10, 2016, 10:05:48 AM »

horsie riding run over
Logged

Pages: [1]   Go Down
  Print  
 
Jump to:  

Related Topics
Subject Started by Replies Views Last post
A new look into escapetime fractals using abs & inner coloring (new) Theories & Research « 1 2 » Kali 18 2136 Last post October 23, 2012, 05:48:56 PM
by Alef
Reflections on dIFS/Escapetime only? feature request MarkJayBee 1 643 Last post October 31, 2012, 11:35:31 PM
by 0Encrypted0
\mathbf not working properly in LaTeX code. Discuss Fractal Forums Pauldelbrot 3 2241 Last post January 12, 2013, 12:21:12 PM
by cKleinhuis
Escapetime (not L-System) tree or plant fractals (new) Theories & Research M Benesi 4 310 Last post January 03, 2016, 09:22:45 PM
by M Benesi
Are you crazy? Still Frame - Wildstyle Sergio CT 0 196 Last post May 08, 2016, 11:43:43 PM
by Sergio CT

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.154 seconds with 29 queries. (Pretty URLs adds 0.008s, 2q)