public static void TeapotTest() { 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 = 2.5f, CastsShadows = false, Transparency = 0f, Roughness = 1f, SpecularColor = new Color(0.0f, 0.0f, 0.0f) } }; //skySphere.SetTransform(Transforms.RotateY(3.4f).Scale(1000f)); skySphere.SetTransform(Transform.RotateY(3.3f).Scale(10000f)); var path = Path.Combine(GetExecutionPath(), "teapot.obj"); Console.WriteLine("Loading file {0}...", path); var data = ObjFile.ParseFile(path); Console.WriteLine("File parsed..."); var triangulated = data.Groups[0]; triangulated.SetTransform(Transform.Scale(0.10f).RotateX(-MathF.PI / 2f).RotateY(MathF.PI / 8f)); var glass = new Material { Texture = new SolidColor(new Color(0.8f, 1f, 0.9f)), Reflective = 0.78f, Roughness = 0.35f, Metallic = 0.65f, SpecularColor = new Color(0.7f, 0.9f, 0.8f), RefractiveIndex = 1.52f, Transparency = 0.80f, Ambient = 0.0f, Diffuse = 0.2f, Shininess = 200f, Specular = 0.9f }; ApplyMaterialToChildren(triangulated, glass); var checkerboard = new Material { Texture = new CheckerTexture(new Color(0.95f, 0.95f, 0.95f), new Color(0.8f, 0.05f, 0.05f)), Metallic = 0.4f, SpecularColor = new Color(0.3f, 0.3f, 0.3f), Reflective = 0.5f, Roughness = 0.1f, Ambient = 0.0f, Diffuse = 0.3f }; checkerboard.Texture.SetTransform(Transform.Scale(0.125f)); var group = new Group(); var floor = new Cube(); floor.SetMaterial(checkerboard); floor.SetTransform(Transform.TranslateY(-1).Scale(5f)); group.AddChild(floor); group.AddChild(triangulated); group.AddChild(skySphere); group.Divide(1); var w = new World(); w.SetLights(new AreaLight(new Point(-80f, 80, -60), new Vector(100f, 0, 0), 6, new Vector(0, 0f, -10f), 3, new Color(1.8f, 1.8f, 1.8f), new Sequence(0.7f, 0.3f, 0.9f, 0.1f, 0.5f))); //w.SetLights(new PointLight(new Point(-30, 30, -30), new Color(1.4f, 1.4f, 1.4f))); w.SetObjects(group); //var width = 600; //var height = 400; //var transform = Transforms.View(new Point(0, 3.0f, -5f), new Point(0, 1, 0), new Vector(0, 1, 0)); //var c = new PinholeCamera(transform, MathF.PI / 3f, width, height); ////var ws = new ComposableWorldShading(3, GGXNormalDistribution.Instance, SchlickBeckmanGeometricShadow.Instance, SchlickFresnelFunction.Instance, w); //var ws = new PhongWorldShading(5, w); //var scene = new Scene(c, ws); //var aaa = new AdaptiveRenderer(3, 0.05f, scene); //var canvas = new Canvas(width, height); var width = 600; var height = 400; var from = new Point(0, 2.5f, -2.5f); var to = new Point(0.25f, 0.5f, 0); var canvas = new Canvas(width, height); var pps = new PerPixelSampler(10); var fov = MathF.PI / 3f; var aspectRatio = (float)width / height; var transform = Transform.LookAt(from, to, new Vector(0, 1, 0)); //var camera = new PinholeCamera(transform, fov, aspectRatio); var camera = new ApertureCamera(fov, aspectRatio, 0.08f, from, to, Vectors.Up); // var cws = new PhongWorldShading(5, w); 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(); //RenderContext.Render(canvas, aaa); ctx.Render(); PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "teapot"); stopwatch.Stop(); Console.WriteLine("Done ({0})", stopwatch.Elapsed); }
private static World BuildWorld() { 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 = 0f, Roughness = 1f, SpecularColor = new Color(0.0f, 0.0f, 0.0f) } }; //skySphere.SetTransform(Transforms.RotateY(3.4f).Scale(1000f)); skySphere.SetTransform(Transform.RotateY(3.3f).Scale(10000f)); var s1 = new StripeTexture(Colors.White, Colors.Black); var s2 = new StripeTexture(Colors.White, Colors.Black); s2.SetTransform(Transform.RotateY(MathF.PI / 2)); var pattern = new BlendedCompositeTexture(s1, s2); pattern.SetTransform(Transform.Scale(1f / 20f)); var testPattern = new UVAlignTestPattern(Colors.White, Colors.Red, Colors.Yellow, Colors.Green, Colors.Blue); var testMap = new TextureMap(testPattern, UVMapping.Cylindrical); //var stripe = new StripePattern(new Color(0.9f, 0, 0), new Color(0.0f, 0.0f, 0.9f)); //stripe.SetTransform(Transforms.Scale(0.25f, 0.25f, 0.25f).RotateY(MathF.PI / 4)); //var perlin = new PerlinRippleCompositePattern(stripe, 0.8f); //perlin.SetTransform(Transforms.Scale(0.1f, 0.1f, 0.1f)); var worldFilePath = Path.Combine(GetExecutionPath(), "world.ppm"); var worldCanvas = PPM.ParseFile(worldFilePath); var worldTexture = new UVImage(worldCanvas); var worldPattern = new TextureMap(worldTexture, UVMapping.Spherical); var floor = new Cube { Material = { Texture = pattern, Specular = 0.1f, Reflective = 0.1f, Roughness = 0.22f, Ambient = 0f, SpecularColor = new Color(0.1f, 0.1f, 0.1f) } }; floor.SetTransform(Transform.TranslateY(-1).Scale(20f)); var middle = new Sphere { Material = { Texture = worldPattern, Diffuse = 0.7f, Specular = 1f, Reflective = 0.4f, Shininess = 600, Roughness = 0.2f, Metallic = 0.3f, SpecularColor = new Color(0.1f,0.2f, 0.5f), Ambient = 0f } }; middle.SetTransform(Transform.RotateY(1.5f).Translate(-0.5f, 1f, 0.1f)); var right = new Sphere { Material = { Texture = new TextureMap(new UVCheckers(20, 10, Colors.Black, Colors.White), UVMapping.Spherical), Roughness = 0.5f, Diffuse = 0.7f, Specular = 0.3f, Reflective = 0.2f, Ambient = 0f, SpecularColor = new Color(0.2f, 0.2f, 0.2f) } }; right.SetTransform(Transform.Translate(0.25f, 0.25f, -1f) * Transform.Scale(0.25f)); var rightPlastic = new Sphere { Material = { Texture = new SolidColor(new Color(1f, 0.0f, 0.0f)), SpecularColor = new Color(0.2f, 0.2f, 0.2f), Roughness = 0.25f, Metallic = 0f, Ambient = 0.0f } }; rightPlastic.SetTransform(Transform.Translate(-0.15f, 0.15f, -0.91f) * Transform.Scale(0.15f)); var left = new Sphere { Material = { Texture = new SolidColor(new Color(0.85f, 0.85f, 0.90f)), SpecularColor = new Color(0.3f, 0.3f, 0.3f), Roughness = 0.10f, Metallic = 0.6f, Transparency = 0.95f, RefractiveIndex = 1.52f,Ambient = 0.0f } }; left.SetTransform(Transform.Translate(-1.3f, 0.30f, -0.75f) * Transform.Scale(0.30f)); // left.SetTransform(Transforms.Translate(-2.1f, 0.33f, 0.5f) * Transforms.Scale(0.33f, 0.33f, 0.33f)); var leftChrome = new Sphere { Material = { Texture = new SolidColor(new Color(0.9f, 0.9f, 0.95f)), Diffuse = 0.05f, Specular = 0.9f, SpecularColor = new Color(0.9f, 0.9f, 0.95f), Roughness = 0.55f, Metallic = 1f, Transparency = 0, RefractiveIndex = 1.52f,Reflective = 1.4f, Ambient = 0.0f, Shininess = 300 } }; leftChrome.SetTransform(Transform.Translate(-0.95f, 0.15f, -1.1f) * Transform.Scale(0.15f)); var cube = new Cube { Material = { Texture = new GradientTexture(new Color(1f, 0, 0), new Color(1f, 0.8f, 0f)), Roughness = 0.5f, Ambient = 0f, SpecularColor = new Color(0.2f,0.2f, 0.2f) } }; cube.Material.Texture.SetTransform(Transform.TranslateX(-0.5f).Scale(2f).RotateZ(MathF.PI / 2f)); cube.SetTransform(Transform.RotateY(MathF.PI / 4f).Translate(2.5f, 1f, 3.6f).Scale(1f, 1f, 1f)); var cone = new Cone { IsClosed = true, Minimum = -1f, Maximum = 0f, Material = { Texture = new SolidColor(new Color(0.4f, 0.8f, 0.1f)), Diffuse = 0.7f, Specular = 0.3f, Ambient = 0f, SpecularColor = new Color(0.2f, 0.2f, 0.2f), Roughness = 0.6f, Reflective = 0.2f } }; cone.SetTransform(Transform.Scale(0.6f, 2f, 0.6f).Translate(1.5f, 2.0f, 0)); var cylinder = new Cylinder { Minimum = 0f, Maximum = 3f, IsClosed = true, Material = { Reflective = 0.33f, Specular = 0.9f, Diffuse = 0.1f, Ambient = 0.0f, Shininess = 100, Metallic = 0.76f, SpecularColor = new Color(0.9f, 0.8f, 0.7f), Roughness = 0.02f, Texture = testMap } }; cylinder.SetTransform(Transform.Translate(-3f, 0f, 3.5f)); //var t = new Triangle(new Point(0, 0, 0), new Point(1, 0.5f, 0), new Point(0.5f, 1f, 1f)) //{ // Material = {Texture = new GradientTexture(new Color(0f, 1, 0), new Color(0f, 0f, 1f))} //}; //t.SetTransform(Transforms.Translate(1f, 2f, 1f)); var ringMaterial = new Material { Texture = new SolidColor(new Color(1f, 0.8f, 0f)), Reflective = 0.4f, RefractiveIndex = 0.95f, Roughness = 0.12f, Metallic = 1f, SpecularColor = new Color(0.9f, 0.7f, 0f), //Transparency = 0.95f, Shininess = 300, Specular = 0.9f, Ambient = 0.0f, Diffuse = 0.3f }; var co = new Cylinder { Minimum = -0.01f, Maximum = 0.01f, IsClosed = true }; co.SetTransform(Transform.Scale(1.5f, 1f, 1.5f)); co.SetMaterial(ringMaterial); var ci = new Cylinder { Minimum = -0.1f, Maximum = 0.1f, IsClosed = true }; ci.SetTransform(Transform.Scale(1.2f, 1f, 1.2f)); ci.SetMaterial(ringMaterial); var s = new ConstructiveSolid(ConstructiveOp.Difference, co, ci); s.SetTransform(Transform.RotateZ(-0.2f).RotateX(-0.1f).Translate(-0.5f, 1f, 0.1f)); var gl = new Group(); gl.AddChild(middle); gl.AddChild(left); gl.AddChild(leftChrome); gl.AddChild(cylinder); gl.AddChild(s); gl.AddChild(right); gl.AddChild(rightPlastic); gl.AddChild(cube); gl.AddChild(cone); //gl.AddChild(t); gl.AddChild(floor); gl.AddChild(skySphere); gl.Divide(1); var w = new World(); w.SetLights(new AreaLight(new Point(-80f, 80, -60), new Vector(100f, 0, 0), 6, new Vector(0, 0f, -10f), 3, new Color(1.8f, 1.8f, 1.8f), new Sequence(0.7f, 0.3f, 0.9f, 0.1f, 0.5f))); //w.SetLights(new PointLight(new Point(-3.5f, 4f, -5f), new Color(0.9f, 0.9f, 0.9f))); w.SetObjects(gl); return(w); }
public static void SolidTestRender(int spp) { Console.WriteLine("Loading file..."); var filePath = Path.Combine(GetExecutionPath(), "neon_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.0f, CastsShadows = false, Transparency = 0f, Roughness = 1f, SpecularColor = new Color(0.0f, 0.0f, 0.0f) } }; skySphere.SetTransform(Transform.RotateY(3.3f).Scale(1000f)); var radius = 0.25f; var red = new Material { Texture = new SolidColor(new Color(1, 0, 0)), Reflective = 0.3f, Roughness = 0.3f, Ambient = 0.0f, Metallic = 0.3f, SpecularColor = new Color(0.3f, 0.3f, 0.3f) }; var blue = new Material { Texture = new SolidColor(new Color(0, 0, 1)), Reflective = 0.3f, Roughness = 0.3f, Ambient = 0.0f, Metallic = 0.3f, SpecularColor = new Color(0.3f, 0.3f, 0.3f) }; var yellow = new Material { Texture = new SolidColor(new Color(1, 1, 0)), Reflective = 0.3f, Roughness = 0.3f, Ambient = 0.0f, Metallic = 0.3f, SpecularColor = new Color(0.3f, 0.3f, 0.3f) }; var white = new Material { Texture = new SolidColor(new Color(1, 1, 1)), Reflective = 0.3f, Roughness = 0.3f, Ambient = 0.0f, Metallic = 0.3f, SpecularColor = new Color(0.3f, 0.3f, 0.3f) }; var blackPip = new Material { Texture = new SolidColor(new Color(0.1f, 0.1f, 0.1f)), Ambient = 0.0f, Roughness = 0.8f, Metallic = 0f, SpecularColor = new Color(0.2f, 0.2f, 0.2f) }; var whitePip = new Material { Texture = new SolidColor(new Color(0.95f, 0.95f, 0.95f)), Ambient = 0.0f, Roughness = 0.8f, Metallic = 0f, SpecularColor = new Color(0.2f, 0.2f, 0.2f) }; var d1 = CutPips(RoundedCube(radius, blue), whitePip); var d2 = CutPips(RoundedCube(radius, red), whitePip); var d3 = CutPips(RoundedCube(radius, white), blackPip); var d4 = CutPips(RoundedCube(radius, yellow), blackPip); d1.SetTransform(Transform.RotateY(-2.2f).TranslateY(1f).Scale(0.5f)); d2.SetTransform(Transform.RotateZ(MathF.PI / 2f).TranslateY(1f).TranslateX(2f).TranslateZ(1f).Scale(0.5f)); d3.SetTransform(Transform.RotateY(0.5f).TranslateY(1f).TranslateX(-4f).TranslateZ(1f).Scale(0.5f)); d4.SetTransform(Transform.RotateY(-0.2f).TranslateY(3f).TranslateX(0.2f).TranslateZ(1.25f).Scale(0.5f)); var lightGray = new Color(0.48f, 0.48f, 0.48f); var darkGray = new Color(0.15f, 0.15f, 0.15f); //var s1 = new StripeTexture(lightGray, darkGray); //var s2 = new StripeTexture(lightGray, darkGray); //s2.SetTransform(Transforms.RotateY(MathF.PI / 2)); //var pattern = new BlendedCompositeTexture(s1, s2); //pattern.SetTransform(Transforms.Scale(1f / 20f)); var pattern = new CheckerTexture(lightGray, darkGray); pattern.SetTransform(Transform.Scale(1f / 20f)); var floor = new Cube { Material = { Texture = pattern, Roughness = 0.5f, Specular = 0.1f, Diffuse = 0.3f, Reflective = 0.15f, SpecularColor = new Color(0.3f, 0.3f, 0.3f), Ambient = 0f } }; floor.SetTransform(Transform.TranslateY(-1f).Scale(20f)); var g = new Group(d1, d2, d3, d4, floor, skySphere); g.Divide(1); var w = new World(); w.SetLights(new AreaLight(new Point(-8, 10, -10), new Vector(12f, 0, 0), 6, new Vector(0, 0f, -10f), 3, new Color(1.1f, 1.1f, 1.1f), new Sequence(0.7f, 0.3f, 0.9f, 0.1f, 0.5f))); //w.SetLights(new PointLight(new Point(-8, 10, -10), new Color(0.9f, 0.9f, 0.9f))); //w.SetLights(new AreaLight(new Point(-3, 6, -4), new Vector(1f, 0, 0), 3, new Vector(0, 1f, 0), 3, // new Color(1.4f, 1.4f, 1.4f), new Sequence(0.7f, 0.3f, 0.9f, 0.1f, 0.5f))); //w.SetLights(new AreaLight(new Point(-10, 10, -10), new Vector(1,0,0), 4, new Vector(0,1,0), 3, Colors.White)); w.SetObjects(g); //var width = 600; //var height = 400; //var transform = Transforms.View(new Point(0, 1.5f, -5f), new Point(0, 1, 0), new Vector(0, 1, 0)); //var c = new PinholeCamera(transform, MathF.PI / 3f, width, height); //var ws = new ComposableWorldShading(2, GGXNormalDistribution.Instance, SchlickBeckmanGeometricShadow.Instance, SchlickFresnelFunction.Instance, w); ////var ws = new PhongWorldShading(2, w); //var scene = new Scene(c, ws); ////var aaa = new AdaptiveRenderer(2, 0.01f, scene); //var aaa = new SamplesPerPixelRenderer(24, scene); //var canvas = new Canvas(width, height); var width = 600; var height = 400; var from = new Point(0, 1.5f, -5f); var to = new Point(0, 1, -0.5f); var canvas = new Canvas(width, height); var pps = new PerPixelSampler(spp); var fov = MathF.PI / 3f; var aspectRatio = (float)width / height; var camera = new ApertureCamera(fov, aspectRatio, 0.15f, from, to, Vectors.Up); //var transform = Transforms.View(from, to, new Vector(0, 1, 0)); //var camera = new PinholeCamera2(transform, fov, aspectRatio); //var cws = new PhongWorldShading2(4, w); var cws = new ComposableWorldSampler(2, 4, 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(); // RenderContext.Render(canvas, aaa); PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "solid"); stopwatch.Stop(); Console.WriteLine("Done ({0})", stopwatch.Elapsed); }
public static void SkyBoxMappingTestRender() { Console.WriteLine("Loading sky box file..."); var skyBoxFile = Path.Combine(GetExecutionPath(), "skyboxsun.ppm"); Console.WriteLine("Parsing sky box file..."); var skyBoxCanvas = PPM.ParseFile(skyBoxFile); var skyBoxTexture = new UVImage(skyBoxCanvas); var skyBoxMap = new SkyBoxMap(skyBoxTexture); Cube Cube(float rotY, float rotX, float tx, float ty) { var cube1 = new Cube { Material = { Texture = skyBoxMap } }; cube1.SetTransform(Transform.RotateY(rotY).RotateX(rotX).Translate(tx, ty, 0)); return(cube1); } var g = new Group(); g.AddChild(Cube(0.7854f, 0.7854f, -6, 2)); g.AddChild(Cube(2.3562f, 0.7854f, -2, 2)); g.AddChild(Cube(3.927f, 0.7854f, 2, 2)); g.AddChild(Cube(5.4978f, 0.7854f, 6, 2)); g.AddChild(Cube(0.7854f, -0.7854f, -6, -2)); g.AddChild(Cube(2.3562f, -0.7854f, -2, -2)); g.AddChild(Cube(3.927f, -0.7854f, 2, -2)); g.AddChild(Cube(5.4978f, -0.7854f, 6, -2)); g.Divide(1); var w = new World(); w.SetLights(new PointLight(new Point(0, 2, -100), Colors.White)); w.SetObjects(g); var width = 800; var height = 400; var from = new Point(0, 0, -20f); var to = new Point(0, 0, 0); var canvas = new Canvas(width, height); var pps = new PerPixelSampler(16); var fov = 0.8f; var aspectRatio = (float)width / height; var transform = Transform.LookAt(from, to, new Vector(0, 1, 0)); var camera = new PinholeCamera(transform, fov, aspectRatio); var cws = new PhongWorldShading(1, 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), "mapping_sky_box"); stopwatch.Stop(); Console.WriteLine("Done ({0})", stopwatch.Elapsed); }
public static void RowTestByDelegate(int spp, string fileSuffix, Func <int, Material> materialFunc) { 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.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; int n = 0; 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)); s.SetMaterial(materialFunc(x + 1)); 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); 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 from = new Point(mid.X, 6f, -32f); var to = mid; var canvas = new Canvas(width, height); var pps = new PerPixelSampler(spp); 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(); PPM.ToFile(canvas, Environment.GetFolderPath(Environment.SpecialFolder.MyPictures), "col_row_" + fileSuffix); stopwatch.Stop(); Console.WriteLine("Done ({0})", stopwatch.Elapsed); }
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); }
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); }