public int FindFirstRay(RayBundle rayBundle, int rayIndexToStartCheckingFrom)
        {
            // check if first ray hits bounding box
            if (rayBundle.rayArray[rayIndexToStartCheckingFrom].Intersection(Aabb))
            {
                return(rayIndexToStartCheckingFrom);
            }

            int count = rayBundle.rayArray.Length;

            // check if all bundle misses
            if (!rayBundle.CheckIfBundleHitsAabb(Aabb))
            {
                return(-1);
            }

            // check each ray until one hits or all miss
            for (int i = rayIndexToStartCheckingFrom + 1; i < count; i++)
            {
                if (rayBundle.rayArray[i].Intersection(Aabb))
                {
                    return(i);
                }
            }

            return(-1);
        }
        public void GetClosestIntersections(RayBundle rayBundle, int rayIndexToStartCheckingFrom, IntersectInfo[] intersectionsForBundle)
        {
            var intersection = GetClosestIntersection(rayBundle.rayArray[rayIndexToStartCheckingFrom]);

            if (intersection == null)
            {
                intersectionsForBundle[rayIndexToStartCheckingFrom].hitType = IntersectionType.None;
            }
        }
Example #3
0
        public void TracePrimaryRayBundle(RayBundle rayBundle, IntersectInfo[] intersectionsForBundle, Scene scene)
        {
            if (scene.shapes.Count != 1)
            {
                throw new Exception("You can only trace a ray bundle into a single shape, usually a BoundingVolumeHierachy.");
            }

            scene.shapes[0].GetClosestIntersections(rayBundle, 0, intersectionsForBundle);
        }
        public void GetClosestIntersections(RayBundle rayBundle, int rayIndexToStartCheckingFrom, IntersectInfo[] intersectionsForBundle)
        {
            int startRayIndex = FindFirstRay(rayBundle, rayIndexToStartCheckingFrom);

            if (startRayIndex != -1)
            {
                IPrimitive checkFirst  = nodeA;
                IPrimitive checkSecond = nodeB;
                if (rayBundle.rayArray[startRayIndex].directionNormal[splittingPlane] < 0)
                {
                    checkFirst  = nodeB;
                    checkSecond = nodeA;
                }

                checkFirst.GetClosestIntersections(rayBundle, startRayIndex, intersectionsForBundle);
                if (checkSecond != null)
                {
                    checkSecond.GetClosestIntersections(rayBundle, startRayIndex, intersectionsForBundle);
                }
            }
        }
Example #5
0
 public void FullyTraceRayBundle(RayBundle rayBundle, IntersectInfo[] intersectionsForBundle, Scene scene)
 {
     TracePrimaryRayBundle(rayBundle, intersectionsForBundle, scene);
     for (int i = 0; i < rayBundle.rayArray.Length; i++)
     {
         try
         {
             IntersectInfo primaryInfo = TracePrimaryRay(rayBundle.rayArray[i], scene);
             if (intersectionsForBundle[i].HitType != IntersectionType.None)
             {
                 intersectionsForBundle[i].TotalColor = CreateAndTraceSecondaryRays(primaryInfo, rayBundle.rayArray[i], scene, 0);
             }
             else
             {
                 intersectionsForBundle[i].TotalColor = scene.background.Color;
             }
         }
         catch
         {
         }
     }
 }
Example #6
0
		public override int FindFirstRay(RayBundle rayBundle, int rayIndexToStartCheckingFrom)
		{
			throw new NotImplementedException();
		}
Example #7
0
        public void TracePrimaryRayBundle(RayBundle rayBundle, IntersectInfo[] intersectionsForBundle, Scene scene)
        {
            if (scene.shapes.Count != 1)
            {
                throw new Exception("You can only trace a ray bundle into a sigle shape, usually a BoundingVolumeHierachy.");
            }

            scene.shapes[0].GetClosestIntersections(rayBundle, 0, intersectionsForBundle);
        }
Example #8
0
 public virtual void GetClosestIntersections(RayBundle rayBundle, int rayIndexToStartCheckingFrom, IntersectInfo[] intersectionsForBundle)
 {
     throw new NotImplementedException("Implement this for the class you want.");
 }
