Exemple #1
0
        public static SceneDescription ManySpheres()
        {
            var primitives = new List <Primitive>();

            for (var i = 0; i < 200; ++i)
            {
                var spectrum = new Spectrum(Random.Shared.NextSingle(), Random.Shared.NextSingle(), Random.Shared.NextSingle());

                Material material;
                if (Random.Shared.NextSingle() > 0.7)
                {
                    material = new MirrorMaterial(spectrum);
                }
                else
                {
                    //material = new MatteMaterial(spectrum, 0);
                    material = new PlasticMaterial(spectrum, new Spectrum(1), Random.Shared.NextSingle());
                }

                var transform = Transform.Translate(Random.Shared.NextSingle() * 2 - 1, Random.Shared.NextSingle() * 2 - 1, Random.Shared.NextSingle() * 2 - 1);
                var radius    = 0.1f + Random.Shared.NextSingle() * 0.1f;

                primitives.Add(new GeometricPrimitive(new Sphere(transform, radius), material));
            }

            var lights = new List <Light>();

            for (var i = 0; i < 5; ++i)
            {
                var transform = Transform.Translate(Random.Shared.NextSingle() * 2 - 1, Random.Shared.NextSingle() * 2 - 1, Random.Shared.NextSingle() * -3 - 5);
                var spectrum  = new Spectrum(Random.Shared.NextSingle() * 25 + 15);

                lights.Add(new PointLight(transform, spectrum));
            }

            return(new SceneDescription(new PrimitiveList(primitives), lights, OrthographicCamera.Create(new Point3 <float>(0, 0, -5))));
        }
Exemple #2
0
        private static IScene Build()
        {
            var white =
                new MatteMaterial(
                    new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 1f, 1f, 1f }, SpectrumType.Illuminant)),
                    new ConstantTexture <float>(0), null);

            var red =
                new PlasticMaterial(
                    new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 1f, 0f, 0f }, SpectrumType.Illuminant)),
                    new ConstantTexture <Spectrum>(new Spectrum(0.3f)),
                    new ConstantTexture <float>(0.0f),
                    null,
                    true);

            var yellow =
                new MatteMaterial(
                    new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 1f, 1f, 0f }, SpectrumType.Illuminant)),
                    new ConstantTexture <float>(0), null);

            var cyan =
                new MatteMaterial(
                    new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 0f, 1f, 1f }, SpectrumType.Illuminant)),
                    new ConstantTexture <float>(0), null);

            var metal =
                new MetalMaterial(
                    new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 0.8f, 0.8f, 0.8f }, SpectrumType.Illuminant)),
                    new ConstantTexture <Spectrum>(Spectrum.One),
                    new ConstantTexture <float>(0.01f), null, null, null, true);

            var mirror =
                new MirrorMaterial(
                    new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 0.8f, 0.8f, 0.8f }, SpectrumType.Illuminant)),
                    null);


            var s1t = Transform.Translate(278, 278, 100);
            var s1  = new Sphere(s1t, Transform.Invert(s1t), false, 100f, -100, 100, 360);
            var s1g = new GeometricPrimitive(s1, mirror, null);

            var s2t = Transform.Translate(340, 100, 80);
            var s2  = new Sphere(s2t, Transform.Invert(s2t), false, 120f, -120, 120, 360);
            var s2g = new GeometricPrimitive(s2, cyan, null);

            var s3t = Transform.Translate(0, 278, 200);
            var s3  = new Sphere(s3t, Transform.Invert(s3t), false, 300f, -300, 300, 360);
            var s3g = new GeometricPrimitive(s3, yellow, null);

            var s4t = Transform.Translate(400, 500, 150);
            var s4  = new Sphere(s4t, Transform.Invert(s4t), false, 180f, -180, 180, 360);
            var s4g = new GeometricPrimitive(s4, metal, null);

            var s5t = Transform.Translate(420, 200, 250);
            var s5  = new Sphere(s5t, Transform.Invert(s5t), false, 180f, -180, 180, 360);
            var s5g = new GeometricPrimitive(s5, white, null);

            var s6t = Transform.Translate(500, 30, 180);
            var s6  = new Sphere(s6t, Transform.Invert(s6t), false, 200f, -200, 200, 360);
            var s6g = new GeometricPrimitive(s6, red, null);

            var bvh = new BVH(new IPrimitive[] { s1g, s2g, s3g, s4g, s5g, s6g }, SplitMethod.HLBVH);

            var lt         = Transform.Translate(400, 900, -800);
            var s          = Spectrum.FromBlackbodyT(5500) * 2000000f;
            var pointLight = new PointLight(lt, null, s);

            return(new Scene(bvh, new ILight[] { pointLight }));
        }
