Exemplo n.º 1
0
 Vector3 Color(Ray r, HitableList world)
 {
     HitRecord rec = new HitRecord();
     if (world.hit(r, 0.001f, float.MaxValue, ref rec))
     {
         Vector3 target = rec.p + rec.normal + Sphere.random_in_unit_sphere();
         return 0.5f * Color(new Ray(rec.p, target - rec.p), world);
     }
     else
     {
         Vector3 unitDirection = Vector3.Normalize(r.Direction());
         float t = 0.5f * (unitDirection.Y + 1.0f);
         return (1.0f - t) * new Vector3(1.0f, 1.0f, 1.0f) + t * new Vector3(0.5f, 0.7f, 1.0f);
     }
 }
Exemplo n.º 2
0
        Vector3 Color(Ray r, HitableList world)
        {
            HitRecord rec = new HitRecord();

            if (world.hit(r, 0.0f, float.MaxValue, ref rec))
            {
                return(0.5f * new Vector3(rec.normal.X + 1.0f, rec.normal.Y + 1.0f, rec.normal.Z + 1.0f));
            }
            else
            {
                Vector3 unitDirection = Vector3.Normalize(r.Direction());
                float   t             = 0.5f * (unitDirection.Y + 1.0f);
                return((1.0f - t) * new Vector3(1.0f, 1.0f, 1.0f) + t * new Vector3(0.5f, 0.7f, 1.0f));
            }
        }
Exemplo n.º 3
0
        Vector3 Color(Ray r, HitableList world, int depth)
        {
            HitRecord rec = new HitRecord();

            if (world.hit(r, 0.001f, float.MaxValue, ref rec))
            {
                Ray     scattered   = null;
                Vector3 attenuation = new Vector3(0, 0, 0);
                if (depth < 50 && rec.mat.scatter(r, rec, ref attenuation, ref scattered))
                {
                    return(attenuation * Color(scattered, world, depth + 1));
                }
                else
                {
                    return(new Vector3(0, 0, 0));
                }
            }
            else
            {
                Vector3 unitDirection = Vector3.Normalize(r.Direction());
                float   t             = 0.5f * (unitDirection.Y + 1.0f);
                return((1.0f - t) * new Vector3(1.0f, 1.0f, 1.0f) + t * new Vector3(0.5f, 0.7f, 1.0f));
            }
        }