Ejemplo n.º 1
0
        public void ShadeHit_ShouldShadeAnIntersection_WhenTheIntersectionPointIsInShadow()
        {
            // arrange
            var sut = new World
            {
                Lights = ImmutableArray.Create(new PointLight(new(0f, 0f, -10f), Color.White)),
                Shapes = ImmutableArray.Create <Shape>(
                    new Sphere(),
                    new Sphere {
                    Transform = Matrix4.Translation(0f, 0f, 10f)
                }
                    )
            };
            var computations = new IntersectionComputations(
                new Ray(new Point(0f, 0f, 5f), Vector.UnitZ),
                new Intersection(sut.Shapes[1], 4f)
                );

            // act
            var result = sut.ShadeHit(computations);

            // assert
            result.Should().Be(new Color(0.1f, 0.1f, 0.1f));
        }
    }
Ejemplo n.º 2
0
        public void Constructor_ShouldPreComputeIntersectionState_WhenIntersectionIsOnTheOutside()
        {
            // arrange
            var ray          = new Ray(new(0f, 0f, -5f), Vector.UnitZ);
            var intersection = new Intersection(new Sphere(), 4f);

            // act
            var result = new IntersectionComputations(ray, intersection);

            // assert
            using var _ = new AssertionScope();
            result.Shape.Should().BeSameAs(intersection.Shape);
            result.Time.Should().Be(intersection.Time);
            result.Point.Should().Be(new Point(0f, 0f, -1f));
            result.Eye.Should().Be(new Vector(0f, 0f, -1f));
            result.Normal.Should().Be(new Vector(0f, 0f, -1f));
            result.HitInside.Should().BeFalse();
        }
Ejemplo n.º 3
0
        public void Constructor_ShouldOffsetOverPointUsingTheSurfaceNormal()
        {
            // arrange
            var ray          = new Ray(new(0f, 0f, -5f), Vector.UnitZ);
            var intersection = new Intersection(
                new Sphere {
                Transform = Matrix4.Translation(0f, 0f, 1f)
            },
                5f
                );

            // act
            var result = new IntersectionComputations(ray, intersection);

            // assert
            using var _ = new AssertionScope();
            result.OverPoint.Z.Should().BeLessThan(-FloatExtensions.ComparisonEpsilon / 2f);
            result.Point.Z.Should().BeGreaterThan(result.OverPoint.Z);
        }
Ejemplo n.º 4
0
        public void ShadeHit_ShouldShadeAnIntersection_WhenTheIntersectionIsInsideTheShape()
        {
            // arrange
            var sut = World.Default with
            {
                Lights = ImmutableArray.Create(new PointLight(new(0f, 0.25f, 0f), Color.White))
            };
            var computations = new IntersectionComputations(
                new Ray(Point.Origin, Vector.UnitZ),
                new Intersection(sut.Shapes[1], 0.5f)
                );

            // act
            var result = sut.ShadeHit(computations);

            // assert
            using var _ = new AssertionScope();
            result.R.Should().BeApproximately(0.90498f, 1e-5f);
            result.G.Should().BeApproximately(0.90498f, 1e-5f);
            result.B.Should().BeApproximately(0.90498f, 1e-5f);
        }