### _recfold

• 27 Replies
• 339 Views

0 Members and 1 Guest are viewing this topic.

• Moderator
• Posts: 971

#### Re: _recfold

« Reply #15 on: May 17, 2020, 09:48:21 PM »
Luca was right, scaling issue:
z.xy needs to be multiplied by .5 (though that does not explain why this formula does behave quite differently to the one in mb3d...)

Code: [Select]
vec3 recFold(inout vec3 z) { float t; z.xy=abs(z.xy); t=z.x; z.x=z.x+z.y-sym; z.y=t-z.y-asym; t=z.x; z.x = z.x+z.y; z.y = t-z.y; z.xy*=0.5; return z; }
Have also changed it in the frag-code in the previous message
« Last Edit: May 17, 2020, 10:07:05 PM by Sabine62 »
To thine own self be true

#### DarkBeam

• Global Moderator
• Formula crazy engineer
• Posts: 26
• 2 plus 2 is 4 minus 1 is 3 quick maffs

#### Re: _recfold

« Reply #16 on: May 17, 2020, 10:21:16 PM »
Sabine it might also be necessary to rotate the axis because adding x and y then subtracting effectively is a rotation. My code gets a bit obscure at a point so I am not sure how. Please help

• Moderator
• Posts: 971

#### Re: _recfold

« Reply #17 on: May 17, 2020, 10:54:07 PM »
Luca, you know I have no clue about maths!

Stole reasonably successful from _rotatedFolding (though not 100% the same, of course, but a little bit closer...):

