I just tried to improve the rendering speed using Quilez optimization and I get:
The (working) code I used for the images above was:
long double DistanceEstimators::CPPDE (D3Vec w) {
D3Vec z = w;
float wr = w.getLength();
float dr = 1.0;
int escape = 20;
int Power = 4;
//double Scale = 1;
// Iterate
for (int i = 0; i != 10 && wr < escape; i++) {
// extract polar coordinates
//float wr = std::sqrt(w * w);
float wo = std::acos(w.y / wr);
float wi = std::atan2(w.x, w.z);
dr = std::pow(wr, Power - 1) * Power * dr + 1;
// scale and rotate the point
wr = std::pow(wr, Power);
wo = wo * Power;
wi = wi * Power;
// convert back to cartesian coordinates
w.x = std::sin(wo) * std::sin(wi);
w.y = std::cos(wo);
w.z = std::sin(wo) * std::cos(wi);
w = w * wr;
// add starting point to new point
w = w + z;
wr = w.getLength();
// running derivative
//std::cout << "#step " << i << ": " << dr << std::endl;
}
// Back
return std::min(1.0, 0.5 * std::log(wr) * wr / dr);
}
And the one with Quilez optimization:
long double DistanceEstimators::CPPDE (D3Vec w) {
D3Vec c = w;
long double wr = w.getLength();
long double dr = 1.0;
int escape = 20;
int Power = 4;
//double Scale = 1;
// Iterate
for (int i = 0; i != 10 && wr < escape; i++) {
// running derivative
dr = std::pow(wr, Power - 1) * Power * dr + 1;
// quilez optimization
long double x = w.x; long double x2 = x*x; long double x4 = x2*x2;
long double y = w.y; long double y2 = y*y; long double y4 = y2*y2;
long double z = w.z; long double z2 = z*z; long double z4 = z2*z2;
long double k3 = x2 + z2;
long double k2 = 1.0L / std::sqrt(k3*k3*k3*k3*k3*k3*k3);
long double k1 = x4 + y4 + z4 - 6.0*y2*z2 - 6.0*x2*y2 + 2.0*z2*x2;
long double k4 = x2 - y2 + z2;
w.x = 64.0*x*y*z*(x2-z2)*k4*(x4-6.0*x2*z2+z4)*k1*k2;
w.y = -16.0*y2*k3*k4*k4 + k1*k1;
w.z = -8.0*y*k4*(x4*x4 - 28.0*x4*x2*z2 + 70.0*x4*z4 - 28.0*x2*z2*z4 + z4*z4)*k1*k2;
// scale w
wr = std::pow(wr, Power);
w = w * wr;
// add starting point to new point
w = w + c;
wr = w.getLength();
}
// Back
return std::min(1.0L, 0.5 * std::log(wr) * wr / dr);
}
I basically tried to insert the modification into the previous code. And checked that my vars are initialized in the correct order regarding previous code but there's a mistake.