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; }
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; }
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); }
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); }
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; }
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; }
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; }
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? }
public Color3 Sample(Ray ray, RNG random, bool ignoreLight) { return _tracer.Sample(this, ray, random, ignoreLight); }