Code: [Select]
// Menger Sponge formula created by Knighty// reference http://www.fractalforums.com/ifs-iterated-function-systems/kaleidoscopic-(escape-time-ifs)/// The distance estimation code was originally devised by Buddhi.// reference http://www.fractalforums.com/3d-fractal-generation/a-mandelbox-distance-estimate-formula/15///_recFold by Darkbeam#info Menger Sponge Distance Estimator.#define providesInit//#define USE_IQ_CLOUDS#define KN_VOLUMETRIC#define USE_EIFFIE_SHADOW#define MULTI_SAMPLE_AO//uniform float time;#include "MathUtils.frag"#include "DE-Kn2cr11.frag"#group Mengeruniform int maxiter;  slider[0,10,50]uniform int ColorIterations;  slider[0,3,300]uniform float bailout; slider[0,16,100]uniform vec3 Rotation; slider[(-180,-180,-180),(0,0,0),(180,180,180)]uniform vec3 PreOffset; slider[(-2,-2,-2),(0,0,0),(2,2,2)]uniform float Scale; slider[0.0,3.0,5.0]uniform vec3 PostOffset; slider[(-2,-2,-2),(0,0,0),(2,2,2)]#group recfolduniform float asym; slider[-10,0,10]uniform float sym; slider[-10,9,20]uniform float fold; slider[0,1,1]uniform bool recfold; checkbox[false]vec3 recFold1(inout vec3 z) { float t; z.xy=abs(z.xy); t=z.x; z.x=z.x+z.y-sym; z.y=t-z.y-asym; return z;} vec3 recFold2(inout vec3 z) { float u=z.x; z.x = z.x+z.y; z.y = u-z.y; z.xy*=0.5; return z; }mat3 rot;void init() { rot = rotationMatrixXYZ(Rotation);}float DE(vec3 pos){ int i = 0; vec3 z = vec3(pos); float rr = 0.0; float Dd = 1.0; if (recfold) { recFold1(z); } for( i=0; i<maxiter ; i++) { //if (recfold) {z.x = fold-abs(z.x+fold);recFold2(z);} if (recfold) {z.xy = abs(z.xy+fold) - abs(z.xy-fold) - z.xy;recFold2(z);} z *= rot; z += PreOffset; z = abs(z); if (z.x - z.y < 0.0) z.xy = z.yx; if (z.x - z.z < 0.0) z.xz = z.zx; if (z.y - z.z < 0.0) z.yz = z.zy; z *= Scale; Dd *= Scale; z.x -= 2.0; z.y -= 2.0; if (z.z > 1.0) z.z -= 2.0; z += PostOffset; rr = dot(z,z); if (i<ColorIterations) orbitTrap = min(orbitTrap, abs(vec4(z.xyz,rr))); if ( rr > bailout) { float r = sqrt(rr); return r / Dd; } }}#preset DefaultFOV = 0.5062657Eye = -0.798576713,-2.3653276,3.9251585Target = -0.330844641,-0.918207645,1.61163473Up = -0.145643562,0.849645317,0.502011895EquiRectangular = falseFocalPlane = 1Aperture = 0InFocusAWidth = 0DofCorrect = trueApertureNbrSides = 7ApertureRot = 0ApStarShaped = falseGamma = 2.08335ToneMapping = 3Exposure = 0.6522Brightness = 1Contrast = 1Saturation = 1GaussianWeight = 1AntiAliasScale = 2Bloom = falseBloomIntensity = 0BloomPow = 2BloomTaps = 4BloomStrong = 1DepthToAlpha = falseShowDepth = falseDepthMagnitude = 1Detail = -3.173575FudgeFactor = 0.244013683MaxRaySteps = 629MaxDistance = 20Dither = 0DetailAO = -1.52980132coneApertureAO = 0.5maxIterAO = 20FudgeAO = 0.5AO_ambient = 0.7AO_camlight = 1AO_pointlight = 1AoCorrect = 0SpecularExp = 16.364CamLight = 1,1,1,0.489361702AmbiantLight = 1,1,1,0.299516909Reflection = 0,0,0ReflectionsNumber = 0SpotGlow = trueLightSize = 0LightFallOff = 0LightGlowRad = 0LightGlowExp = 1HardShadow = 1ShadowSoft = 0.961098392ShadowBlur = 0.005668934perf = falseSSS = falsesss1 = 0.1sss2 = 0.5BaseColor = 1,1,1OrbitStrength = 1X = 1,1,1,0.198614318Y = 0.345097989,0.666666985,0,0.055427251Z = 1,0.666666985,0,0.692840647R = 0.0784313977,1,0.941175997,-0.031213872BackgroundColor = 0.450980395,0.709803939,0.866666675GradientBackground = 0.3261CycleColors = falseCycles = 4.04901EnableFloor = falseFloorNormal = 0,0,0FloorColor = 1,1,1HF_Fallof = 0.1HF_Const = 0HF_Intensity = 0HF_Dir = 0,0,1HF_Offset = 0HF_Color = 1,1,1,1HF_Scatter = 0HF_Anisotropy = 0,0,0HF_FogIter = 1HF_CastShadow = falseEnCloudsDir = falseCloudDir = 0,0,1CloudScale = 1CloudFlatness = 0CloudDensity = 1CloudRoughness = 1CloudContrast = 1CloudColor = 0.649999976,0.680000007,0.699999988CloudColor2 = 0.0700000003,0.170000002,0.239999995SunLightColor = 0.699999988,0.5,0.300000012Cloudvar1 = 0.99Cloudvar2 = 1CloudIter = 5CloudBgMix = 1WindDir = 0,0,1WindSpeed = 1RefineSteps = 4NormalBackStep = 1Specular = 1SpotLight = 1,1,1,2.81212121LightPos = -0.818854,1.08108107,2.16216218FloorHeight = 0CloudTops = 1CloudBase = -1asym = 0sym = 0recfold = truemaxiter = 10ColorIterations = 3bailout = 16Rotation = 0,0,0PreOffset = 0,0,0Scale = 3PostOffset = 0,0,0fold = 0.070175438#endpreset
Update: Sadly does not at all revert to standard menger sponge if set to 0
Good gracious, I wish I knew what I am doing
« Last Edit: June 05, 2020, 11:26:37 AM by Sabine62 »

• Moderator
• Posts: 971

#### Re: _recfold

« Reply #18 on: May 18, 2020, 12:24:25 AM »
Had another go at it, still not right but at least it reverts to standard Menger:

