Exemple #1
0
        static void Main(string[] args)
        {
            ICamera camera = new PerspectiveCamera(45);
            Film film = new Film(500, 500);

            Scene scene = new Scene();
            Light light = new Light(new Color(10, 10, 10));
            light.Transform(new Transformation().Translate(1.5f, 0, -1.5f));
            scene.Lights.Add(light);
            Image texImage = Image.FromFile(@"C:\Users\tom.swedlund\Documents\src\images\test-image2.png");
            IShape shape = new SphereShape(0.2f, new LambertianBRDF(), new ImageTexture(texImage));
            shape.Transform(new Transformation().Translate(0.2f, -0.2f, 0.4f));
            scene.Shapes.Add(shape);
            shape = new PlaneShape(new LambertianBRDF(), null);
            shape.Transform(new Transformation().Scale(1.2f, 1.2f, 1.2f).Translate(0, 0, 1).Rotate(45, 1, 0, 0));
            scene.Shapes.Add(shape);

            Image image = Renderer.Render(scene, camera, film);
            image.Save(@"image.bmp");
        }
Exemple #2
0
 public static Image Render(Scene scene, ICamera camera, Film film)
 {
     float halfWidth = film.Width / 2;
     float halfHeight = film.Height / 2;
     IIntegrator integrator = new DirectIntegrator();
     for (int x = 0; x < film.Width; ++x)
     {
         for (int y = 0; y < film.Height; ++y)
         {
             // Transform image->space to camera space
             Math.Point rayOrigin = new Math.Point()
             {
                 X = (x - halfWidth) / film.Width,
                 Y = -(y - halfHeight) / film.Width,
                 Z = 0
             };
             Ray ray = camera.GenerateRay(rayOrigin);
             film[x, y] = integrator.Integrate(ray, scene);
         }
     }
     return film.ToImage();
 }