Ejemplo n.º 1
0
        Color GetColorForTestDefocus(Ray ray, HitableList hitableList, int depth)
        {
            HitRecord record = new HitRecord();

            if (hitableList.Hit(ray, 0.0001f, float.MaxValue, ref record))
            {
                Ray   r           = new Ray(Vector3.zero, Vector3.zero);
                Color attenuation = Color.black;
                if (depth < MAX_SCATTER_TIME && record.material.scatter(ray, record, ref attenuation, ref r))
                {
                    Color c = GetColorForTestDefocus(r, hitableList, depth + 1);
                    return(new Color(c.r * attenuation.r, c.g * attenuation.g, c.b * attenuation.b));
                }
                else
                {
                    //假设已经反射了太多次,或者压根就没有发生反射,那么就认为黑了
                    return(Color.black);
                }
            }
            float t = 0.5f * ray.normalDirection.y + 1f;

            return((1 - t) * new Color(1, 1, 1) + t * new Color(0.5f, 0.7f, 1f));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 材质表面发生的光线变化过程
 /// </summary>
 /// <param name="rayIn"></param>
 /// <param name="record"></param>
 /// <param name="attenuation"></param>
 /// <param name="scattered"></param>
 /// <returns>是否发生了光线变化</returns>
 public abstract bool scatter(Ray rayIn, HitRecord record, ref Color attenuation, ref Ray scattered);
Ejemplo n.º 3
0
 public abstract bool Hit(Ray ray, float t_min, float t_max, ref HitRecord rec);