Home Forums GAMES在线课程(现代计算机图形学入门)讨论区 【作业二提高】维护了两个buffer无法出现正确的图

Tagged: 

Viewing 6 reply threads
  • Author
    Posts
    • #3534 Score: 0
      PeterSen
      Participant
      2 pts

      depth_buffer和sample_frame_buffer大小都为(4*w*h),sample_frame_buffer初始化为0.思路是在遍历2*2的点时不断更新两个buffer,如果深度小于当前buffer存的值,更新depth_buffer和sample_frame_buffer。每次遍历都加入颜色信息到pixel_color中。然后每结束一个像素点的四次遍历后就开始绘图。结果是整个三角形都变成黄色了。希望大佬们看看哪里出了问题

      Attachments:
      You must be logged in to view attached files.
    • #3536 Score: 0
      Angus
      Participant
      23 pts

      如果我没推错的话,假设你前三个采样点都采样到了颜色,但如果第四个采样点没有通过insideTriangle(),就不会触发setColor()方法,这是不是不太对呢?

      • #3537 Score: 0
        PeterSen
        Participant
        2 pts

        这个地方确实有问题,已经修改,但是输出图片还是全部为黄色

        Attachments:
        You must be logged in to view attached files.
      • #3539 Score: 0
        PeterSen
        Participant
        2 pts

        奇怪的结果图

        Attachments:
        You must be logged in to view attached files.
    • #3542 Score: 0
      戴皓天
      Participant
      9 pts
      if(inside_num>0&&i==3)
       ......
      

      这一段是不是应该放到

      for(int i=0;i<4;i++)
      {
      ....
      }

      的外面?

      ps:既然你已经更新了,那就不是这个的问题,我再看看

      • This reply was modified 4 years, 1 month ago by 戴皓天.
    • #3545 Score: 0
      戴皓天
      Participant
      9 pts

      pixel_color初始化的问题?
      pixel_color是不是应该在每个

      for(int i=0;i<4;i++)
      {
      ....
      }

      循环外面初始化一下?

      • #3549 Score: 0
        PeterSen
        Participant
        2 pts

        谢谢大佬,是忘了初始化。不过发现生成的图仍然有比较明显的锯齿。不知道对不对

        Attachments:
        You must be logged in to view attached files.
      • #3554 Score: 0
        PeterSen
        Participant
        2 pts

        对比了一下非附加题生成的图片。发现没有优化,依旧不知道问题出在了哪里

        • #3562 Score: 0
          戴皓天
          Participant
          9 pts

          光看你这段代码好像没什么问题。。

          • #3586 Score: 1
            PeterSen
            Participant
            2 pts

            这是修改过的代码,还是毫无优化,快哭了

            This post has received 1 vote up.
            Attachments:
            You must be logged in to view attached files.
            • #3594 Score: 0
              Bear
              Participant
              -11 pt

              我强答一波。。。你把 pixel_color 更新的那行从深度的判断条件里移出来,因为获得的值直接就是 1/4 了,所以按上图的代码的话整体像素值会变小

            • #3599 Score: 0
              sublimation
              Participant
              3 pts

              楼上说的是对的,pixel_color 更新的那行从深度的判断条件里移出来。
              原因是,即使当前亚像素的深度是比之前的图形深度“深”,同样也需要对当前像素的最终颜色做出贡献,加上之前的颜色。

              • #3602 Score: 0
                PeterSen
                Participant
                2 pts

                不知道是否理解了二位的意思,这是改过之后的代码。依旧是一点优化都没有(跟没做提高的一模一样)。图形学小白有点晕了

                Attachments:
                You must be logged in to view attached files.
    • #3548 Score: 0
      PeterSen
      Participant
      2 pts

      对第一个i==3保证在最后一个sample点之后才set_pixel,放出去的话程序效率会提高。谢谢提醒。
      第二个地方我没截屏截到,sample_frame_buf是我自己后来定义的一个数组,大小是4*w*h,这里没有修改用于画图的frame_buffer。这个数组用于保存当前的每个采样点的颜色信息。

    • #3715 Score: 0
      狂草来书
      Participant
      2 pts

      看了你的问题,我终于解决了自己碰到的困难,我之前一直没有注意到get_index(x,y)函数来获取depth_buffer的索引,一直是自己计算,结果发生了奇怪的错误。希望有我这样问题的人也能如此解决。

    • #6828 Score: 0
      dafei
      Participant

      检查一下 insideTriangle 这个函数是不是传参数的时候用了 int 导致小数部分被抹除

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