Beispiel #1
0
        Hit IShape.Intersect(Ray ray)
        {
            (double tmin, double tmax) = Box.Intersect(ray);
            double step  = 1.0 / 512;
            double start = Math.Max(step, tmin);
            int    sign  = -1;

            for (double t = start; t <= tmax; t += step)
            {
                Vector p = ray.Position(t);
                int    s = Sign(p);

                if (s == 0 || (sign >= 0 && s != sign))
                {
                    t    -= step;
                    step /= 64;
                    t    += step;
                    for (int i = 0; i < 64; i++)
                    {
                        if (Sign(ray.Position(t)) == 0)
                        {
                            return(new Hit(this, t - step, null));
                        }
                        t += step;
                    }
                }
                sign = s;
            }
            return(Hit.NoHit);
        }
Beispiel #2
0
        internal Hit Intersect(Ray r)
        {
            (double tmin, double tmax) = Box.Intersect(r);

            if (tmax < tmin || tmax <= 0)
            {
                return(Hit.NoHit);
            }
            return(Root.Intersect(r, tmin, tmax));
        }
Beispiel #3
0
        Hit IShape.Intersect(Ray ray)
        {
            double epsilon  = 0.00001;
            double start    = 0.0001;
            double jumpSize = 0.001;
            Box    box      = BoundingBox();

            (double t1, double t2) = box.Intersect(ray);
            if (t2 < t1 || t2 < 0)
            {
                return(Hit.NoHit);
            }
            double t    = Math.Max(start, t1);
            bool   jump = true;

            for (int i = 0; i < 1000; i++)
            {
                var d = Evaluate(ray.Position(t));
                if (jump && d < 0)
                {
                    t   -= jumpSize;
                    jump = false;
                    continue;
                }

                if (d < epsilon)
                {
                    return(new Hit(this, t, null));
                }

                if (jump && d < jumpSize)
                {
                    d = jumpSize;
                }

                t += d;

                if (t > t2)
                {
                    return(Hit.NoHit);
                }
            }
            return(Hit.NoHit);
        }