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 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 TestDefaultWorld() { var light = new PointLight( Vector4.CreatePosition(-10, 10, -10), Color.White); var s1 = new Sphere { Material = new Material { Color = new Color(0.8, 1.0, 0.6), Diffuse = 0.7, Specular = 0.2, }, }; var s2 = new Sphere { Transform = Transform.Scale(0.5, 0.5, 0.5), }; var w = new DefaultWorld(); Assert.Contains(light, w.Lights); Assert.Contains(s1, w.Objects); Assert.Contains(s2, w.Objects); }
public void AreaLightWithJitteredSamples( double px, double py, double pz, double result) { var w = new DefaultWorld(); var corner = Vector4.CreatePosition(-0.5, -0.5, -5); var v1 = Vector4.CreateDirection(1, 0, 0); var v2 = Vector4.CreateDirection(0, 1, 0); var light = new AreaLight( corner, v1, 2, v2, 2, Color.White) { Jitter = new Sequence(0.7, 0.3, 0.9, 0.1, 0.5), }; var pt = Vector4.CreatePosition(px, py, pz); var intensity = light.GetIntensity(pt, w); Assert.Equal(result, intensity); }
public void LightingUsesLightIntensityToAttenuateColor( double intensity, double r, double g, double b) { var w = new DefaultWorld(); w.Lights = new ILight[] { new PointLight(Vector4.CreatePosition(0, 0, -10), Color.White), }; var shape = w.Objects[0]; shape.Material.Ambient = 0.1; shape.Material.Diffuse = 0.9; shape.Material.Specular = 0; shape.Material.Color = new Color(1, 1, 1); var pt = Vector4.CreatePosition(0, 0, -1); var eyev = Vector4.CreateDirection(0, 0, -1); var normalv = Vector4.CreateDirection(0, 0, -1); var result = shape.Material.Li( shape, w.Lights[0], pt, eyev, normalv, intensity); var expected = new Color(r, g, b); Assert.Equal(expected, result); }
public void TestColorWhenRayMisses() { var w = new DefaultWorld(); var r = new Ray(Vector4.CreatePosition(0, 0, -5), Vector4.CreateDirection(0, 1, 0)); var c = w.Trace(r, 5); Assert.Equal(Color.Black, c); }
public void TestColorWhenRayHits() { var w = new DefaultWorld(); var r = new Ray(Vector4.CreatePosition(0, 0, -5), Vector4.CreateDirection(0, 0, 1)); var c = w.Trace(r, 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 TestIntersectWorldWithRay() { var w = new DefaultWorld(); var r = new Ray(Vector4.CreatePosition(0, 0, -5), Vector4.CreateDirection(0, 0, 1)); var xs = w.Intersect(r); Assert.Equal(4, xs.Count); Assert.Equal(4, xs[0].T); Assert.Equal(4.5, xs[1].T); Assert.Equal(5.5, xs[2].T); Assert.Equal(6, xs[3].T); }
public void IsShadowTestsForOcclusionBetweenTwoPoints( double px, double py, double pz, bool result) { var w = new DefaultWorld(); var lightPosition = Vector4.CreatePosition(-10, -10, -10); var point = Vector4.CreatePosition(px, py, pz); Assert.Equal(result, w.IsShadowed(lightPosition, point)); }
public void PointLightsEvaluateLightIntensityAtGivenPoint( double px, double py, double pz, double result) { var w = new DefaultWorld(); var light = w.Lights[0]; var pt = Vector4.CreatePosition(px, py, pz); var intensity = light.GetIntensity(pt, w); Assert.Equal(result, intensity); }
public void ReflectedColorForNonReflectiveMaterial() { var w = new DefaultWorld(); var r = new Ray(Vector4.CreatePosition(0, 0, 0), Vector4.CreateDirection(0, 0, 1)); var shape = w.Objects[1]; shape.Material.Ambient = 1; var i = new Intersection(1, shape); var comps = i.Precompute(r); var c = w.GetReflectedColor(comps, 5); Assert.Equal(Color.Black, c); }
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 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 TestColorWithIntersectionBehindRay() { var w = new DefaultWorld(); var outer = w.Objects[0]; outer.Material.Ambient = 1; var inner = w.Objects[1]; inner.Material.Ambient = 1; var r = new Ray(Vector4.CreatePosition(0, 0, 0.75), Vector4.CreateDirection(0, 0, -1)); var c = w.Trace(r, 5); const double eps = 0.00001; var comparer = Color.GetEqualityComparer(eps); Assert.Equal(inner.Material.Color, 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 ReflectedColorAtMaxRecursiveDepth() { 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.GetReflectedColor(comps, 0); Assert.Equal(Color.Black, c); }
public void RenderingWorldWithCamera() { var w = new DefaultWorld(); var from = Vector4.CreatePosition(0, 0, -5); var to = Vector4.CreatePosition(0, 0, 0); var up = Vector4.CreateDirection(0, 1, 0); var c = new Camera(11, 11, Math.PI / 2) { Transform = Transform.View(from, to, up), }; var img = c.Render(w); var actual = img[5, 5]; var expected = new Color(0.38066, 0.47583, 0.2855); const double epsilon = 0.0001; var comparer = Color.GetEqualityComparer(epsilon); Assert.Equal(expected, actual, 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); }
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); }
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 AreaLightIntensityFunction( double px, double py, double pz, double result) { var w = new DefaultWorld(); var corner = Vector4.CreatePosition(-0.5, -0.5, -5); var v1 = Vector4.CreateDirection(1, 0, 0); var v2 = Vector4.CreateDirection(0, 1, 0); var light = new AreaLight( corner, v1, 2, v2, 2, Color.White); var pt = Vector4.CreatePosition(px, py, pz); var intensity = light.GetIntensity(pt, w); Assert.Equal(result, intensity); }