public void ShouldHaveConstantNormal(float x, float y, float z) { var p = new XZPlane(); var n = p.GetLocalNormalAt(CreatePoint(x, y, z)); AssertActualEqualToExpected(n, CreateVector(0, 1, 0)); }
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 ShouldNotIntersectWithParallelRay(float x, float y, float z) { var p = new XZPlane(); var r = CreateRay(CreatePoint(x, y, z), CreateVector(0, 0, 1)); var xs = p.LocalIntersect(r); xs.Should().BeEmpty(); }
public void ShouldIntersectWithPerpendicularRay(float px, float py, float pz, float vx, float vy, float vz) { var p = new XZPlane(); var r = CreateRay(CreatePoint(px, py, pz), CreateVector(vx, vy, vz)); var xs = p.LocalIntersect(r); xs.Should().ContainSingle().And.Subject.First().T.Should().Be(1); xs.First().Shape.Should().Be(p); }
public void ShouldPrecomputeReflectionVector() { var shape = new XZPlane(); var r = CreateRay(CreatePoint(0, 1, -1), CreateVector(0, -Sqrt(2) / 2, Sqrt(2) / 2)); var i = new Intersection(Sqrt(2), shape); var comps = Computations.Prepare(i, r); AssertActualEqualToExpected(comps.ReflectV, CreateVector(0, Sqrt(2) / 2, Sqrt(2) / 2)); }
public void ShouldComputeColorForReflectiveMaterialAtMaximumRecursiveDepth() { 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.ComputeReflectedColor(comps, 0); AssertActualEqualToExpected(color, VColor.Black); }
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 static World CreateTestWorld() { var floor = new XZPlane("floor") { Material = { Pattern = new CheckerPattern(VColor.LinearRGB(1, 0.5f, 0.5f), VColor.Red) { Transform = CreateScale(2, 2, 2) * CreateShear(0,1, 0, 0, 0, 0) }, Specular = 0, Reflective = 0.1f, }, }; var water = new XZPlane("water") { Transform = CreateTranslation(0, 0.25f, 0), Material = { Color = VColor.LinearRGB(0, 0, 0.1f), Reflective = 0.4f, RefractiveIndex = 1.7f, Transparency = 0.9f, } }; var rightWall = new XZPlane("right wall") { Transform = CreateRotationZ(-MathF.PI / 2) * CreateTranslation(5, 0, 0), Material = { Pattern = new RingPattern(VColor.Green, VColor.White), Specular = 0, }, }; var leftWall = new XZPlane("left wall") { Transform = CreateRotationX(MathF.PI / 2) * CreateTranslation(0, 0, 5), Material = { Pattern = new StripePattern(VColor.Blue, VColor.LinearRGB(0.5f, 0.5f, 1)), Specular = 0, }, }; var middle = new Sphere("middle") { Transform = CreateTranslation(-0.5f, 1, 0.5f), Material = { Pattern = new GradientPattern(VColor.LinearRGB(0.1f, 1, 0.5f), VColor.SRGB(1, 0.5f, 0)) { Transform = CreateScale(2, 1, 1) * CreateTranslation(1, 0, 0), }, Diffuse = 0.7f, Specular = 0.3f, Reflective = 0.05f, Transparency = 0.3f, RefractiveIndex = 1.5f, } }; var right = Sphere.CreateGlass("right"); right.Transform = CreateScale(0.5f, 0.5f, 0.5f) * CreateTranslation(1.5f, 0.5f, -0.5f); right.Material.Color = VColor.Black; var left = new Cone("left") { Closed = true, Minimum = -1, Maximum = 1, Transform = CreateScale(0.33f, 1, 0.33f) * CreateTranslation(-1.5f, 1, -0.75f), Material = { Color = VColor.White, //Ambient = 0.1f, //Diffuse = 0.4f, //Specular = 0, } }; return(new World { Objects = { floor, water, rightWall, leftWall, middle, right, left, }, Lights = { new PointLight(CreatePoint(-10, 10, -10), VColor.LinearRGB(0.3f, 0.3f, 0.3f)), new PointLight(CreatePoint(0, 10, -10), VColor.LinearRGB(0.3f, 0.3f, 0.3f)), new PointLight(CreatePoint(3, 10, -10), VColor.LinearRGB(0.3f, 0.3f, 0.3f)), }, }); }