2.5 BVH 渲染 没有图像

计算机图形学 bvh 446 views 2 replies 🔒 closed
#1 ·

BVH 的建立没有问题
图片

但是渲染没有图像出现
图片

optional<Intersection> BVH::ray_node_intersect(BVHNode* node, const Ray& ray) const
{
    .....
    if (node->left == nullptr && node->right == nullptr) {
        isect = ray_triangle_intersect(ray, mesh, node->face_idx);
        return isect;
    } else{
        auto isect_left  = ray_node_intersect(node->left, ray);
        auto isect_right = ray_node_intersect(node->right, ray);

        return isect_left->t < isect_right->t ? isect_left : isect_right;
    }
}

图片

ray_triangle_intersect() 函数有正常的返回值,但是 BVH::intersect() 中得到的 isect 一直为空,请问会是哪里的问题呢 😭

optional<Intersection> BVH::intersect(const Ray& ray, [[maybe_unused]] const GL::Mesh& mesh,
                                      const Eigen::Matrix4f obj_model){
    .......
    isect = ray_node_intersect(root, model_ray);
    if (isect.has_value()) {
        isect->normal = (model_inv.transpose() *
                         Vector4f(isect->normal.x(), isect->normal.y(), isect->normal.z(), 0.0f)).head<3>();
    }
    return isect;
}
#2 ·

你的遍历考虑掉了左右子树之一是空,而另一侧还有子节点的情况,不妨改了之后再试一试

#3 ·

感谢学长 🥳

🔒 Closed