Beispiel #1
0
        static HitableList()
        {
            DefaultWorld = new HitableList {
                //Bottom "plane"
                new Sphere(new Vec3(0, -1000, 0), 1000, new Lambertain(new Vec3(0.5F, 0.5F, 0.5F))),

                // three large spheres
                new Sphere(new Vec3(4, 1, 0), 1.0F, new Dielectric(1.5F)),
                new Sphere(new Vec3(-4, 1, 0), 1.0F, new Lambertain(new Vec3(0.4F, 0.2F, 0.1F))),
                new Sphere(new Vec3(0, 1, 0), 1.0F, new Metal(new Vec3(0.7F, 0.6F, 0.5F), 0.0F))
            };

            // numerous small sphere
            RandomizeWorld(DefaultWorld);
        }
Beispiel #2
0
        public Vec3 GetColor(Ray ray, HitableList scene, int depth)
        {
            if (depth == 0)
            {
                return(new Vec3(0, 0, 0));
            }

            var hit = scene.GetNearestHit(ray, 0.0001F);

            if (hit != null)
            {
                var result = hit.Material.Scatter(ray, hit);
                if (result != default)
                {
                    return(GetColor(result.ray, scene, depth - 1) * result.color);
                }
            }
            var t = (MathR.Normalize(ray.Direction).Y + 1) * 0.5F;

            return((new Vec3(1, 1, 1) * (1.0F - t)) + (new Vec3(0.5F, 0.7F, 1) * t));
        }
Beispiel #3
0
        private static void RandomizeWorld(HitableList world)
        {
            for (var a = -11; a < 11; a++)
            {
                for (var b = -11; b < 11; b++)
                {
                    var chooseMat = Rand.Rand01();
                    var center    = new Vec3(a + (0.9F * Rand.Rand01()), 0.2F, b + (0.9F * Rand.Rand01()));
                    if ((center - new Vec3(4, 0.2F, 0)).Lenght() > 0.9F)
                    {
                        if (chooseMat < 0.8F)
                        {
                            // diffuse
                            var albedo = Vec3.Random() * Vec3.Random();

                            world.Add(new Sphere(center, 0.2F, new Lambertain(albedo)));
                        }
                        else if (chooseMat < 0.95)
                        {
                            // metal
                            var albedo  = Rand.Rand01();
                            var albedo2 = Rand.Rand01();
                            var albedo3 = Rand.Rand01();

                            var fuzz = Rand.Rand01();

                            world.Add(new Sphere(center, 0.2F, new Metal(new Vec3(albedo, albedo2, albedo3), fuzz)));
                        }
                        else
                        {
                            // glass
                            world.Add(new Sphere(center, 0.2F, new Dielectric(Rand.Uniform(0.5F, 1.5F))));
                        }
                    }
                }
            }
        }