Example #9
0
		public virtual void GetClosestIntersections(RayBundle rayBundle, int rayIndexToStartCheckingFrom, IntersectInfo[] intersectionsForBundle)
		{
			throw new NotImplementedException("Implement this for the class you want.");
		}
Example #10
0
		public abstract int FindFirstRay(RayBundle rayBundle, int rayIndexToStartCheckingFrom);
		public void GetClosestIntersections(RayBundle rayBundle, int rayIndexToStartCheckingFrom, IntersectInfo[] intersectionsForBundle)
		{
			int startRayIndex = FindFirstRay(rayBundle, rayIndexToStartCheckingFrom);
			if (startRayIndex != -1)
			{
				IPrimitive checkFirst = nodeA;
				IPrimitive checkSecond = nodeB;
				if (rayBundle.rayArray[startRayIndex].directionNormal[splitingPlane] < 0)
				{
					checkFirst = nodeB;
					checkSecond = nodeA;
				}

				checkFirst.GetClosestIntersections(rayBundle, startRayIndex, intersectionsForBundle);
				if (checkSecond != null)
				{
					checkSecond.GetClosestIntersections(rayBundle, startRayIndex, intersectionsForBundle);
				}
			}
		}
		public int FindFirstRay(RayBundle rayBundle, int rayIndexToStartCheckingFrom)
		{
			// check if first ray hits bounding box
			if (rayBundle.rayArray[rayIndexToStartCheckingFrom].Intersection(Aabb))
			{
				return rayIndexToStartCheckingFrom;
			}

			int count = rayBundle.rayArray.Length;
			// check if all bundle misses
			if (!rayBundle.CheckIfBundleHitsAabb(Aabb))
			{
				return -1;
			}

			// check each ray until one hits or all miss
			for (int i = rayIndexToStartCheckingFrom + 1; i < count; i++)
			{
				if (rayBundle.rayArray[i].Intersection(Aabb))
				{
					return i;
				}
			}

			return -1;
		}
		public void GetClosestIntersections(RayBundle rayBundle, int rayIndexToStartCheckingFrom, IntersectInfo[] intersectionsForBundle)
		{
			intersectionsForBundle[rayIndexToStartCheckingFrom] = GetClosestIntersection(rayBundle.rayArray[rayIndexToStartCheckingFrom]);
		}
Example #14
0
		public override void GetClosestIntersections(RayBundle rayBundle, int rayIndexToStartCheckingFrom, IntersectInfo[] intersectionsForBundle)
		{
			throw new NotImplementedException();
		}
Example #15
0
 public void GetClosestIntersections(RayBundle rayBundle, int rayIndexToStartCheckingFrom, IntersectInfo[] intersectionsForBundle)
 {
     intersectionsForBundle[rayIndexToStartCheckingFrom] = GetClosestIntersection(rayBundle.rayArray[rayIndexToStartCheckingFrom]);
 }
Example #16
0
 public abstract int FindFirstRay(RayBundle rayBundle, int rayIndexToStartCheckingFrom);
Example #17
0
 public override void GetClosestIntersections(RayBundle rayBundle, int rayIndexToStartCheckingFrom, IntersectInfo[] intersectionsForBundle)
 {
     throw new NotImplementedException();
 }
Example #18
0
 public override int FindFirstRay(RayBundle rayBundle, int rayIndexToStartCheckingFrom)
 {
     throw new NotImplementedException();
 }
Example #19
0
        public void FullyTraceRayBundle(RayBundle rayBundle, IntersectInfo[] intersectionsForBundle, Scene scene)
        {
            TracePrimaryRayBundle(rayBundle, intersectionsForBundle, scene);
            for (int i = 0; i < rayBundle.rayArray.Length; i++)
            {
                IntersectInfo primaryInfo = TracePrimaryRay(rayBundle.rayArray[i], scene);
                if (intersectionsForBundle[i].hitType != IntersectionType.None)
                {
                    intersectionsForBundle[i].totalColor = CreateAndTraceSecondaryRays(primaryInfo, rayBundle.rayArray[i], scene, 0);
                }

                intersectionsForBundle[i].totalColor = scene.background.Color;
            }
        }