Пример #1
0
        //class Scene : Hitable
        //{
        //    AABB _box;
        //    Hitable _inner;
        //    public Scene(HitList l,float t0,float t1)
        //    {
        //        _box = l.BoundVolume(t0,t1);
        //        _inner = l;
        //    }
        //    public AABB BoundVolume(float t0, float t1)
        //    {
        //        return _box;
        //    }

        //    public bool Hit(Ray ray, float min, float max, out HitRecord r)
        //    {
        //        r = null;
        //        if(!_box.Hit(ray,min,max))
        //        {
        //            return false;
        //        }
        //        return _inner.Hit(ray, min, max, out r);
        //    }
        //}

        static Hitable random_scene(bool bvh)
        {
            int n = 500;

            Hitable[] list  = new Hitable[n + 1];
            vec3      black = new vec3(0.1f, 0.1f, 0.2f);
            vec3      white = new vec3(1f, 1f, 1f);
            var       check = new CheckTexture(black, white);
            var       noise = new NoiseTexture(new Noise());

            list[0] = new Sphere(new vec3(0, -1000, 0), 1000, new Lambertian(noise));
            int i = 1;

            //for (int a = -11; a < 11; a++)
            //{
            //    for (int b = -11; b < 11; b++)
            //    {
            //        float choose_mat = Exten.rand01();
            //        var center = new vec3(a + 0.9f * Exten.rand01(), 0.2f, b + 0.9f * Exten.rand01());
            //        if ((center - new vec3(4f, 0.2f, 0f)).length() > 0.9f)
            //        {
            //            if (choose_mat < 0.8)
            //            {  // diffuse
            //                var color = new vec3(Exten.rand01() * Exten.rand01(), Exten.rand01() * Exten.rand01(), Exten.rand01() * Exten.rand01());

            //                var mat = new Lambertian(new SolidTexture(color));
            //                list[i++] = new Sphere(center, 0.2f,mat);
            //            }
            //            else if (choose_mat < 0.95f)
            //            { // metal
            //                list[i++] = new Sphere(center, 0.2f,
            //                        new Metal(new vec3(0.5f * (1 + drand48()), 0.5f * (1 + drand48()), 0.5f * (1 + drand48())), 0.5f * drand48()));
            //            }
            //            else
            //            {  // glass
            //                list[i++] = new Sphere(center, 0.2f, new Dieletric(1.5f));
            //            }
            //        }
            //    }
            //}

            //list[i++] = new Sphere(new vec3(2, 1, 0), 1.0f, new Dieletric(1.3f));
            //list[i++] = new Sphere(new vec3(-3, 1, 2), 1.0f, new Metal(new vec3(0.4f, 0.2f, 0.1f),0.2f));
            list[i++] = new Sphere(new vec3(4, 1, 0), 1.0f, new Lambertian(noise));
            //list[i++] = new Sphere(new vec3(4, 1, -0.5f), 1.0f, new Metal(new vec3(0.7f, 0.6f, 0.5f), 0.0f));
            var finalList = list.Where(p => p != null).ToArray();

            if (!bvh)
            {
                return(new HitList(finalList));
            }
            else
            {
                //Array.Sort(finalList, new BVHNode.BVHComparer(0));
                return(new BVHNode(finalList, 0, finalList.Length, 0, 1));
            }
        }
Пример #2
0
        static Hitable SimpleLight()
        {
            Texture perlintext = new NoiseTexture(new Noise());

            Hitable[] hitables = new Hitable[4];
            int       i        = 0;
            var       tex2     = new SolidTexture(new vec3(4, 4, 4));

            hitables[i++] = new Sphere(new vec3(0, -1000, 0), 1000, new Lambertian(perlintext));
            hitables[i++] = new Sphere(new vec3(0, 2, 0), 2, new Lambertian(perlintext));
            //hitables[i++] = new Sphere(new vec3(0, 7, 0), 2, new DiffuseLight(tex2));
            hitables[i++] = new XYRect(-2, 3, 5, 1, 3, new DiffuseLight(tex2));
            var finalList = hitables.Where(h => h != null).ToArray();

            return(new BVHNode(finalList, 0, finalList.Length, 0, 1));
        }
Пример #3
0
        static Hitable FinalTest()
        {
            int nb = 20;

            Hitable[] list    = new Hitable[30];
            Hitable[] boxlist = new Hitable[10000];
            Material  ground  = new Lambertian(new SolidTexture(new vec3(0.48f, 0.83f, 0.53f)));
            int       b       = 0;

            for (int i = 0; i < nb; i++)
            {
                for (int j = 0; j < nb; j++)
                {
                    float w  = 100;
                    float x0 = -1000 + i * w;
                    float z0 = -1000 + j * w;
                    float y0 = 0;
                    float x1 = x0 + w;
                    float y1 = 100 * (Exten.rand01() + 0.01f);
                    float z1 = z0 + w;
                    boxlist[b++] = new Box(new vec3(x0, y0, z0), new vec3(x1, y1, z1), ground);
                }
            }
            int l = 0;

            list[l++] = new BVHNode(boxlist, 0, b, 0, 1);
            Material light = new DiffuseLight(new SolidTexture(new vec3(7, 7, 7)));

            list[l++] = new XZRect(554, 123, 423, 147, 412, light);
            vec3 center = new vec3(400, 400, 200);

            //public Sphere(vec3 c, vec3 c1, float r, Material m, float time1, float time2)
            list[l++] = new Sphere(center, center + new vec3(30, 0, 0), 50, new Lambertian(new SolidTexture(new vec3(0.7f, 0.3f, 0.1f))), 0, 1);
            list[l++] = new Sphere(new vec3(260, 150, 45), 50, new Dieletric(1.5f));
            list[l++] = new Sphere(new vec3(0, 150, 145), 50, new Metal(new vec3(0.8f, 0.8f, 0.9f), 10.0f));
            Hitable boundary = new Sphere(new vec3(360, 150, 145), 70, new Dieletric(1.5f));

            list[l++] = boundary;
            boundary  = new Sphere(new vec3(0, 0, 0), 5000, new Dieletric(1.5f));
            Texture pertext = new NoiseTexture(new Noise());

            list[l++] = new Sphere(new vec3(220, 280, 300), 80, new Lambertian(pertext));
            return(new HitList(list.Where(arg => arg != null).ToArray()));
        }