Пример #1
0
        public override bool Scatter(RayComponent ray, ref HitInfo result, ref ScatterInfo info)
        {
            float fuzz   = Value.fuzz;
            Color albedo = Value.albedo;

            Vector3 reflected = math.reflect(ray.Value.direction, result.normal);

            info.direction   = reflected + fuzz * RandomUtility.RandomInUnitSphere();
            info.attenuation = albedo;
            info.position    = result.position;
            return(false);
        }
        public override bool Scatter(RayComponent ray, ref HitInfo result, ref ScatterInfo scatterInfo)
        {
            scatterInfo.attenuation = Color.white;
            scatterInfo.position    = result.position;

            float refIdx = Value.refractiveIndex;

            float   ni_over_nt;
            Vector3 outwardNormal;
            float   cosine = math.dot(ray.Value.direction, result.normal);

            if (cosine > 0.0f)
            {
                outwardNormal = -result.normal;
                ni_over_nt    = refIdx;
                cosine        = ni_over_nt * cosine / math.length(ray.Value.direction);
            }
            else
            {
                outwardNormal = result.normal;
                ni_over_nt    = 1.0f / refIdx;
                cosine        = -cosine / math.length(ray.Value.direction);
            }

            float   reflectProb = 1.0f;
            Vector3 refracted;

            if (MathUtility.Refract(ray.Value.direction, outwardNormal, ni_over_nt, out refracted))
            {
                reflectProb = MathUtility.FresnelSchlick(cosine, refIdx);
            }

            if (RandomUtility.RandomNDF() < reflectProb)
            {
                scatterInfo.direction = math.reflect(ray.Value.direction, result.normal);
            }
            else
            {
                scatterInfo.direction = refracted;
            }

            return(true);
        }
Пример #3
0
 public static bool Hit(RayComponent r, float min, float max, AABB aabb, ref HitInfo info)
 {
     return(false);
 }
Пример #4
0
 public virtual Vector3 Emmitted(RayComponent rayIn, ref HitInfo result, float u, float v, Vector3 point)
 {
     return(Vector3.zero);
 }
Пример #5
0
 public virtual bool Scatter(RayComponent ray, ref HitInfo result, ref ScatterInfo info)
 {
     return(false);
 }
Пример #6
0
 public abstract bool Hit(RayComponent ray, float min, float max, ref HitInfo info);