Exemplo n.º 1
0
 public Intersection(Intersectable intersectsWith, Ray ray, Vector3 surfaceNormal, Vector3 location, float distance, Material material)
 {
     IntersectsWith = intersectsWith;
     Ray = ray;
     SurfaceNormal = surfaceNormal;
     Location = location;
     Distance = distance;
     Material = material;
 }
Exemplo n.º 2
0
 public static bool DoesIntersect(Ray ray, IEnumerable<Intersectable> intersectables, Intersectable ignore = null)
 {
     foreach (var obj in intersectables)
     {
         //if (obj is DebugSphere)
         //{
         //    continue;
         //}
         Intersection intersection;
         if (obj != ignore && obj.Intersect(ray, out intersection))// && !ReferenceEquals(ray.OriginPrimitive, obj))
         {
             return true;
         }
     }
     return false;
 }
Exemplo n.º 3
0
        public Color3 Sample(Scene scene, Ray ray, RNG rng, bool ignoreLight)
        {
            if (ray.BouncesLeft < 1)
            {
                return Color4.Black;
            }

            //get nearest intersection
            var intersection = IntersectionHelper.GetClosestIntersection(ray, scene.Objects);
            if (intersection == null)
            {
                return scene.Skybox.Intersect(ray.Direction);
            }

            var lightingModel = new MonteCarloLightingModel(scene, rng, nee: true, cosineDist: true, russianRoulette: false);
            return lightingModel.Calculate(intersection, ignoreLight);
        }
Exemplo n.º 4
0
        public Color3 Sample(Scene scene, Ray ray, RNG random, bool ignoreLight)
        {
            //Debug.Assert(scene.BVH != null);

            if (ray.BouncesLeft < 1)
            {
                return Color4.Red;
            }

            //get nearest intersection
            var intersection = IntersectionHelper.GetClosestIntersection(ray, scene.Objects);
            if (intersection == null)
            {
                return scene.Skybox.Intersect(ray.Direction);
            }

            var lightingModel = new WhittedStyleLightingModel(scene, random);
            return lightingModel.Calculate(intersection);
        }
Exemplo n.º 5
0
        public static Intersection GetClosestIntersection(Ray ray, IEnumerable<Intersectable> intersectables)
        {
            float closestDistance = float.MaxValue;
            Intersection closestIntersection = null;
            foreach (var obj in intersectables)
            {
                Intersection intersection;
                if (obj.Intersect(ray, out intersection))// && !ReferenceEquals(ray.OriginPrimitive, obj))
                {
                    if (intersection.Distance < closestDistance)
                    {
                        closestDistance = intersection.Distance;
                        closestIntersection = intersection;
                    }
                }
            }

            return closestIntersection;
        }
Exemplo n.º 6
0
        public bool Intersect(Ray ray, out Intersection intersection)
        {
            intersection = null;
            var nodes = new Stack<BVHNode>(_logNumBoundables);
            nodes.Push(Root);
            while (nodes.Count > 0)
            {
                var node = nodes.Pop();
                if (node.IsLeaf)
                {
                    var i = IntersectionHelper.GetClosestIntersection(ray, node.Boundables);
                    intersection = IntersectionHelper.GetMinimumIntersection(intersection, i);
                }

                Intersection i1 = null, i2 = null;
                float t1 = float.MaxValue, t2 = float.MaxValue;
                var goLeft = node._left != null && node._left.BoundingBox.Intersect(ray, out t1);
                var goRight = node._right != null && node._right.BoundingBox.Intersect(ray, out t2);

                if (goLeft && goRight)
                {
                    //choose shortest
                    if (t1 < t2)
                    {
                        nodes.Push(node._right);
                        nodes.Push(node._left);
                    }
                    else
                    {
                        nodes.Push(node._left);
                        nodes.Push(node._right);
                    }
                }
                else if (goLeft)
                {
                    nodes.Push(node._left);
                }
                else if (goRight)
                {
                    nodes.Push(node._right);
                }
            }

            return intersection != null;
        }
Exemplo n.º 7
0
 public Intersection(Intersectable intersectsWith, Ray ray, Vector3 surfaceNormal, Vector3 location,
     float distance, Material material, bool insidePrimitive)
     : this(intersectsWith, ray, surfaceNormal, location, distance, material)
 {
     InsidePrimitive = insidePrimitive;
 }
Exemplo n.º 8
0
        public bool Intersect(Ray ray, out float t)
        {
            float tmin = float.NegativeInfinity, tmax = float.PositiveInfinity;

            var t1 = (Min.X - ray.Origin.X)*ray.InverseDirection.X;
            var t2 = (Max.X - ray.Origin.X)*ray.InverseDirection.X;

            tmin = Math.Max(tmin, Math.Min(t1, t2));
            tmax = Math.Min(tmax, Math.Max(t1, t2));

            t1 = (Min.Y - ray.Origin.Y) * ray.InverseDirection.Y;
            t2 = (Max.Y - ray.Origin.Y) * ray.InverseDirection.Y;

            tmin = Math.Max(tmin, Math.Min(t1, t2));
            tmax = Math.Min(tmax, Math.Max(t1, t2));

            t1 = (Min.Z - ray.Origin.Z) * ray.InverseDirection.Z;
            t2 = (Max.Z - ray.Origin.Z) * ray.InverseDirection.Z;

            tmin = Math.Max(tmin, Math.Min(t1, t2));
            tmax = Math.Min(tmax, Math.Max(t1, t2));
            t = tmin;
            return tmax >= Math.Max(tmin, 0) && ray.T >= tmin; //todo klopt dit laatste?
        }
Exemplo n.º 9
0
Arquivo: Scene.cs Projeto: tincann/AGR
 public Color3 Sample(Ray ray, RNG random, bool ignoreLight)
 {
     return _tracer.Sample(this, ray, random, ignoreLight);
 }