示例#1
0
        public override bool scatter(Ray rayIn, ShadeRec sr, out SColor Attenuation, out Ray rayScatter)
        {
            Point3D target = (sr.HitPoint + sr.Normal) + Vector3D.RandomInUnitSphere();

            rayScatter  = new Ray(sr.HitPoint, target - sr.HitPoint);
            Attenuation = texture.getColor(sr.U, sr.V, sr.HitPoint);
            return(true);
        }
示例#2
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);
        }
示例#3
0
 public override bool Hit(Ray ray, double tMin, double tMax, out ShadeRec shadeRec)
 {
     if (obj.Hit(ray, tMin, tMax, out shadeRec))
     {
         shadeRec.Normal = -1 * shadeRec.Normal;
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#4
0
        public override bool Hit(Ray ray, double tMin, double tMax, out ShadeRec shadeRec)
        {
            Ray movedRay = new Ray(ray.Origin - offset, ray.Direction);

            if (ptr.Hit(movedRay, tMin, tMax, out shadeRec))
            {
                shadeRec.HitPoint = shadeRec.HitPoint + offset;
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#5
0
        public override bool Hit(Ray ray, double tMin, double tMax, out ShadeRec shadeRec)
        {
            shadeRec = new ShadeRec(); shadeRec.IsHit = false;
            double closestT = tMax;

            foreach (GeometryObject geometry in list)
            {
                ShadeRec tmp;
                if (geometry.Hit(ray, tMin, closestT, out tmp))
                {
                    shadeRec = tmp;
                    closestT = tmp.HitT;
                }
            }
            return(shadeRec.IsHit);
        }
示例#6
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);
        }
示例#7
0
        public ShadeRec HitAll(Ray ray)
        {
            ShadeRec srNearest = new ShadeRec(); srNearest.IsHit = false;

            foreach (GeometryObject geometry in geometrys)
            {
                ShadeRec tmp;
                geometry.Hit(ray, 1e-3, 1e15, out tmp);
                if (tmp.IsHit)
                {
                    if (!srNearest.IsHit)
                    {
                        srNearest = tmp;
                    }
                    else if (tmp.HitT < srNearest.HitT)
                    {
                        srNearest = tmp;
                    }
                }
            }
            return(srNearest);
        }
示例#8
0
        public override bool Hit(Ray ray, double tMin, double tMax, out ShadeRec shadeRec)
        {
            ShadeRec rec1, rec2; shadeRec = new ShadeRec();

            if (boundary.Hit(ray, -1e15, 1e15, out rec1))
            {
                if (boundary.Hit(ray, rec1.HitT + 1e-4, 1e15, out rec2))
                {
                    if (rec1.HitT < tMin)
                    {
                        rec1.HitT = tMin;
                    }
                    if (rec2.HitT > tMax)
                    {
                        rec2.HitT = tMax;
                    }
                    if (rec1.HitT >= rec2.HitT)
                    {
                        return(false);
                    }
                    if (rec1.HitT < 0)
                    {
                        rec1.HitT = 0;
                    }
                    double distanceInsideBoundary = (rec2.HitT - rec1.HitT) * ray.Direction.Magnitude();
                    double hitDistance            = -(1.0 / density) * Math.Log(Form2.random());
                    if (hitDistance < distanceInsideBoundary)
                    {
                        shadeRec.IsHit        = true;
                        shadeRec.HitT         = rec1.HitT + hitDistance / ray.Direction.Magnitude();
                        shadeRec.HitPoint     = ray.getPointAtRay(shadeRec.HitT);
                        shadeRec.Normal       = new Vector3D(Form2.random(), Form2.random(), Form2.random());
                        shadeRec.HitObjGloMat = phase_function;
                        return(true);
                    }
                }
            }
            return(false);
        }
示例#9
0
        SColor Render(Ray ray, int depth)
        {
            ShadeRec sr        = world.HitAll(ray);
            Ray      scattered = new Ray();

            if (sr.IsHit)
            {
                SColor emited      = sr.HitObjGloMat.emit(sr.U, sr.V, sr.HitPoint);
                SColor attenuation = new SColor(0, 0, 0);
                if (depth < 50 && sr.HitObjGloMat.scatter(ray, sr, out attenuation, out scattered))
                {
                    return(emited + attenuation * Render(scattered, depth + 1));
                }
                else
                {
                    return(emited);
                }
            }
            else
            {
                return(new SColor(0, 0, 0));
            }
        }
示例#10
0
 public override bool Hit(Ray ray, double tMin, double tMax, out ShadeRec shadeRec)
 {
     shadeRec = new ShadeRec(); shadeRec.IsHit = false;
     if (_box.hit(ray))
     {
         ShadeRec left_rec, right_rec;
         bool     hit_left  = left.Hit(ray, tMin, tMax, out left_rec);
         bool     hit_right = right.Hit(ray, tMin, tMax, out right_rec);
         if (hit_left && hit_right)
         {
             if (left_rec.HitT < right_rec.HitT)
             {
                 shadeRec = left_rec;
             }
             else
             {
                 shadeRec = right_rec;
             }
             return(true);
         }
         else if (hit_left)
         {
             shadeRec = left_rec;
             return(true);
         }
         else if (hit_right)
         {
             shadeRec = right_rec;
             return(true);
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
示例#11
0
 public override bool Hit(Ray ray, double tMin, double tMax, out ShadeRec shadeRec)
 {
     return(list_ptr.Hit(ray, tMin, tMax, out shadeRec));
 }