Пример #1
0
        public bool Hit(Ray r, float tMin, float tMax, ref HitRecord rec)
        {
            HitRecord tempRecord   = new HitRecord();
            bool      hitAnything  = false;
            float     closestSoFar = tMax;

            for (var i = 0; i < Objects.Length; i++)
            {
                var obj = Objects[i];
                if (obj.Hit(r, tMin, closestSoFar, ref tempRecord))
                {
                    hitAnything  = true;
                    closestSoFar = tempRecord.t;
                    rec          = tempRecord;
                }
            }

            return(hitAnything);
        }
Пример #2
0
        public static bool Generic(Ray r, HitRecord rec,
                                   ref float3 attenuation, ref Ray scattered, ref Random rng)
        {
            switch (rec.material.type)
            {
            case MaterialType.Lambertian:
                return(Diffuse(r, rec, ref attenuation, ref scattered, ref rng));

            case MaterialType.Metal:
                return(Metal(r, rec, ref attenuation, ref scattered, ref rng));

            case MaterialType.Dielectric:
                // The dark sphere outline bug was fixed by adding this line, which
                // changes the state of the RNG so reflection probability works somehow.
                // this doesn't work if you call .NextFloat() inside .Dielectric() ??
                // DON'T REMOVE
                rng.NextFloat();
                return(Dielectric(r, rec, ref attenuation, ref scattered, ref rng));
            }

            return(false);
        }
Пример #3
0
 public bool Scatter(HitRecord rec,
                     ref float3 attenuation, ref Ray scattered, ref Random rng)
 {
     return(ScatterMethod.Generic(this, rec, ref attenuation, ref scattered, ref rng));
 }