예제 #1
0
        public static void RowTransparentRoughness(int spp)
        {
            Material CreateMaterial()
            {
                var material = new Material();
                var color    = new Color(1f, 1f, 1f);

                material.Texture         = SolidColor.Create(color);
                material.SpecularColor   = new Color(0.8f, 0.8f, 0.8f);
                material.Transparency    = 0.92f;
                material.Metallic        = 0.65f;
                material.RefractiveIndex = 1.51f;
                material.Ambient         = 0f;
                return(material);
            }

            const float delta = 1f / 9;

            RowTestByDelegate(spp, "transparent_roughness", i =>
            {
                var metal       = CreateMaterial();
                metal.Roughness = MathFunction.Saturate((i - 1) * delta);
                return(metal);
            });
        }
예제 #2
0
        public void CreateMethod()
        {
            var color = new Color(0, 1, 0);
            var sc1   = new SolidColor(color);
            var sc2   = SolidColor.Create(0, 1, 0);

            sc1.Color.Should().Be(sc2.Color);
        }
예제 #3
0
        public static void RowPlastic(int spp)
        {
            Material CreateMaterial()
            {
                var material = new Material();
                var color    = new Color(1f, 0.3f, 0.3f);

                material.Texture       = SolidColor.Create(color);
                material.SpecularColor = new Color(0.2f, 0.2f, 0.2f);
                material.Metallic      = 0f;
                material.Ambient       = 0f;
                return(material);
            }

            const float delta = 1f / 9;

            RowTestByDelegate(spp, "plastic", i =>
            {
                var metal       = CreateMaterial();
                metal.Roughness = MathFunction.Saturate((i - 1) * delta + 0.01f);
                return(metal);
            });
        }
예제 #4
0
        public static void ColRowTestRender()
        {
            Console.WriteLine("Loading file...");
            //var filePath = Path.Combine(GetExecutionPath(), "indoor_env.ppm");
            var filePath = Path.Combine(GetExecutionPath(), "winter_river_1k.ppm");

            Console.WriteLine("Parsing file...");
            var textureCanvas = PPM.ParseFile(filePath);
            var image         = new UVImage(textureCanvas);
            var map           = new TextureMap(image, UVMapping.Spherical);

            var skySphere = new Sphere()
            {
                Material = { Texture = map, Ambient = 1.5f, CastsShadows = false, Transparency = 1f }
            };

            skySphere.SetTransform(Transform.RotateY(3.4f).Scale(1000f));

            var  g        = new Group();
            var  dx       = 2.75f;
            var  dz       = 3.5f;
            var  y        = 1f;
            var  nX       = 10;
            var  nZ       = 1;
            var  delta    = 1f / (nX * nZ - 1);
            int  n        = 0;
            bool metallic = false;

            for (var z = 0; z < nZ; z++)
            {
                for (var x = 0; x < nX; x++)
                {
                    var s = new Sphere();
                    s.SetTransform(Transform.TranslateY(1f).Scale(1.2f).Translate(x * dx, 0, z * dz));
                    // var color = x % 2 == 0 ? new Color(1f, 1f, 1f) : new Color(1f, 0.3f, 0.3f);
                    var color = new Color(1f, 0.3f, 0.3f);
                    s.Material.Texture       = SolidColor.Create(color);
                    s.Material.SpecularColor = metallic ? color : new Color(0.2f, 0.2f, 0.2f);
                    s.Material.Roughness     = MathFunction.Saturate(n * delta + 0.01f);
                    s.Material.Metallic      = metallic ? 1f : 0f;
                    s.Material.Ambient       = 0f;
                    s.Material.Reflective    = 0.9f;
                    g.AddChild(s);
                    n++;
                }
            }

            var lightGray = new Color(0.9f, 0.9f, 0.9f);
            var darkGray  = new Color(0.1f, 0.9f, 0.1f);
            var s1        = new StripeTexture(lightGray, darkGray);
            var s2        = new StripeTexture(lightGray, darkGray);

            s2.SetTransform(Transform.RotateY(MathF.PI / 2));
            var pattern = new BlendedCompositeTexture(s1, s2);

            pattern.SetTransform(Transform.Scale(1f / 30f));

            var text = new CheckerTexture(new Color(0.3f, 0.7f, 0.3f), new Color(0.13f, 0.13f, 0.13f));

            text.SetTransform(Transform.Scale(1f / 16f));

            var floor = new Cube
            {
                Material =
                {
                    Texture       = text,
                    SpecularColor = new Color(0.3f, 0.3f, 0.3f),
                    Metallic      =             0f,
                    Roughness     =          0.45f,
                    Ambient       = 0.15f
                }
            };

            floor.SetTransform(Transform.TranslateY(-1f).Scale(40f));

            var min = g.LocalBounds().Min;
            var max = g.LocalBounds().Max;
            var dir = max - min;
            var mid = min + (dir * 0.5f);

            var g2 = new Group(g, floor, skySphere);

            //var g2 = new Group(g);
            g2.Divide(1);

            var w = new World();

            w.SetLights(new PointLight(new Point(mid.X, 500, -500), new Color(1.7f, 1.7f, 1.7f)));
            w.SetObjects(g2);

            //var width = 1200;
            //var height = 140;
            //var transform = Transforms.View(new Point(mid.X, 6f, -32f), mid, new Vector(0, 1, 0));
            //var c = new PinholeCamera(transform, MathF.PI / 4f, width, height);
            ////var c = new ApertureCamera(MathF.PI / 4f, width, height, 0.04f, new Point(mid.X, 6f, -32f), mid);
            //var ws = new ComposableWorldShading(3, GGXNormalDistribution.Instance, GGXSmithGeometricShadow.Instance, SchlickFresnelFunction.Instance, w);
            ////var ws = new PhongWorldShading(3, w);
            //var scene = new Scene(c, ws);
            //var aaa = new AdaptiveRenderer(4, 0.00001f, scene);
            //var canvas = new Canvas(width, height);


            var width  = 1200;
            var height = 140;
            var from   = new Point(mid.X, 6f, -32f);
            var to     = mid;

            var canvas      = new Canvas(width, height);
            var pps         = new PerPixelSampler(400);
            var fov         = MathF.PI / 4f;
            var aspectRatio = (float)width / height;
            var camera      = new ApertureCamera(fov, aspectRatio, 0.2F, from, to, Vectors.Up);
            var cws         = new ComposableWorldSampler(2,
                                                         16,
                                                         GGXNormalDistribution.Instance,
                                                         GGXSmithGeometricShadow.Instance,
                                                         SchlickFresnelFunction.Instance,
                                                         w);
            var ctx = new RenderContext(canvas, new RenderPipeline(cws, camera, pps));

            Console.WriteLine("Rendering at {0}x{1}...", width, height);
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            ctx.Render();
            //RenderContext.Render(canvas, aaa);
            PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "col_row");
            stopwatch.Stop();
            Console.WriteLine("Done ({0})", stopwatch.Elapsed);
        }
