#info Kleinian groups
#info Original idea and code by Jos Leys (Dec 2016)
#info Some cosmetic modifications by Naït Merzouk Abdelaziz (A.k.a. Knighty)
#info liscence: Ask Jos Leys ;-)
//#include "DE-Raytracer.frag"
#include "DE-Kn2.frag"
#group Kleinian_test
uniform int Box_Iterations; slider[1,50,100]
//Trace of the transformation a
uniform float KleinR; slider[1.8,2.0,2.0]
uniform float KleinI; slider[-0.2,0.0,0.2]
//To really give a kleinian group they must be of the form cos(PI/n) if <1 and any value if >=1
uniform float box_size_z; slider[0.0,0.5,1.0]
uniform float box_size_x; slider[0.0,0.5,1.0]
//Want do show the balls
uniform bool ShowBalls; checkbox[true]
//The DE is wilde. It needs some clamping
uniform float Clamp_y; slider[0.01,1.0,10.0]
uniform float Clamp_DF; slider[0.0,1.0,10.0]
#group SphInv
//Want do do an inversion
uniform bool DoInversion; checkbox[false]
//Inversion center
uniform vec3 InvCenter; slider[(-1,-1,-1),(0,0,0),(1,1,1)]
//Inversion radius squared
uniform float InvRadius; slider[0.01,1,2]
float dot2(vec3 z){ return dot(z,z);}
vec3 wrap(vec3 x, vec3 a, vec3 s){
x -= s;
return (x-a*floor(x/a)) + s;
}
void TransA(inout vec3 z, inout float DF, float a, float b){
float iR = 1. / dot2(z);
z *= -iR;
z.x = -b - z.x; z.y = a + z.y;
DF *= iR;
}
float JosKleinian(vec3 z)
{
float DE=1e10;
float DF = 1.0;
float a = KleinR, b = KleinI;
float f = sign(b) ;
for (int i = 0; i < Box_Iterations; i++)
{
z = wrap(z, vec3(2. * box_size_x, a, 2. * box_size_z), vec3(- box_size_x, 0., - box_size_z));
//If above the separation line, rotate by 180° about (-b/2, a/2)
if (z.y >= a * (0.5 + 0.2 * sin(f * PI * (z.x + b * 0.5) / box_size_x)))
z = vec3(-b, a, 0.) - z;//z.xy = vec2(-b, a) - z.xy;
orbitTrap = min(orbitTrap, abs(vec4(z,dot(z,z))));//For colouring
//Apply transformation a
TransA(z, DF, a, b);
//DE=min(DE,min(z.y,Clamp_y)/max(DF,Clamp_DF));//Slower but gives slightly better DE
}
if (ShowBalls) z.y= min(z.y, a-z.y);//Shows the spheres ?
DE=min(z.y, Clamp_y) / max(DF, Clamp_DF);//Faster
return DE;
}
float DE(vec3 p) {
if(DoInversion){
p=p-InvCenter;
float r=length(p);
float r2=r*r;
p=(InvRadius * InvRadius/r2)*p+InvCenter;
float de=JosKleinian(p);
de=r2*de/(InvRadius * InvRadius+r*de);
return de;
}
else return JosKleinian(p);
}
#preset Default
FOV = 0.4
Eye = 1.63974,-8.43643,-10.1553
Target = 1.53718,-7.12339,-8.65018
Up = -0.302626,0.642868,-0.70366
FocalPlane = 1
Aperture = 0
InFocusAWidth = 0
ApertureNbrSides = 5
ApertureRot = 0
ApStarShaped = false
Gamma = 2.2
ToneMapping = 3
Exposure = 1.5
Brightness = 1
Contrast = 1.1
Saturation = 1
GaussianWeight = 1
AntiAliasScale = 1.6
Bloom = false
BloomIntensity = 0.25
BloomPow = 2
BloomTaps = 4
Detail = -3
RefineSteps = 4
FudgeFactor = 0.3636
MaxRaySteps = 297
MaxDistance = 120
Dither = 0.5
NormalBackStep = 1
DetailAO = -2.51849
coneApertureAO = 0.5
maxIterAO = 20
AO_ambient = 1
AO_camlight = 0
AO_pointlight = 0
AoCorrect = 0
Specular = 0.00529
SpecularExp = 100
CamLight = 1,1,1,0.1923
AmbiantLight = 1,1,1,0.47058
Glow = 1,1,1,0
GlowMax = 0
Reflection = 0,0,0
ReflectionsNumber = 0
SpotGlow = false
SpotLight = 1,1,1,10
LightPos = 5,8,-10
LightSize = 0.01
LightFallOff = 0
LightGlowRad = 0
LightGlowExp = 1
HardShadow = 1
ShadowSoft = 2
BaseColor = 0.776471,0.776471,0.776471
OrbitStrength = 0.6
X = 0,1,0.164706,0.44186
Y = 1,0.533333,0,0.7907
Z = 0.603922,0.164706,0.776471,0.4186
R = 0.262745,0.482353,1,0.6
BackgroundColor = 0,0,0
GradientBackground = 0
CycleColors = true
Cycles = 4.44153
EnableFloor = false
FloorNormal = 0,0,1
FloorHeight = 0
FloorColor = 1,1,1
HF_Fallof = 0.1
HF_Const = 0
HF_Intensity = 0
HF_Dir = 0,0,1
HF_Offset = 0
HF_Color = 1,1,1,1
HF_Scatter = 0
HF_Anisotropy = 0,0,0
HF_FogIter = 1
HF_CastShadow = false
CloudScale = 1
CloudFlatness = 0
CloudTops = 1
CloudBase = -1
CloudDensity = 1
CloudRoughness = 1
CloudContrast = 1
CloudColor = 0.65,0.68,0.7
SunLightColor = 0.7,0.5,0.3
Box_Iterations = 30
KleinR = 1.9
KleinI = 0.056
box_size_z = 1
box_size_x = 1
Clamp_y = 0.5
Clamp_DF = 1
DoInversion = true
InvCenter = 0,1,0
InvRadius = 0.38705
ShowBalls = false
#endpreset
#preset QF
FOV = 0.4
Eye = 8.0037,-6.88172,-22.1531
Target = 7.79584,-6.28974,-20.2541
Up = -0.474336,0.813055,-0.305367
Gamma = 2.2
ToneMapping = 3
Exposure = 1.5
Brightness = 1
Contrast = 1.1
Saturation = 1
GaussianWeight = 1
AntiAliasScale = 1.6
Detail = -3
FudgeFactor = 0.25
MaxRaySteps = 297
Dither = 0.5
NormalBackStep = 1
CamLight = 1,1,1,0.1923
Glow = 1,1,1,0
GlowMax = 0
BaseColor = 0.576471,0.576471,0.576471
OrbitStrength = 0.73333
X = 0,1,0.164706,0.44186
Y = 1,0.533333,0,0.7907
Z = 0.603922,0.164706,0.776471,0.4186
R = 0.262745,0.482353,1,0.6
BackgroundColor = 0,0,0
GradientBackground = 0
CycleColors = true
Cycles = 4.44153
EnableFloor = false
FloorNormal = 0,0,1
FloorHeight = 0
FloorColor = 1,1,1
Box_Iterations = 40
KleinR = 1.9
KleinI = 0.1
box_size_z = 0.7071
box_size_x = 0.7071
Clamp_y = 0.5
Clamp_DF = 1
DoInversion = true
InvCenter = 0,-1,0
InvRadius = 0.30327
FocalPlane = 1
Aperture = 0
InFocusAWidth = 0
ApertureNbrSides = 5
ApertureRot = 0
ApStarShaped = false
Bloom = false
BloomIntensity = 0.25
BloomPow = 2
BloomTaps = 4
RefineSteps = 5
MaxDistance = 120
DetailAO = -2.51849
coneApertureAO = 0.5
maxIterAO = 20
AO_ambient = 1
AO_camlight = 0
AO_pointlight = 0
AoCorrect = 0
Specular = 0.00529
SpecularExp = 100
AmbiantLight = 1,1,1,0.47058
Reflection = 0,0,0
ReflectionsNumber = 0
SpotGlow = false
SpotLight = 1,1,1,10
LightPos = 5,8,-10
LightSize = 0.01
LightFallOff = 0
LightGlowRad = 0
LightGlowExp = 1
HardShadow = 1
ShadowSoft = 2
HF_Fallof = 0.1
HF_Const = 0
HF_Intensity = 0
HF_Dir = 0,0,1
HF_Offset = 0
HF_Color = 1,1,1,1
HF_Scatter = 0
HF_Anisotropy = 0,0,0
HF_FogIter = 1
HF_CastShadow = false
CloudScale = 1
CloudFlatness = 0
CloudTops = 1
CloudBase = -1
CloudDensity = 1
CloudRoughness = 1
CloudContrast = 1
CloudColor = 0.65,0.68,0.7
SunLightColor = 0.7,0.5,0.3
ShowBalls = true
#endpreset
#preset QF2
FOV = 0.71698
Eye = -0.906954,0.667628,0.47372
Target = 0.0324118,0.542785,0.0115637
Up = 0,1,0
Gamma = 2
ToneMapping = 5
Exposure = 1
Brightness = 1
Contrast = 1
Saturation = 1
GaussianWeight = 1
AntiAliasScale = 1.5
Detail = -3.5
FudgeFactor = 0.21212
MaxRaySteps = 541
Dither = 0.5
NormalBackStep = 1
CamLight = 1,1,1,0.03846
Glow = 1,1,1,0
GlowMax = 0
BaseColor = 0.776471,0.776471,0.776471
OrbitStrength = 0.5
X = 0,1,0.164706,1
Y = 1,0.533333,0,-1
Z = 0.603922,0.164706,0.776471,1
R = 0.262745,0.482353,1,0.29412
BackgroundColor = 0.270588,0.403922,0.6
GradientBackground = 0
CycleColors = true
Cycles = 4.44153
EnableFloor = false
FloorNormal = 0,0,1
FloorHeight = 0
FloorColor = 1,1,1
Box_Iterations = 20
KleinR = 1.91134
KleinI = 0.06126
box_size_z = 0.7071
box_size_x = 0.7071
Clamp_y = 0.4
Clamp_DF = 3
DoInversion = false
InvCenter = 0,-1,0
InvRadius = 0.30327
FocalPlane = 1
Aperture = 0
InFocusAWidth = 0
ApertureNbrSides = 5
ApertureRot = 0
ApStarShaped = false
Bloom = false
BloomIntensity = 0.25
BloomPow = 2
BloomTaps = 4
RefineSteps = 4
MaxDistance = 20
DetailAO = -2.5
coneApertureAO = 0.5
maxIterAO = 20
AO_ambient = 1
AO_camlight = 0
AO_pointlight = 0
AoCorrect = 0
Specular = 0.4
SpecularExp = 16
AmbiantLight = 1,1,1,2
Reflection = 1,1,1
ReflectionsNumber = 0
SpotGlow = true
SpotLight = 1,1,1,7
LightPos = -1,1,-1
LightSize = 0.02
LightFallOff = 0
LightGlowRad = 0
LightGlowExp = 1
HardShadow = 1
ShadowSoft = 10
HF_Fallof = 0.1
HF_Const = 0.08861
HF_Intensity = 0
HF_Dir = 0,0,1
HF_Offset = 0
HF_Color = 0.670588,0.807843,0.890196,1
HF_Scatter = 10
HF_Anisotropy = 0.847059,0.847059,0.847059
HF_FogIter = 1
HF_CastShadow = false
CloudScale = 1
CloudFlatness = 0
CloudTops = 1
CloudBase = -1
CloudDensity = 1
CloudRoughness = 1
CloudContrast = 1
CloudColor = 0.65,0.68,0.7
SunLightColor = 0.7,0.5,0.3
ShowBalls = true
#endpreset
#preset QF3
FOV = 0.4
Eye = -0.657958,-0.589646,-3.7183
Target = -0.286782,0.0337675,-1.8546
Up = 0.0451903,0.028017,-0.998585
FocalPlane = 1
Aperture = 0
InFocusAWidth = 0
ApertureNbrSides = 5
ApertureRot = 0
ApStarShaped = false
Gamma = 2.2
ToneMapping = 3
Exposure = 1.5
Brightness = 1
Contrast = 1
Saturation = 1
GaussianWeight = 1
AntiAliasScale = 1.6
Bloom = false
BloomIntensity = 0.25
BloomPow = 2
BloomTaps = 4
Detail = -3
RefineSteps = 5
FudgeFactor = 0.25
MaxRaySteps = 297
MaxDistance = 120
Dither = 0.5
NormalBackStep = 1
DetailAO = -2.51849
coneApertureAO = 0.95556
maxIterAO = 10
AO_ambient = 1
AO_camlight = 0
AO_pointlight = 0
AoCorrect = 0
Specular = 0.00529
SpecularExp = 100
CamLight = 1,1,1,0
AmbiantLight = 1,1,1,0.6
Glow = 1,1,1,0
GlowMax = 0
Reflection = 0,0,0
ReflectionsNumber = 0
SpotGlow = false
SpotLight = 1,1,1,10
LightPos = 10,10,-8.1578
LightSize = 0.01
LightFallOff = 0
LightGlowRad = 0
LightGlowExp = 1
HardShadow = 1
ShadowSoft = 2
BaseColor = 0.576471,0.576471,0.576471
OrbitStrength = 0.65
X = 0,1,0.164706,1
Y = 1,0.215686,0.752941,0.95348
Z = 0.415686,0.776471,0.137255,1
R = 0.262745,0.482353,1,1
BackgroundColor = 0,0,0
GradientBackground = 0
CycleColors = true
Cycles = 5.16506
EnableFloor = false
FloorNormal = 0,0,1
FloorHeight = 0
FloorColor = 1,1,1
HF_Fallof = 0.1
HF_Const = 0
HF_Intensity = 0
HF_Dir = 0,0,1
HF_Offset = 0
HF_Color = 0.741176,0.87451,1,1
HF_Scatter = 0
HF_Anisotropy = 0,0,0
HF_FogIter = 1
HF_CastShadow = false
CloudScale = 1
CloudFlatness = 0
CloudTops = 1
CloudBase = -1
CloudDensity = 1
CloudRoughness = 1
CloudContrast = 1
CloudColor = 0.65,0.68,0.7
SunLightColor = 0.7,0.5,0.3
Box_Iterations = 40
KleinR = 1.91134
KleinI = 0.125
box_size_z = 0.7071
box_size_x = 0.7071
Clamp_y = 0.5
Clamp_DF = 1
DoInversion = true
InvCenter = 0,1,0
InvRadius = 0.3242
ShowBalls = true
#endpreset
#preset QF4
FOV = 0.4
Eye = -0.657958,-0.589646,-3.7183
Target = -0.286782,0.0337675,-1.8546
Up = 0.0451903,0.028017,-0.998585
FocalPlane = 1
Aperture = 0
InFocusAWidth = 0
ApertureNbrSides = 5
ApertureRot = 0
ApStarShaped = false
Gamma = 2.2
ToneMapping = 3
Exposure = 1.5
Brightness = 1
Contrast = 1
Saturation = 1
GaussianWeight = 1
AntiAliasScale = 1.6
Bloom = false
BloomIntensity = 0.25
BloomPow = 2
BloomTaps = 4
Detail = -3
RefineSteps = 5
FudgeFactor = 0.25
MaxRaySteps = 297
MaxDistance = 120
Dither = 0.5
NormalBackStep = 1
DetailAO = -2.51849
coneApertureAO = 0.95556
maxIterAO = 10
AO_ambient = 1
AO_camlight = 0
AO_pointlight = 0
AoCorrect = 0
Specular = 0.00529
SpecularExp = 100
CamLight = 1,1,1,0
AmbiantLight = 1,1,1,0.6
Glow = 1,1,1,0
GlowMax = 0
Reflection = 0,0,0
ReflectionsNumber = 0
SpotGlow = false
SpotLight = 1,1,1,10
LightPos = 10,10,-8.1578
LightSize = 0.01
LightFallOff = 0
LightGlowRad = 0
LightGlowExp = 1
HardShadow = 1
ShadowSoft = 2
BaseColor = 0.576471,0.576471,0.576471
OrbitStrength = 0.65
X = 0,1,0.164706,1
Y = 1,0.215686,0.752941,0.95348
Z = 0.415686,0.776471,0.137255,1
R = 0.262745,0.482353,1,1
BackgroundColor = 0,0,0
GradientBackground = 0
CycleColors = true
Cycles = 5.16506
EnableFloor = false
FloorNormal = 0,0,1
FloorHeight = 0
FloorColor = 1,1,1
HF_Fallof = 0.1
HF_Const = 0
HF_Intensity = 0
HF_Dir = 0,0,1
HF_Offset = 0
HF_Color = 0.741176,0.87451,1,1
HF_Scatter = 0
HF_Anisotropy = 0,0,0
HF_FogIter = 1
HF_CastShadow = false
CloudScale = 1
CloudFlatness = 0
CloudTops = 1
CloudBase = -1
CloudDensity = 1
CloudRoughness = 1
CloudContrast = 1
CloudColor = 0.65,0.68,0.7
SunLightColor = 0.7,0.5,0.3
Box_Iterations = 40
KleinR = 1.90309
KleinI = 0.1125
box_size_z = 0.80902
box_size_x = 0.80902
Clamp_y = 0.5
Clamp_DF = 1
DoInversion = true
InvCenter = 0,1,0
InvRadius = 0.3242
ShowBalls = true
#endpreset
#preset Balls
FOV = 0.71698
Eye = 0.514148,0.626541,-1.14617
Target = 0.178895,0.554774,-0.149159
Up = 0.0849694,0.996071,-0.0249459
FocalPlane = 1
Aperture = 0
InFocusAWidth = 0
ApertureNbrSides = 5
ApertureRot = 0
ApStarShaped = false
Gamma = 2
ToneMapping = 5
Exposure = 1
Brightness = 1
Contrast = 1
Saturation = 1
GaussianWeight = 1
AntiAliasScale = 1.5
Bloom = false
BloomIntensity = 0.25
BloomPow = 2
BloomTaps = 4
Detail = -3.5
RefineSteps = 3
FudgeFactor = 0.25
MaxRaySteps = 500
MaxDistance = 3
Dither = 0.5
NormalBackStep = 1
DetailAO = -1.5
coneApertureAO = 0.5
maxIterAO = 20
AO_ambient = 1
AO_camlight = 0
AO_pointlight = 0
AoCorrect = 0
Specular = 0.4
SpecularExp = 16
CamLight = 1,1,1,0
AmbiantLight = 1,1,1,1
Glow = 1,1,1,0
GlowMax = 0
Reflection = 1,1,1
ReflectionsNumber = 0
SpotGlow = true
SpotLight = 1,1,1,3
LightPos = -1,1,-1
LightSize = 0.02
LightFallOff = 0
LightGlowRad = 0
LightGlowExp = 1
HardShadow = 1
ShadowSoft = 10
BaseColor = 0.552941,0.552941,0.552941
OrbitStrength = 0.33333
X = 0,1,0.164706,1
Y = 1,0.533333,0,0.27906
Z = 0.603922,0.164706,0.776471,0.4186
R = 0.262745,0.482353,1,0.12942
BackgroundColor = 0.270588,0.403922,0.6
GradientBackground = 0
CycleColors = false
Cycles = 4.44153
EnableFloor = false
FloorNormal = 0,0,1
FloorHeight = 0
FloorColor = 1,1,1
HF_Fallof = 0.1
HF_Const = 0.05063
HF_Intensity = 0
HF_Dir = 0,0,1
HF_Offset = 0
HF_Color = 0.670588,0.807843,0.890196,1
HF_Scatter = 10
HF_Anisotropy = 0.847059,0.847059,0.847059
HF_FogIter = 1
HF_CastShadow = false
CloudScale = 1
CloudFlatness = 0
CloudTops = 1
CloudBase = -1
CloudDensity = 1
CloudRoughness = 1
CloudContrast = 1
CloudColor = 0.65,0.68,0.7
SunLightColor = 0.7,0.5,0.3
Box_Iterations = 20
KleinR = 1.91134
KleinI = 0.06126
box_size_z = 1
box_size_x = 0.7071
Clamp_y = 0.5
Clamp_DF = 4
DoInversion = false
InvCenter = 0,-1,0
InvRadius = 0.30327
ShowBalls = true
#endpreset