Exemple #3
0
        private static IScene Build()
        {
            var white =
                new MatteMaterial(
                    new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 1f, 1f, 1f }, SpectrumType.Illuminant)),
                    new ConstantTexture <float>(0), null);

            var red =
                new DisneyMaterial(
                    new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 0.9f, 0f, 0f }, SpectrumType.Reflectance)),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(1.5f),
                    new ConstantTexture <float>(0.6f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0.9f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <Spectrum>(Spectrum.Zero),
                    false,
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0.5f),
                    null);

            var yellow =
                new DisneyMaterial(
                    new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 1f, 1f, 0f }, SpectrumType.Reflectance)),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(1.5f),
                    new ConstantTexture <float>(1f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0.9f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <Spectrum>(Spectrum.Zero),
                    false,
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0.5f),
                    null);

            var cyan =
                new DisneyMaterial(
                    new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 0.01f, 0.5f, 0.01f }, SpectrumType.Reflectance)),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(1.8f),
                    new ConstantTexture <float>(1f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0.9f),
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <Spectrum>(Spectrum.Zero),
                    false,
                    new ConstantTexture <float>(0f),
                    new ConstantTexture <float>(0.5f),
                    null);

            var metal = new DisneyMaterial(
                new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 0.5f, 0.5f, 0.5f }, SpectrumType.Reflectance)),
                new ConstantTexture <float>(1f),
                new ConstantTexture <float>(1.8f),
                new ConstantTexture <float>(0.5f),
                new ConstantTexture <float>(0f),
                new ConstantTexture <float>(0f),
                new ConstantTexture <float>(0f),
                new ConstantTexture <float>(0f),
                new ConstantTexture <float>(0f),
                new ConstantTexture <float>(1f),
                new ConstantTexture <float>(0f),
                new ConstantTexture <Spectrum>(Spectrum.Zero),
                false,
                new ConstantTexture <float>(0f),
                new ConstantTexture <float>(0.5f),
                null);

            var sss = new DisneyMaterial(
                new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 0.9f, 0.9f, 0.9f }, SpectrumType.Reflectance)),
                new ConstantTexture <float>(0f),
                new ConstantTexture <float>(1.5f),
                new ConstantTexture <float>(0.5f),
                new ConstantTexture <float>(0f),
                new ConstantTexture <float>(0f),
                new ConstantTexture <float>(1f),
                new ConstantTexture <float>(0.5f),
                new ConstantTexture <float>(0f),
                new ConstantTexture <float>(1f),
                new ConstantTexture <float>(0f),
                new ConstantTexture <Spectrum>(new Spectrum(10f)),
                false,
                new ConstantTexture <float>(0f),
                new ConstantTexture <float>(0.5f),
                null);

            var mirror =
                new MirrorMaterial(
                    new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 0.8f, 0.8f, 0.8f }, SpectrumType.Illuminant)),
                    null);

            var trans = new DisneyMaterial(
                new ConstantTexture <Spectrum>(Spectrum.FromRGB(new[] { 0.9f, 0.9f, 0.9f }, SpectrumType.Illuminant)),
                new ConstantTexture <float>(1f),
                new ConstantTexture <float>(1.62f),
                new ConstantTexture <float>(0.5f),
                new ConstantTexture <float>(1f),
                new ConstantTexture <float>(0f),
                new ConstantTexture <float>(0.0f),
                new ConstantTexture <float>(0f),
                new ConstantTexture <float>(0.0f),
                new ConstantTexture <float>(0.5f),
                new ConstantTexture <float>(0.90f),
                new ConstantTexture <Spectrum>(new Spectrum(0f)),
                false,
                new ConstantTexture <float>(0f),
                new ConstantTexture <float>(0f),
                null);

            var path = Path.Combine(TestScenes.GetExecutionPath(), "teapot.obj");

            Console.WriteLine("Loading file {0}...", path);
            var data = ObjFileMeshBuilder.ParseFile(path);

            Console.WriteLine("File parsed...");

            var teapotTransform = Transform.Scale(10)
                                  .RotateX(MathF.Rad(-90))
                                  .RotateY(MathF.Rad(26))
                                  .Translate(272f, 175f, -123f);
            var teapot     = data.Meshes[0].BuildShape(teapotTransform, Transform.Invert(teapotTransform), false);
            var primitives = teapot.Select(tri => new GeometricPrimitive(tri, metal, null)).Cast <IPrimitive>().ToList();

            var plane = TestScenes.CreatePlane(new Point(-1500, 178, -800), new Point(1500, 178, 2500));

            primitives.AddRange(plane.Select(tri => new GeometricPrimitive(tri, cyan, null)));

            var bvh = new BVH(primitives.ToArray(), SplitMethod.HLBVH);

            var transform = Transform.RotateX(MathF.Rad(70)).Translate(278, 600, -200);
            var spectrum  = Spectrum.FromBlackbodyT(4000) * 500000f;
            var spotLight = new SpotLight(transform, null, spectrum, 120, 20);

            transform = Transform.Translate(402, 300, 200);
            spectrum  = Spectrum.FromBlackbodyT(7500) * 20000f;
            var pointLight = new PointLight(transform, null, spectrum);

            return(new Scene(bvh, new ILight[] { pointLight, spotLight }));
        }