Exemplo n.º 1
0
        public void ReflectionTest()
        {
            var image = new Image(100, 100);
            var scene = new Scene
            {
                Camera = new Camera(0, 0, 0)
                {
                    Direction   = Vector3.UnitZ,
                    FieldOfView = 90f,
                    Position    = Vector3.Zero
                }
            };

            var reflectiveSphere = new Sphere
            {
                Center   = new Vector3(0, 0, -10),
                Radius   = 2,
                Material = new BrdfMaterial
                {
                    Scene = scene
                }
            };

            var hollowSphere = new SphereHollow
            {
                Center   = Vector3.Zero,
                Radius   = 20,
                Material = new FullBright {
                    Color = Color.FromArgb(255, 0, 0)
                }
            };

            scene.RenderObjects = new List <IRenderObject>()
            {
                reflectiveSphere,
                hollowSphere
            };

            scene.Render(image);

            foreach (var(x, y, pixel) in image.PixelEnumerator())
            {
                Assert.Equal(1.0f, pixel.R);
            }
        }
Exemplo n.º 2
0
        public void Render(Image image)
        {
            foreach (var(x, y, _) in image.PixelEnumerator())
            {
                var primaryRay = Camera.RasterToPrimaryRay(image, x, y);

                var closestIntersection = Intersect(primaryRay);

                if (closestIntersection != null)
                {
                    var color = closestIntersection.RenderObject.Material.Render(closestIntersection);

                    image.PixelGrid[y, x] = new Pixel(color);
                }
                else
                {
                    image.PixelGrid[y, x] = Pixel.Black;
                }
            }
        }