public void ShouldShadeHitWithReflectiveTransparentMaterial() { var w = World.CreateDefault(); var floorPlane = new XZPlane { Transform = CreateTranslation(0, -1, 0), Material = { Reflective = 0.5f, Transparency = 0.5f, RefractiveIndex = 1.5f, } }; w.Objects.Add(floorPlane); var ball = new Sphere { Material = { Color = VColor.LinearRGB(1, 0, 0), Ambient = 0.5f, }, Transform = CreateTranslation(0, -3.5f, -0.5f), }; w.Objects.Add(ball); var r = new Ray(CreatePoint(0, 0, -3), CreateVector(0, -Sqrt(2) / 2, Sqrt(2) / 2)); var xs = Intersection.CreateList((Sqrt(2), floorPlane)); var comps = Computations.Prepare(xs[0], r, xs); var color = w.ShadeHit(comps, 5); AssertActualEqualToExpected(color, VColor.LinearRGB(0.93391f, 0.69643f, 0.69243f)); }
public void ShouldCreateDefaultWorld() { var light = new PointLight(CreatePoint(-10, 10, -10), VColor.White); var s1 = new Sphere { Material = { Color = VColor.LinearRGB(0.8f, 1, 0.6f), Diffuse = 0.7f, Specular = 0.2f, } }; var s2 = new Sphere { Transform = CreateScale(0.5f, 0.5f, 0.5f), }; var w = World.CreateDefault(); w.Lights.Should().Contain(light); w.Objects.Count.Should().Be(2); w.Objects[0].Material.Should().Be(s1.Material); w.Objects[0].Transform.Should().Be(s1.Transform); w.Objects[1].Material.Should().Be(s2.Material); w.Objects[1].Transform.Should().Be(s2.Transform); }
public void ShouldLinearlyInterpolateColorsInGradientPattern(float x) { var pattern = new GradientPattern(VColor.White, VColor.Black); AssertActualEqualToExpected( pattern.GetColorAt(CreatePoint(x, 0, 0)), VColor.LinearRGB(1 - x, 1 - x, 1 - x)); }
public void ShouldComputeColorWhenRayHits() { var w = World.CreateDefault(); var r = CreateRay(CreatePoint(0, 0, -5), CreateVector(0, 0, 1)); var c = w.ComputeColor(r); AssertActualEqualToExpected(c, VColor.LinearRGB(0.38066f, 0.47583f, 0.2855f)); }
public void ShouldShadeIntersection() { var w = World.CreateDefault(); var r = CreateRay(CreatePoint(0, 0, -5), CreateVector(0, 0, 1)); var shape = w.Objects.First(); var i = new Intersection(4, shape); var comps = Computations.Prepare(i, r); var c = w.ShadeHit(comps); AssertActualEqualToExpected(c, VColor.LinearRGB(0.38066f, 0.47583f, 0.2855f)); }
public void ShouldComputeLightingWithEyeBetweenLightAndSurface() { var m = new Material(); var p = CreatePoint(0, 0, 0); var eye = CreateVector(0, 0, -1); var normalY = CreateVector(0, 0, -1); var light = new PointLight(CreatePoint(0, 0, -10), VColor.White); var result = m.ComputeColor(light, new Sphere(), p, eye, normalY); AssertActualEqualToExpected(result, VColor.LinearRGB(1.9f, 1.9f, 1.9f)); }
public void ShouldComputeLightingWithSurfaceInShadow() { var m = new Material(); var p = CreatePoint(0, 0, 0); var eye = CreateVector(0, 0, -1); var normal = CreateVector(0, 0, -1); var light = new PointLight(CreatePoint(0, 0, -10), VColor.White); var result = m.ComputeColor(light, new Sphere(), p, eye, normal, inShadow: true); AssertActualEqualToExpected(result, VColor.LinearRGB(0.1f, 0.1f, 0.1f)); }
public void ShouldComputeLightingWithEyeInPathOfReflectionVector() { var m = new Material(); var p = CreatePoint(0, 0, 0); var eye = CreateVector(0, -Sqrt(2) / 2, -Sqrt(2) / 2); var normalY = CreateVector(0, 0, -1); var light = new PointLight(CreatePoint(0, 10, -10), VColor.White); var result = m.ComputeColor(light, new Sphere(), p, eye, normalY); AssertActualEqualToExpected(result, VColor.LinearRGB(1.6364f, 1.6364f, 1.6364f)); }
public void ShouldComputeLightingWithEyeOppositeSurfaceWithLightOffset45Degrees() { var m = new Material(); var p = CreatePoint(0, 0, 0); var eye = CreateVector(0, 0, -1); var normalY = CreateVector(0, 0, -1); var light = new PointLight(CreatePoint(0, 10, -10), VColor.White); var result = m.ComputeColor(light, new Sphere(), p, eye, normalY); AssertActualEqualToExpected(result, VColor.LinearRGB(0.7364f, 0.7364f, 0.7364f)); }
public void ShouldShadeIntersectionFromTheInside() { var w = World.CreateDefault(); w.Lights[0] = new PointLight(CreatePoint(0, 0.25f, 0), VColor.White); var r = CreateRay(CreatePoint(0, 0, 0), CreateVector(0, 0, 1)); var shape = w.Objects[1]; var i = new Intersection(0.5f, shape); var comps = Computations.Prepare(i, r); var c = w.ShadeHit(comps); AssertActualEqualToExpected(c, VColor.LinearRGB(0.90498f, 0.90498f, 0.90498f)); }
public void ShouldComputeColorForReflectiveMaterial() { var w = World.CreateDefault(); var shape = new XZPlane { Material = { Reflective = 0.5f }, Transform = CreateTranslation(0, -1, 0), }; w.Objects.Add(shape); var r = CreateRay(CreatePoint(0, 0, -3), CreateVector(0, -Sqrt(2) / 2, Sqrt(2) / 2)); var i = new Intersection(Sqrt(2), shape); var comps = Computations.Prepare(i, r); var color = w.ShadeHit(comps, 4); AssertActualEqualToExpected(color, VColor.LinearRGB(0.87677f, 0.92436f, 0.82918f)); }
public void ShouldComputeRefractedColorWithRefractedRay() { var w = World.CreateDefault(); var a = w.Objects.First(); a.Material.Ambient = 1; a.Material.Pattern = new TestPattern(); var b = w.Objects[1]; b.Material.Transparency = 1; b.Material.RefractiveIndex = 1.5f; var r = new Ray(CreatePoint(0, 0, 0.1f), CreateVector(0, 1, 0)); var xs = Intersection.CreateList((-0.9899f, a), (-0.4899f, b), (0.4899f, b), (0.9899f, a)); var comps = Computations.Prepare(xs[2], r, xs); var c = w.ComputeRefractedColor(comps, 5); AssertActualEqualToExpected(c, VColor.LinearRGB(0, 0.99888f, 0.04725f)); }
public void ShouldShowShadeIntersectionInShadow() { var w = new World { Lights = { new PointLight(CreatePoint(0, 0, -10), VColor.White) }, Objects = { new Sphere(), new Sphere { Transform = CreateTranslation(0, 0, 10) }, } }; var r = CreateRay(CreatePoint(0, 0, 5), CreateVector(0, 0, 1)); var i = new Intersection(4, w.Objects[1]); var comps = Computations.Prepare(i, r); var c = w.ShadeHit(comps); AssertActualEqualToExpected(c, VColor.LinearRGB(0.1f, 0.1f, 0.1f)); }
public override Vector4 GetColorAt(Vector4 point) => VColor.LinearRGB(point.X, point.Y, point.Z);