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); }
public override bool Hit(Ray ray, float t_min, float t_max, ref HitRecord record) { throw new NotImplementedException(); }
public bool Hit(Ray ray, float t_min, float t_max, ref HitRecord record) { return(root.Hit(ray, t_min, t_max, ref record)); }
public virtual bool Refracted(Ray ray_in, HitRecord record, ref Ray refracted) { return(false); }
public virtual Ray GetScatteredRay(Ray ray_in, HitRecord record) { throw new NotImplementedException(); }
/// <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(); }
///懒得注释了,折射公式推一推就有了 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,等以后看看其他书籍比较一下
public override Ray GetScatteredRay(Ray ray_in, HitRecord record) { //漫反射 //取单位法向量 + 单位半径球上任意一点(可以理解为法向量的endpoint出发,指向球面任意一点) return(new Ray(record.hit_point, record.normal + utils.GenerateRandomVector(1f), ray_in.DeltaTime)); }