Code: [Select]
// Menger Sponge formula created by Knighty// reference http://www.fractalforums.com/ifs-iterated-function-systems/kaleidoscopic-(escape-time-ifs)/// The distance estimation code was originally devised by Buddhi.// reference http://www.fractalforums.com/3d-fractal-generation/a-mandelbox-distance-estimate-formula/15/#info Menger Sponge Distance Estimator.#define providesInit//#define USE_IQ_CLOUDS#define KN_VOLUMETRIC#define USE_EIFFIE_SHADOW#define MULTI_SAMPLE_AO//uniform float time;#include "MathUtils.frag"#include "DE-Kn2cr11.frag"#group Mengeruniform int maxiter;  slider[0,10,50]uniform int ColorIterations;  slider[0,3,300]uniform float bailout; slider[0,16,100]uniform vec3 Rotation; slider[(-180,-180,-180),(0,0,0),(180,180,180)]uniform vec3 PreOffset; slider[(-2,-2,-2),(0,0,0),(2,2,2)]uniform float Scale; slider[0.0,3.0,5.0]uniform vec3 PostOffset; slider[(-2,-2,-2),(0,0,0),(2,2,2)]#group recfolduniform float asym; slider[-10,0,10]uniform float sym; slider[-10,9,20]uniform float fold; slider[0,1,1]uniform bool recfold; checkbox[false]vec3 recFold1(inout vec3 z) { float t; z.xy=abs(z.xy); t=z.x; z.x=z.x+z.y-sym; z.y=t-z.y-asym; return z;} vec3 recFold2(inout vec3 z) { float u=z.x; z.x = z.x-z.y; z.y = u+z.y; z.xy*=0.5; return z; }mat3 rot;void init() { rot = rotationMatrixXYZ(Rotation);}float DE(vec3 pos){ int i = 0; vec3 z = vec3(pos); float rr = 0.0; float Dd = 1.0; for( i=0; i<maxiter ; i++) { //if (recfold) {z.x = fold-abs(z.x+fold);recFold2(z);} //if (recfold) {recFold1(z);z = abs(z+fold) - abs(z-fold) - z;recFold2(z);} if (recfold) {recFold1(z);z = fold-abs(z+fold);recFold2(z);} z *= rot; z += PreOffset; z = abs(z); if (z.x - z.y < 0.0) z.xy = z.yx; if (z.x - z.z < 0.0) z.xz = z.zx; if (z.y - z.z < 0.0) z.yz = z.zy; z *= Scale; Dd *= Scale; z.x -= 2.0; z.y -= 2.0; if (z.z > 1.0) z.z -= 2.0; z += PostOffset; rr = dot(z,z); if (i<ColorIterations) orbitTrap = min(orbitTrap, abs(vec4(z.xyz,rr))); if ( rr > bailout) { float r = sqrt(rr); return r / Dd; } }}

• Posts: 1866

#### Re: _recfold

