Home › Forums › GAMES在线课程(现代计算机图形学入门)讨论区 › 作业6渲染时间过长是为什么
- This topic has 4 replies, 4 voices, and was last updated 3 years ago by
brian.
Viewing 2 reply threads
-
AuthorPosts
-
-
Jay.shen
Participant问题代码如下 为Bound3.hpp中的 IntersectP
double t_x_min = (pMin.x - ray.origin.x)*invDir[0]; double t_x_max = (pMax.x - ray.origin.x)*invDir[0]; double t_y_min = (pMin.y - ray.origin.y)*invDir[1]; double t_y_max = (pMax.y - ray.origin.y)*invDir[1]; double t_z_min = (pMin.z - ray.origin.z)*invDir[2]; double t_z_max = (pMax.z - ray.origin.z)*invDir[2]; //计算出了每个包围盒的对面的tmin和tmax //now we should judge the tmin and tmax according to the light's dirctions if(!dirIsNeg[0]){ //光线不是正方向的 tmin和tmax反一下 double tmp = t_x_min; t_x_min = t_x_max; t_x_max = tmp; } if(!dirIsNeg[1]){ //光线不是正方向的 tmin和tmax反一下 double tmp = t_y_min; t_y_min = t_y_max; t_y_max = tmp; } if(!dirIsNeg[2]){ //光线不是正方向的 tmin和tmax反一下 double tmp = t_z_min; t_z_min = t_z_max; t_z_max = tmp; } float t_enter = std::min(t_x_min,std::min(t_y_min,t_z_min)); float t_exit = std::max(t_x_max,std::max(t_y_max,t_z_max)); if(t_enter < t_exit && t_exit > 0){ return true; } else{ return false; } -
Jay.shen
Participant运行时间长达十几分钟才渲染出来 运行答案中的正确代码只需要4秒。。。求解惑这个地方哪里写的有问题
-
南
Participant你可以看一下BVH的递归调用这块,判断左右孩子节点的distance谁更小,应该提前用两个intersection变量 保存左右孩子节点的递归调用返回值,再比较distance。千万不要比较distance之后又递归调用一次getIntersection得到返回值,这样树的层数比较高时函数递归调用的次数会爆炸。我刚开始就是这种情况,渲染需要花10min,改了之后只需3秒。
-
-
Tiayna
Participanthjh,我今天遇到了个和你一模一样的问题,跑了好几分钟才20%,寻思没报错也没啥不对劲(分辨率挺大的貌似),然后上论坛看了看别人的,都是几秒或者十几秒的,然后检查了下代码然后修改之后几秒就跑完了。回到正题,直接上错误代码:float t_enter = std::min(t_x_min,std::min(t_y_min,t_z_min)); 问题出在哪呢,回顾课程的话就一目了然了,进入时间enter,应该取各截面进入时间的最大值(就是所有截面都进入了才算真正进入了AABB的意思),所以应该改成float t_enter = std::max(t_x_min,std::max(t_y_min,t_z_min)); t_exit同理
-
brian
Participant我也是一模一样的问题哈哈哈,感谢老哥解答。分析了下,按照错误代码这么写的话包围盒就变得巨大,虽然不会影响最后的输出,但会造成很多无用的运算量,这也是为啥虽然结果是对的,但是耗时很长。
-
-
-
AuthorPosts
Viewing 2 reply threads
- You must be logged in to reply to this topic.