static void Main(string[] args) { ISceneGraph scene_graph = SceneGraphFactory.Create(); ITexture checker_texture = new CheckerTexture(new ConstantTexture(new Vector3(0.2f, 0.3f, 0.1f)), new ConstantTexture(new Vector3(0.9f, 0.9f, 0.9f))); SphereNode sphere = scene_graph.AddShape(Shape.Sphere) as SphereNode; sphere.Translation = new Vector3(0.0f, -1000.0f, 0.0f); sphere.Material = new LambertianMaterial(checker_texture); sphere.Radius = 1000.0f; sphere = scene_graph.AddShape(Shape.Sphere) as SphereNode; sphere.Translation = new Vector3(0.0f, 1.0f, 0.0f); sphere.Material = new DielectricMaterial(1.5f); sphere.Radius = 1.0f; sphere = scene_graph.AddShape(Shape.Sphere) as SphereNode; sphere.Translation = new Vector3(0.0f, 3.0f, 0.0f); sphere.Material = new DiffuseLightMaterial(new ConstantTexture(new Vector3(3.0f, 3.0f, 3.0f))); sphere.Radius = 1.0f; sphere = scene_graph.AddShape(Shape.Sphere) as SphereNode; sphere.Translation = new Vector3(-4.0f, 1.0f, 0.0f); sphere.Material = new LambertianMaterial(new ConstantTexture(new Vector3(0.4f, 0.2f, 0.1f))); sphere.Radius = 1.0f; sphere = scene_graph.AddShape(Shape.Sphere) as SphereNode; sphere.Translation = new Vector3(4.0f, 1.0f, 0.0f); sphere.Material = new MetalMaterial(new ConstantTexture(new Vector3(0.7f, 0.6f, 0.5f)), 0.0f); sphere.Radius = 1.0f; for (int z = -10; z <= 10; ++z) { for (int x = -10; x <= 10; ++x) { float choose_material = MathHelper.RandomFloat(); Vector3 translation = new Vector3(x + 0.9f * MathHelper.RandomFloat(), 0.2f, z + 0.9f * MathHelper.RandomFloat()); if (Vector3.Distance(translation, new Vector3(4.0f, 0.2f, 0.0f)) > 0.9f) { SphereNode ball = scene_graph.AddShape(Shape.Sphere) as SphereNode; ball.Translation = translation; ball.Radius = 0.2f; if (choose_material < 0.8f) { ball.Material = new LambertianMaterial(new ConstantTexture(new Vector3(MathHelper.RandomFloat() * MathHelper.RandomFloat(), MathHelper.RandomFloat() * MathHelper.RandomFloat(), MathHelper.RandomFloat() * MathHelper.RandomFloat()))); } else if (choose_material < 0.95f) { ball.Material = new MetalMaterial(new ConstantTexture(new Vector3(1.0f + MathHelper.RandomFloat(), 1.0f + MathHelper.RandomFloat(), 1.0f + MathHelper.RandomFloat()) * 0.5f), 0.5f * MathHelper.RandomFloat()); } else { ball.Material = new DielectricMaterial(1.5f); } } } } ICameraNode camera = scene_graph.AddCamera(); camera.View.Width = 1200; camera.View.Height = 800; camera.SetProjection(20.0f); camera.Translation = new Vector3(13.0f, 2.0f, 3.0f); camera.Rotation = MathHelper.LookAt(camera.Translation, new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 1.0f, 0.0f)); Image image = scene_graph.Render(camera, 50, 50); PPMImageSaver saver = new PPMImageSaver(); string path = args.Length > 0 ? args[0] : "output.ppm"; saver.Save(image, path); }