Home Forums GAMES在线课程(现代计算机图形学入门)讨论区 作业3 interpolated_shadingcoords

Viewing 8 reply threads
  • Author
    Posts
    • #6759 Score: 0
      hyt589
      Participant
      2 pts

      有没有大神知道interpolated_shadingcoords是个什么东西啊,不知道怎么算

    • #6815 Score: 0
      chronoOverFlow
      Participant

      同问, 从名字上看是插值的底纹坐标, 但是根据下面的代码:
      payload.view_pos = interpolated_shadingcoords;
      我推测这个值应该是通过参数:
      const std::array<Eigen::Vector3f, 3>& view_pos
      得到的.

      我也只能猜…难受…

    • #6819 Score: 0
      chronoOverFlow
      Participant

      auto interpolated_shadingcoords = interpolate(alpha, beta, gamma, view_pos[0], view_pos[1], view_pos[2], 1);

      我是这样计算的, 希望会对你有一点参考.

    • #6832 Score: 0
      nuomi
      Participant

      插值得到的纹理坐标,实际上是UV,后面讲贝塞尔曲线时会讲到

    • #6935 Score: 14
      zzb
      Participant
      14 pts

      前面的回答都没有说到点子上!
      首先,你进行了光栅化,然后这个时候你其实是只知道像素坐标x,y的,经过深度插值,你得到了screen space中对应的某点的坐标(x,y,z)。这个坐标其实也不是真实世界(或者说camera space)里面的点!因为你想projection矩阵本质上是把视锥压缩成了长方体,你算出来的这个坐标是经历了压缩之后的。
      那么怎么才能知道camera space中像素对应过去的那个点呢?当然是插值!也就是利用alpha,beta,gamma结合rasterize_triangle传进来的参数viewspace_pos插值出来一个空间中的点。
      好了,我们得到了这个所谓的interpolated_shadingcoords,这个点有什么意义呢?这个点其实就是camera space中你真正在着色的那个点!这个点是你插值出来的,所以起了这么个名字。
      这个点知道了有什么用?你想想Bling Phong反射模型是不是需要一个叫r的参数,也就是着色点到光源的距离?我们需要拿光源位置和这个着色点来计算出r,同时得到一个light ray的单位向量(也就是那个所谓的向量l)!
      最后一个点:我们的重心坐标明明是在2D空间里做的啊?为什么可以拿来插值3D空间的坐标呢?
      答案是不行的!这个alpha,beta,gamma本质上是需要经过矫正才能用的!但是!其实误差不大,我们就直接拿过来用了。详见(https://stackoverflow.com/questions/24441631/how-exactly-does-opengl-do-perspectively-correct-linear-interpolation#:~:text=Perspective%20correct%20interpolation,-So%20let’s%20say&text=First%20we%20calculate%20its%20barycentric,on%20the%202D%20triangle%20projection.)

      This post has received 14 votes up.
    • #7062 Score: -1
      troot
      Participant
      -1 pt

      zzb,yyds

      This post has received 1 vote down.
    • #7066 Score: 2
      汤包喵喵喵
      Participant
      2 pts

      刚写完作业3来答一发!
      (一开始也完全不明白,因为老师讲课的时候其实没有提的很清楚。是看了程序框架然后猜出来的。。)
      以下是我的理解:

      首先在rasterizer.cpp里可以看到,interpolated_shadingcoords计算出来以后,直接赋给了payload.view_pos。
      然后在main.cpp中,可以找到payload.view_pos的最终用途是phong_shader用来做shading的那个三维空间坐标点,也就是shading2里面讲的blinn-phong光照模型的光线作用点。知道了这个点,就可以用来计算光线相关的参数了,比如:1.跟光源的距离R;2.跟视点之间的向量,然后计算出半程向量h。这一切都发生在哪个空间呢?答案是view space。

      这里有一个地方一定要搞懂。。。那就是光线作用是在哪一步进行。我的理解是在view space进行。
      经过了MV变换(model变换+viewpoint变换)的空间就是view space,这时所有空间点之间的相对位置都还是正常的,所以我们要在这个view_space来做shading,来计算光的入射和空间点的作用,这样才是正常的。
      经过了MVP变换的空间还是三维空间,但已经是被透视变换distorted的三维空间,因为Z被压缩了,所以不能用这个空间来做光线作用;
      经过了MVP变换+viewport变换的空间叫做screen space,已经是二维空间点了,准备好成为像素了。

      从rasterizer.cpp中的draw()函数中可以看到,viewspace_pos是只经过了MV变换的,是view space坐标,然后被传递给rasterize_triangle()。在每一个像素上插值后,成为interpolated_shadingcoords,传递给shader去做光线作用了。来龙去脉就是这样。

      This post has received 2 votes up.
      • #7924 Score: 2
        waqia
        Participant
        2 pts

        请问rasterizer.cpp的207-212这一段是啥意思呢,
        Eigen::Matrix4f inv_trans = (view * model).inverse().transpose();
        Eigen::Vector4f n[] = {
        inv_trans * to_vec4(t->normal[0], 0.0f),
        inv_trans * to_vec4(t->normal[1], 0.0f),
        inv_trans * to_vec4(t->normal[2], 0.0f)
        };
        为什么要给norm乘以inv_trans 呢?

        This post has received 2 votes up.
        • #8123 Score: 3
          akira
          Participant
          3 pts

          假设向量v的法线是n(有v.T * n = 0),v经过view*model变换后设为v’。因为也要变换法线坐标,但不能用view*model变换,需要保证变换之后其法线经过变换后n’仍然有(v’.T * n’ = 0),故要重新构造一个变换矩阵M,简单推导一下就得到inv_trans了。设v’.T * n’ = (view * model * v).T * (M * n) = 0,得到v.T * (view*model).T * M * n = 0,令(view *model).T * M为单位矩阵I,就能得到M就是代码中的inv_trans了

          This post has received 3 votes up.
    • #8604 Score: 0
      zzzlll
      Participant

      请问一下这个对法线进行MV逆变换的操作具体是什么意思呢?为什么需要这一步?
      按照您的理解是不是有这样的结论:
      向量v 及其 法线n 在mv变换后不具有角度不变性?
      但是在projection前不应该都是不变的吗?

      • #8614 Score: 0
        BernardLi
        Participant

        可以看一下LearnOpenGL里的解释, 在”最后一件事”那一节

        • #10505 Score: 0
          hibian
          Participant
          1 pt

          感谢,解决了我看代码时的疑惑。

    • #16710 Score: 0
      OliverThompson
      Participant

      With quick computerized progress, different sorts of designers become the most sought after subject matter experts. The asset TechRepublic.com has distributed a rundown of five most popular coder abilities, where .NET full stack engineer is the first. The ASP.NET Center and Blazor stay the most famous innovations. On Indeed.com you might secure around 16,000 thousand positions with depiction “Net Engineer”. There are much more employment opportunities for similar experts with somewhat various names. Organizations from various nations need to enlist full stack .NET engineer>> full stack developer net

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