Home Forums GAMES在线课程(现代计算机图形学入门)讨论区 作业3:小牛正面或背面正对镜头时出现缝隙

  • This topic has 2 replies, 2 voices, and was last updated 2 years ago by _HUA.
Viewing 2 reply threads
  • Author
    Posts
    • #10827 Score: 0
      happyfire
      Participant
      4 pts

      将angle设置为0或180时,发现小牛身体中间出现一条缝,是缝不是黑线。但是0.2或179.9就没有。(0.1会crash)
      大家有遇到了吗?可能是什么原因呢?

      Attachments:
      You must be logged in to view attached files.
    • #11032 Score: 0
      happyfire
      Participant
      4 pts

      找到原因了,作业3框架Texture类getColor方法有bug:

      Eigen::Vector3f getColor(float u, float v)
      {
      auto u_img = u * width;
      auto v_img = (1 – v) * height;
      auto color = image_data.at<cv::Vec3b>(v_img, u_img);
      return Eigen::Vector3f(color[0], color[1], color[2]);
      }

      uv坐标转像素坐标的时候,不能直接乘width和height。这是因为uv坐标的范围是[0,1],而像素坐标的范围是[0,width-1]和[0,height-1]。如果直接乘width,height。那么uv为1的时候,坐标就会越界。但是作业框架使用的库对于越界的像素坐标并不会crash或报错,而是返回一个透明值,因此小牛uv为1的地方就没有颜色了。
      正确的方法是:

      auto u_img = u * (width-1);
      auto v_img = (1 – v) * (height-1);

      另外打个广告,以GAMES101的理论为基础,在Unity平台上实现了一个光栅化渲染器,同时支持多核和GPGPU加速
      https://github.com/happyfire/URasterizer

      Attachments:
      You must be logged in to view attached files.
    • #11086 Score: 0
      _HUA
      Participant

      此处的确是个 bug,但应该并不是导致缝隙的原因。因为在 normal_fragment_shader & phong_fragment_shader 中并没有使用这个 texture,但依然会有缝隙的现象

Viewing 2 reply threads
  • You must be logged in to reply to this topic.