ڑؔͷܰྔԽ
• Mandelbox ͱ͍͏౷తͳϑϥΫλϧਤܗ
• ifذ͋ͬͯॲཧ͕ॏ͍…
• ݟͨͷྼԽΛ͑ͳ͕ΒڑؔΛܰྔԽʂ
8
// http://blog.hvidtfeldts.net/index.php/2011/11/distance-estimated-3d-fractals-vi-the-mandelbox/
float minRadius2 = 0.5;
float fixedRadius2 = 1.0;
float foldingLimit = 1.0;
#define Iterations 8
void sphereFold(inout vec3 z, inout float dz) {
float r2 = dot(z,z);
if (r2 < minRadius2) {
// linear inner scaling
float temp = (fixedRadius2 / minRadius2);
z *= temp;
dz *= temp;
} else if (r2 < fixedRadius2) {
// this is the actual sphere inversion
float temp = fixedRadius2 / r2;
z *= temp;
dz *= temp;
}
}
void boxFold(inout vec3 z, inout float dz) {
z = clamp(z, -foldingLimit, foldingLimit) * 2.0 - z;
}
float dMbox(vec3 z) {
vec3 offset = z;
float dr = 1.0;
for (int n = 0; n < Iterations; n++) {
boxFold(z, dr); // Reflect
sphereFold(z, dr); // Sphere Inversion
z = kadoScale * z + offset; // Scale & Translate
dr = dr * abs(kadoScale) + 1.0;
}
float r = length(z);
return r / abs(dr);
}
float dMandel(float3 p, float scale, int n) {
float4 q0 = float4 (p, 1.0);
float4 q = q0;
for (int i = 0; i < n; i++) {
q.xyz = clamp(q.xyz, -1.0, 1.0) * 2.0 - q.xyz;
q = q * scale / clamp(dot(q.xyz, q.xyz), 0.5, 1.0) + q0;
}
return length(q.xyz) / abs(q.w);
}
ܰྔԽ
※GLSL
※HLSL
ҰൠԽ͞Εͨܗ͔ࣜΒύϥϝʔλ
ൣғʹ੍ݶΛ͚ͭͯॲཧΛ؆ུԽ