public void RefractedColorWithRefractedRay() { var w = new DefaultWorld(); var a = w.Objects[0]; a.Material.Ambient = 1.0; a.Material.Pattern = new TestPattern(); var b = w.Objects[1]; b.Material.Transparency = 1.0; b.Material.RefractiveIndex = 1.5; var r = new Ray( Vector4.CreatePosition(0, 0, 0.1), Vector4.CreateDirection(0, 1, 0)); var xs = IntersectionList.Create( new Intersection(-0.9899, a), new Intersection(-0.4899, b), new Intersection(0.4899, b), new Intersection(0.9899, a)); var comps = xs[2].Precompute(r, xs); var c = w.GetRefractedColor(comps, 5); var expected = new Color(0, 0.99888, 0.04725); const double eps = 0.0001; var comparer = Color.GetEqualityComparer(eps); Assert.Equal(expected, c, comparer); }
public void RefractedColorWithOpaqueSurface() { var w = new DefaultWorld(); var shape = w.Objects[0]; var r = new Ray(Vector4.CreatePosition(0, 0, -5), Vector4.CreateDirection(0, 0, 1)); var xs = IntersectionList.Create( new Intersection(4, shape), new Intersection(6, shape)); var comps = xs[0].Precompute(r, xs); var c = w.GetRefractedColor(comps, 5); Assert.Equal(Color.Black, c); }
public void RefractedColorUnderTotalInternalReflection() { var w = new DefaultWorld(); var shape = w.Objects[0]; shape.Material.Transparency = 1.0; shape.Material.RefractiveIndex = 1.5; var r = new Ray( Vector4.CreatePosition(0, 0, Math.Sqrt(2) / 2), Vector4.CreateDirection(0, 1, 0)); var xs = IntersectionList.Create( new Intersection(-Math.Sqrt(2) / 2, shape), new Intersection(Math.Sqrt(2) / 2, shape)); var comps = xs[1].Precompute(r, xs); var c = w.GetRefractedColor(comps, 5); Assert.Equal(Color.Black, c); }
public void RefractedColorAtMaxRecursiveDepth() { var w = new DefaultWorld(); var shape = w.Objects[0]; shape.Material.Transparency = 1.0; shape.Material.RefractiveIndex = 1.5; var r = new Ray( Vector4.CreatePosition(0, 0, -5), Vector4.CreateDirection(0, 0, 1)); var xs = IntersectionList.Create( new Intersection(4, shape), new Intersection(6, shape)); var comps = xs[0].Precompute(r, xs); var c = w.GetRefractedColor(comps, 0); Assert.Equal(Color.Black, c); }