Exemplo n.º 1
0
        public override bool scatter(Ray rayIn, ShadeRec sr, out SColor Attenuation, out Ray rayScatter)
        {
            Vector3D reflectDir = Ray.getReflectDir(rayIn.Direction, sr.Normal);

            reflectDir.Normalize();
            rayScatter  = new Ray(sr.HitPoint, reflectDir + fuzz * Vector3D.RandomInUnitSphere());
            Attenuation = texture.getColor(sr.U, sr.V, sr.HitPoint);
            return((rayScatter.Direction * sr.Normal) > 0);
        }
Exemplo n.º 2
0
        public override bool scatter(Ray rayIn, ShadeRec sr, out SColor Attenuation, out Ray rayScatter)
        {
            Attenuation = new SColor(1, 1, 1);
            Vector3D outward_normal;
            Vector3D refracted;
            Vector3D reflected = Ray.getReflectDir(rayIn.Direction, sr.Normal);
            double   eta, cos, reflect_prob;

            if (rayIn.Direction * sr.Normal > 0)
            {
                outward_normal = -1 * sr.Normal;
                eta            = _RI;
                cos            = _RI * (rayIn.Direction * sr.Normal) / rayIn.Direction.Magnitude();
            }
            else
            {
                outward_normal = sr.Normal;
                eta            = 1.0 / _RI;
                cos            = -1.0 * (rayIn.Direction * sr.Normal) / rayIn.Direction.Magnitude();
            }
            if (refract(rayIn.Direction, outward_normal, eta, out refracted))
            {
                reflect_prob = schlick(cos, eta);
                rayScatter   = new Ray(sr.HitPoint, refracted);
            }
            else
            {
                reflect_prob = 1.0;
                rayScatter   = new Ray(sr.HitPoint, reflected);
            }
            if (Form2.random() < reflect_prob)
            {
                rayScatter = new Ray(sr.HitPoint, reflected);
            }
            else
            {
                rayScatter = new Ray(sr.HitPoint, refracted);
            }
            return(true);
        }