Home Forums GAMES在线课程(现代计算机图形学入门)讨论区 作业7 简单抗锯齿出现毛边

Viewing 4 reply threads
  • Author
    Posts
    • #6483 Score: 1
      oxine
      Participant
      9 pts

      原来的代码是这样的:

      
      float x = (2 * (i + 0.5 ) / (float)scene.width - 1) * imageAspectRatio * scale;
      float y = (1 - 2 * (j + 0.5) / (float)scene.height) * scale;
      

      真的很简单,把下面代码中的0.5改成get_random_float()

      
      float x = (2 * (i + get_random_float() ) / (float)scene.width - 1) * imageAspectRatio * scale;
      float y = (1 - 2 * (j + get_random_float()) / (float)scene.height) * scale;
      

      原来的代码是在像素的中心点采样的,现在我们在整个像素中随机采样,思路类似SSAA, 得益于spp的存在,都不用多加一层循环了。

      现在锯齿是没有了,但是不可避免的出现毛边,一开始我还以是因为spp不够,拉到512,边依然是毛糙的。

      我的EPSILON = 0.01,测试下来好像与epsilon无关。

      This post has received 1 vote up.
      Attachments:
      You must be logged in to view attached files.
    • #6485 Score: 0
      oxine
      Participant
      9 pts

      有条件的同学试着跑跑看吧,我想不明白了…

    • #6488 Score: 1
      arc
      Participant
      5 pts

      直接修改的话会导致每个像素都取到某一个固定的位置上,产生毛边是正常的。
      你需要在计算每一个样本的时候都计算一个随机的位置,这样才会产生平滑的结果。

      This post has received 1 vote up.
      • This reply was modified 4 years, 6 months ago by arc.
      Attachments:
      You must be logged in to view attached files.
    • #6495 Score: 0
      oxine
      Participant
      9 pts

      对哦,有道理!我的xy在spp的循环内都是不变的,我太蠢了先前没想到,谢谢大佬解答!

      • This reply was modified 4 years, 6 months ago by oxine.
    • #6497 Score: 0
      oxine
      Participant
      9 pts

      修改起来很方便,把xy以及射线的生成挪到spp循环内部就行了,这样可以节省一次循环

      for (int k = 0; k < spp; k++){
      	//generate primary ray direction
      	float x = (2 * (i + get_random_float()) / (float)scene.width - 1) * imageAspectRatio * scale;
      	float y = (1 - 2 * (j + get_random_float()) / (float)scene.height) * scale;
      	Vector3f dir = normalize(Vector3f(-x, y, 1));
      	auto index = j*scene.width + i;
              framebuffer[index] += scene.castRay(Ray(eye_pos, dir), 0) / spp;
      }

      在低spp情况下也能获取不错的效果

      Attachments:
      You must be logged in to view attached files.
Viewing 4 reply threads
  • You must be logged in to reply to this topic.