After taking a look at the Mobius strip, I noticed its equation is really simple and tried to add it into my Raytracer.
I tried a "naive" way by simply generating N
triangles attached to each other to obtain the desired shape. While this approach works, the result it not really pretty:
(By the way I probably have an issue with my normals but I don't know where it comes from.)
I tried it with PovRay and the result was astonishing. Perfectly smooth strip made in a far far FAR smaller time than mine. I'm pretty sure Povray is well optimized but I also think it won't generate triangles like I did.
In case that might help, here is the actual code used (C++) :
float step = .1f;
float halW = 0.5f;
_facets.clear();
auto lambda = [this] (float v, float t) {
Vec_t p;
float cdv = Tools::Cos(2 * v);
float sdv = Tools::Sin(2 * v);
float ctv = Tools::Cos(v);
float stv = Tools::Sin(v);
float c = 2 + t * ctv;
p.x = c * cdv;
p.z = c * sdv;
p.y = t * stv;
return p;
};
for (float v = 0.f; v < Globals::PI; v += step)
{
if (v > Globals::PI)
v = Globals::PI;
for (float t = -halW; t < halW; t += step)
{
if (t > halW)
t = halW;
Vec3 p1 = lambda(v, t);
Vec3 p2 = lambda(v + step, t);
Vec3 p3 = lambda(v, t + step);
Vec3 p4 = lambda(v + step, t + step);
_facets.emplace_back(p1, p2, p3);
_facets.emplace_back(p3, p2, p4);
}
}
TL;DR
How can I handle parametric surfaces like this one in raytracing?
Edit After letting the above algorithm run for about 20 hours, I got a way prettier result (with 3 torsions instead of 1)
isInside
flag in the triangle intersection method. If it is true I then negate the normal vector. The flag is set ifdet < 0
using an intersection method I don't recall the name for now $\endgroup$