Home Forums GAMES在线课程(现代计算机图形学入门)讨论区 作业三,光照模型和问题

Viewing 5 reply threads
  • Author
    Posts
    • #7556 Score: -2
      偏偏123456
      Participant

      phong_fragment_shader 光照模型

      Eigen::Vector3f light_dir = light.position – point;
      Eigen::Vector3f view_dir = eye_pos – point;
      float r = light_dir.dot(light_dir);
      // ambient
      Eigen::Vector3f La = ka.cwiseProduct(amb_light_intensity);
      // diffuse
      Eigen::Vector3f Ld = kd.cwiseProduct(light.intensity / r);
      Ld *= std::max(0.0f, normal.normalized().dot(light_dir.normalized()));

      Eigen::Vector3f h = (light_dir + view_dir).normalized();

      Eigen::Vector3f Ls = ks.cwiseProduct(light.intensity / r);
      Ls *= std::pow(std::max(0.0f, normal.normalized().dot(h)), p);
      result_color += (La + Ld + Ls);

      有个问题:结果变成了黑白小牛,从光栅化的角度来讲。

      This post has received 1 vote down.
      Attachments:
      You must be logged in to view attached files.
    • #7558 Score: 1
      偏偏123456
      Participant

      使用normal_fragment_shader 的情况

      This post has received 1 vote up.
      Attachments:
      You must be logged in to view attached files.
    • #7560 Score: 1
      偏偏123456
      Participant

      是不是光栅化还是有问题你,因为同样的光栅化方法,normal_fragment_shader 可以正确显示。可能是哪块除了问题,应该从哪个角度考虑解决方法呢。

      This post has received 1 vote up.
    • #7574 Score: -1
      cggg
      Participant
      -2 pt

      light_dir , view_dir 都应该单位化,公式里面的几个向量都是单位向量。

      This post has received 1 vote up and 1 vote down.
    • #7575 Score: -1
      cggg
      Participant
      -2 pt

      (light_dir + view_dir).normalized(); 应该先单位化,否则结果错误。

      This post has received 1 vote down.
    • #7576 Score: -1
      偏偏123456
      Participant

      @cggg 谢谢~

      This post has received 1 vote down.
Viewing 5 reply threads
  • You must be logged in to reply to this topic.