« Reply #19 on: May 18, 2020, 12:47:18 AM »
Recfold2 causes the bevel.
try...
Code: [Select]
 ... if (Recfold1) { recFold1(z); } if (Recfold2) { recFold2(z); } for( i=0; i<maxiter ; i++) { if (Recfold1) {z.xy = abs(z.xy+fold) - abs(z.xy-fold) - z.xy;} if (Recfold2) recFold2(z);...
edit: Thanks Sabine  some interesting structures using Knighty's menger sphere too. should have had this for the IOTM contest
« Last Edit: May 18, 2020, 03:08:41 AM by 3DickUlus, Reason: pic »

#### mclarekin

• Fractal Freak
• Posts: 784

#### Re: _recfold

« Reply #20 on: May 18, 2020, 03:47:18 AM »
@ sabine the second abs(y).  Anyhow what ever we do, we end up with  interesting folds on a menger3 (and nice images folks!).  Darkbeam is correct about a scaling, if we write out x as one line with  no offsets,  we get x = 2x, so a scaling of 0.5 would fix that

Code: [Select]
x=abs(x);y=abs(y);t= x;x = x+y-sym;y = t-y-asym;y = -abs(y); // this onet= x;x = x+y;y = t-y;

• Moderator
• Posts: 971

#### Re: _recfold

« Reply #21 on: May 18, 2020, 08:50:02 AM »
Nice results with Menger Sphere, Dick!

Graeme, doubly blind, what can I say

#### mclarekin

• Fractal Freak
• Posts: 784

#### Re: _recfold

« Reply #22 on: May 19, 2020, 09:25:29 AM »
we are all doubly blind at times, i sure am

#### mclarekin

• Fractal Freak
• Posts: 784

#### Re: _recfold

« Reply #23 on: June 30, 2020, 06:13:38 AM »
I have had another play with this, I have not checked if it has same result as m3d,  added some bools.  There is still more options to test later

Code: [Select]
uniform int MaxRecFoldIters;  slider[0,4,10]uniform float sym;  slider[-5,0,5]uniform float asym;  slider[-5,0,5]uniform bool negAbsX; checkbox[false]uniform bool negAbsY; checkbox[true]uniform float scaleZ;  slider[0,1,1]uniform bool Xfold; checkbox[true]uniform float foldX;  slider[-5,1,5]uniform bool Yfold; checkbox[false]uniform float foldY;  slider[-5,1,5]vec3 recFold(vec3 z, int i){ if (i < MaxRecFoldIters) { z.x = abs(z.x); z.y = abs(z.y); float t = z.x; z.x = z.x + z.y - sym; z.y = t - z.y - asym; if (negAbsX) z.x = -abs(z.x); if (negAbsY) z.y = -abs(z.y); t = z.x; z.x = z.x + z.y; z.y = t - z.y; z.x *= 0.5; z.y *= 0.5; z.z *= scaleZ; if (Xfold) z.x = foldX - abs(z.x + foldX); if (Yfold) z.y = foldY - abs(z.y + foldY); } return z;}

• Moderator
• Posts: 971

#### Re: _recfold

« Reply #24 on: June 30, 2020, 10:09:48 AM »
What's your code in the loop, Graeme? Just recFold(z,i); ?
Does not get built here/shown in the variable editor...

#### mclarekin

• Fractal Freak
• Posts: 784

#### Re: _recfold

« Reply #25 on: June 30, 2020, 12:22:49 PM »
@ sabine , here is a frag, also added an xy swap

Code: [Select]
#info Menger Distance Estimator.#define providesInit#include "MathUtils.frag"#include "DE-Raytracer.frag"#group Menger// Based on Knighty's Kaleidoscopic IFS 3D Fractals, described here:// http://www.fractalforums.com/3d-fractal-generation/kaleidoscopic-%28escape-time-ifs%29/// rearranged// testing two similar types of variable scale (only need one)// scaleVary != 0.0 to work!// placed an additional 3 angle rotation before the offset//   mclarekin 23-02-19// Pre_Rotationuniform vec3 RotVector; slider[(0,0,0),(1,1,1),(1,1,1)]uniform float RotAngle; slider[0.00,0,180]// Scale parameter. A perfect Menger is 3.0uniform float Scale; slider[0.00,3.0,4.00]uniform float scaleVary; slider[-2.00,0.0,2.00]uniform float scaleOffset; slider[-2.00,0.0,2.00]uniform bool varyMode2; checkbox[false]// 3 angle rotationuniform vec3 Rotation; slider[(-180,-180,-180),(0,0,0),(180,180,180)]uniform vec3 Offset; slider[(0,0,0),(1,1,1),(5,5,5)]mat3 rotA;mat3 rotB;void init() { rotA = rotationMatrix3(normalize(RotVector), RotAngle); rotB = rotationMatrixXYZ(Rotation);}// Number of fractal iterations.uniform int Iterations;  slider[0,8,100]uniform int ColorIterations;  slider[0,8,100]uniform float Bailout;  slider[0,20,100]uniform float DEtweak;  slider[0,2,5]uniform int MaxRecFoldIters;  slider[0,4,10]uniform bool altXYswap; checkbox[false]uniform float sym;  slider[-5,0,5]uniform float asym;  slider[-5,0,5]uniform bool negAbsX; checkbox[false]uniform bool negAbsY; checkbox[true]uniform float scaleZ;  slider[0,1,1]uniform bool Xfold; checkbox[true]uniform float foldX;  slider[-5,1,5]uniform bool Yfold; checkbox[false]uniform float foldY;  slider[-5,1,5]vec3 recFold(vec3 z, int i){ if (i < MaxRecFoldIters) { z.x = abs(z.x); z.y = abs(z.y);if (altXYswap) z.xy = z.yx; float t = z.x; z.x = z.x + z.y - sym; z.y = t - z.y - asym; if (negAbsX) z.x = -abs(z.x); if (negAbsY) z.y = -abs(z.y); t = z.x; z.x = z.x + z.y; z.y = t - z.y; z.x *= 0.5; z.y *= 0.5; z.z *= scaleZ; if (Xfold) z.x = foldX - abs(z.x + foldX); if (Yfold) z.y = foldY - abs(z.y + foldY); } return z;}float DE(vec3 z){ int i = 0; float useScale = 1.0; float addScale = 0.0; float Dd = 1.0; float rr = dot(z,z); while(rr<Bailout && (i<Iterations))  {z = recFold (z, i); // pre-rotation z = rotA *z; // MENGER SPONGE // menger sponge abs and swizzle z = abs(z); if (z.x<z.y){ z.xy = z.yx;} if (z.x<z.z){ z.xz = z.zx;} if (z.y<z.z){ z.yz = z.zy;} // menger sponge scale useScale = addScale + Scale; z *= useScale; Dd = Dd * abs(useScale); // update addScale for next iteration float vary = scaleVary * (abs(addScale) - scaleOffset); if (varyMode2) addScale = -vary; else addScale -= vary; // rotation inside menger sponge z = rotB *z;  // menger sponge conditional offset z -= Offset; if( z.z<-0.5*Offset.z)  z.z+=Offset.z; //orbitTrap color rr = dot(z,z); if (i<ColorIterations) orbitTrap = min(orbitTrap, (vec4(abs(z),rr))); i++; } return sqrt(rr) / (Dd + DEtweak);}

• Moderator
• Posts: 971

#### Re: _recfold

« Reply #26 on: June 30, 2020, 12:36:40 PM »
Oops, made a little error with naming a bool the same as a #group...
Pasted your code and still the same happening   Blind, that's me...
Thanks, Graeme

• Moderator
• Posts: 971