Ejemplo n.º 1
0
 public bool Hit(Ray ray, float t_min, float t_max, ref HitRecord record)
 {
     if (aabb != null && aabb.Hit(ray, t_min, t_max))
     {
         HitRecord temp1 = null;
         HitRecord temp2 = null;
         if (left_node != null && right_node != null)
         {
             bool hit_left  = left_node.Hit(ray, t_min, t_max, ref temp1);
             bool hit_right = right_node.Hit(ray, t_min, t_max, ref temp2);
             if (hit_left && hit_right)
             {
                 record = temp1.t < temp2.t ? temp1 : temp2;
                 return(true);
             }
             else if (hit_left)
             {
                 record = temp1;
                 return(true);
             }
             else if (hit_right)
             {
                 record = temp2;
                 return(true);
             }
         }
         else if (left_node != null)
         {
             if (left_node.Hit(ray, t_min, t_max, ref record))
             {
                 return(true);
             }
         }
         else if (right_node != null)
         {
             if (right_node.Hit(ray, t_min, t_max, ref record))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Ejemplo n.º 2
0
 public override bool Hit(Ray ray, float t_min, float t_max, ref HitRecord record)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 3
0
 public bool Hit(Ray ray, float t_min, float t_max, ref HitRecord record)
 {
     return(root.Hit(ray, t_min, t_max, ref record));
 }
Ejemplo n.º 4
0
 public virtual bool Refracted(Ray ray_in, HitRecord record, ref Ray refracted)
 {
     return(false);
 }
Ejemplo n.º 5
0
 public virtual Ray GetScatteredRay(Ray ray_in, HitRecord record)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="light">光源</param>
 /// <param name="view_ray">视线</param>
 /// <param name="record">相交信息</param>
 /// <param name="depth">渲染深度</param>
 /// <returns></returns>
 public virtual Vec3 GetColor(BaseLight light, Ray view_ray, HitRecord record, float depth)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 7
0
        ///懒得注释了,折射公式推一推就有了
        public override bool Refracted(Ray ray_in, HitRecord record, ref Ray refracted)
        {
            Vec3  outward_normal;
            float ni_over_nt;

            # region 判断从空气到介质还是介质到空气.此外这里折射计算可能有误,参考的ray tracing in one weekend,等以后看看其他书籍比较一下
Ejemplo n.º 8
0
 public override Ray GetScatteredRay(Ray ray_in, HitRecord record)
 {
     //漫反射
     //取单位法向量 + 单位半径球上任意一点(可以理解为法向量的endpoint出发,指向球面任意一点)
     return(new Ray(record.hit_point, record.normal + utils.GenerateRandomVector(1f), ray_in.DeltaTime));
 }