Example #1
0
        public BVHNode(Hitable[] list, int low, int high, float t0, float t1)
        {
            if (low < 0 || high > list.Length)
            {
                throw new Exception("BVHNode Contruction error low <0 || high >list.Length");
            }
            int length = high - low;

            if (length <= 0)
            {
                throw new Exception("BVHNode Contruction error low >= high");
            }

            if (length == 1)
            {
                _left = _right = list[low];
                _box  = _left.BoundVolume(t0, t1);
            }
            else if (length == 2)
            {
                _left  = list[low];
                _right = list[low + 1];
                _box   = AABB.SurroundingBox(_left.BoundVolume(t0, t1), _right.BoundVolume(t0, t1));
            }
            else
            {
                Array.Sort(list, low, high - low, new BVHComparer((int)(3 * Exten.rand01())));
                int mid = (low + high) / 2;
                _left  = new BVHNode(list, low, mid, t0, t1);
                _right = new BVHNode(list, mid, high, t0, t1);
                _box   = AABB.SurroundingBox(_left.BoundVolume(t0, t1), _right.BoundVolume(t0, t1));
            }
        }
Example #2
0
            static int CmpBVH(Hitable left, Hitable right, int idx)
            {
                var ab1 = left.BoundVolume(0, 1);
                var ab2 = right.BoundVolume(0, 1);

                return((int)(ab1._max[idx] - ab2._min[idx]));
            }
Example #3
0
 public AABB BoundVolume(float t0, float t1)
 {
     return(_inner.BoundVolume(t0, t1));
 }
Example #4
0
        public AABB BoundVolume(float t0, float t1)
        {
            var b = _inner.BoundVolume(t0, t1);

            return(new AABB(b._min + _offset, b._max + _offset));
        }