예제 #5
0
        public static void InsideSphere()
        {
            Console.WriteLine("Loading file...");
            var filePath = Path.Combine(GetExecutionPath(), "winter_river_1k.ppm");

            Console.WriteLine("Parsing file...");
            var textureCanvas = PPM.ParseFile(filePath);
            var image         = new UVImage(textureCanvas);
            var map           = new TextureMap(image, UVMapping.Spherical);

            var skySphere = new Sphere()
            {
                Material = { Texture = map, Ambient = 1.2f, CastsShadows = false, Transparency = 1f }
            };

            skySphere.SetTransform(Transform.RotateY(2.1f).Scale(1000f));

            var s = new Sphere
            {
                Material =
                {
                    Roughness     =                           0.1f,
                    Texture       = SolidColor.Create(new Color(1f, 0.0f, 0.0f)),
                    SpecularColor = new Color(0.2f,                 0.2f,  0.2f),
                    Metallic      =                             0f,
                    Ambient       = 0f
                }
            };

            var g = new Group();

            g.AddChild(skySphere);
            g.AddChild(s);

            g.Divide(1);

            var w = new World();

            w.SetLights(new PointLight(new Point(100, 100, -100), new Color(1f, 1f, 1f)));
            w.SetObjects(g);

            var width  = 400;
            var height = 400;
            var from   = new Point(0, -0.8f, -4f);
            var to     = new Point(0, 0, 0);

            var canvas      = new Canvas(width, height);
            var pps         = new PerPixelSampler(1000);
            var fov         = 0.8f;
            var aspectRatio = (float)width / height;
            var camera      = new ApertureCamera(fov, aspectRatio, 0.05F, from, to, Vectors.Up);
            var cws         = new ComposableWorldSampler(1,
                                                         2,
                                                         GGXNormalDistribution.Instance,
                                                         SchlickBeckmanGeometricShadow.Instance,
                                                         SchlickFresnelFunction.Instance,
                                                         w);
            var ctx = new RenderContext(canvas, new RenderPipeline(cws, camera, pps));

            Console.WriteLine("Rendering at {0}x{1}...", width, height);
            var stopwatch = new Stopwatch();

            stopwatch.Start();
            ctx.Render();
            PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "sky_sphere");
            stopwatch.Stop();
            Console.WriteLine("Done ({0})", stopwatch.Elapsed);
        }