【问题标题】:Depth Texture in Panda3DPanda3D 中的深度纹理
【发布时间】:2010-10-08 19:14:18
【问题描述】:

在 Panda3D 中,我有以下代码

self.manager = FilterManager(base.win, base.cam)

self.sceneTex = Texture("scene")
self.depthTex = Texture("depth")


self.quad = self.manager.renderSceneInto(colortex=self.sceneTex, depthtex = self.depthTex)

...   

当我运行上述程序并启用视图缓冲区 (show-buffers #t) 时,“sceneTex”纹理看起来正确。但是,无论我将相机移动到哪里,“depthTex”总是空白(全黑)。有谁知道怎么回事?

谢谢

【问题讨论】:

    标签: python 3d panda3d


    【解决方案1】:

    也许您禁用了深度测试写作?即使您可能没有得到任何明显的伪影(取决于您的场景),您也可以在没有深度缓冲区的情况下运行。查看panda tutorial about depth buffer writing,它还告诉您一些场景在深度排序方面效果更好(您可能对此进行了测试,但没有恢复您的深度缓冲区禁用代码?)

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题。我必须创建一个自定义着色器来提取深度。由于我想要超过 8 位的深度信息,因此我必须将深度转换为 3 个 8 位字段,这些字段可以进入图像的 RGB 分量。

      在 Panda3D Python 中:

      # Set up Shader
      dcam = loader.loadShader('Dcam.sha')
      # render everything through this camera and shader
      self.terrain.getRoot().setShader(dcam)
      

      还需要设置着色器输入和输出(即 vtx_position、mat_modelproj 等。请参阅 Panda3D 文档中的示例。

      在 Dcam.sha 中:

      //Cg
      
      void vshader(float4 vtx_position : POSITION,
                   uniform float4x4 mat_modelproj,
                   out float4 l_position : POSITION,
                   out float4 l_pos : TEXCOORD0)
      {
          float4 position = vtx_position;
          l_pos = mul(mat_modelproj, position);
          l_position = l_pos;
      }
      
      void fshader(in float4 l_pos : TEXCOORD0,
                   out float4 o_color : COLOR)
      {
          float z = (l_pos.z / l_pos.w) * 0.5 + 0.5;
          float zres = 16777216.0 * z;
          float v0 = round(zres / 65536.0);
          zres = zres - 65536.0 * v0;
          float v1 = round(zres / 256.0);
          zres = zres - 256.0 * v1;
          float v2 = round(zres);
          o_color = float4(v0, v1, v2, 1);
      }
      

      【讨论】:

        猜你喜欢
        • 2014-05-11
        • 1970-01-01
        • 1970-01-01
        • 2011-11-06
        • 2011-10-09
        • 1970-01-01
        • 2013-05-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多