public void ShadeWithReflectiveTransparentMaterial() { var w = new DefaultWorld(); var r = new Ray( Vector4.CreatePosition(0, 0, -3), Vector4.CreateDirection(0, -Math.Sqrt(2) / 2, Math.Sqrt(2) / 2)); var floor = new Plane(); floor.Transform = Transform.Translate(0, -1, 0); floor.Material.Reflective = 0.5; floor.Material.Transparency = 0.5; floor.Material.RefractiveIndex = 1.5; var ball = new Sphere(); ball.Transform = Transform.Translate(0, -3.5, -0.5); ball.Material.Color = new Color(1, 0, 0); ball.Material.Ambient = 0.5; w.Objects.Add(floor); w.Objects.Add(ball); var xs = IntersectionList.Create( new Intersection(Math.Sqrt(2), floor)); var comps = xs[0].Precompute(r, xs); var c = w.Render(comps, 5); var expected = new Color(0.93391, 0.69643, 0.69243); const double eps = 0.00001; var comparer = Color.GetEqualityComparer(eps); Assert.Equal(expected, c, comparer); }
public void TestShadingAnIntersection() { var w = new DefaultWorld(); var r = new Ray(Vector4.CreatePosition(0, 0, -5), Vector4.CreateDirection(0, 0, 1)); var shape = w.Objects[0]; var i = new Intersection(4, shape); var comps = i.Precompute(r); var c = w.Render(comps, 5); var expected = new Color(0.38066, 0.47583, 0.2855); const double eps = 0.00001; var comparer = Color.GetEqualityComparer(eps); Assert.Equal(expected, c, comparer); }
public void TestShadingAnIntersectionFromTheInside() { var w = new DefaultWorld(); w.Lights.Clear(); w.Lights.Add(new PointLight(Vector4.CreatePosition(0, 0.25, 0), Color.White)); var r = new Ray(Vector4.CreatePosition(0, 0, 0), Vector4.CreateDirection(0, 0, 1)); var shape = w.Objects[1]; var i = new Intersection(0.5, shape); var comps = i.Precompute(r); var c = w.Render(comps, 5); var expected = new Color(0.90498, 0.90498, 0.90498); const double eps = 0.00001; var comparer = Color.GetEqualityComparer(eps); Assert.Equal(expected, c, comparer); }
public void ShadeWithReflectiveMaterial() { var w = new DefaultWorld(); var plane = new Plane(); plane.Material.Reflective = 0.5; plane.Transform = Transform.Translate(0, -1, 0); w.Objects.Add(plane); var r = new Ray( Vector4.CreatePosition(0, 0, -3), Vector4.CreateDirection(0, -Math.Sqrt(2) / 2, Math.Sqrt(2) / 2)); var i = new Intersection(Math.Sqrt(2), plane); var comps = i.Precompute(r); var c = w.Render(comps, 5); var expected = new Color(0.87677, 0.92436, 0.82918); const double eps = 0.0001; var comparer = Color.GetEqualityComparer(eps); Assert.Equal(expected, c, comparer); }