Depth Texture in Panda3D
In Panda3D, I have the following code
self.manager = FilterManager(base.win, base.cam)
self.sceneTex = Texture("scene")
self.depthTex = Texture("depth")
self.quad = self.manager.renderSceneInt开发者_运维技巧o(colortex=self.sceneTex, depthtex = self.depthTex)
...
When I run the above and enable view buffers (show-buffers #t), the "sceneTex" texture looks right. However, "depthTex" is always blank (all black) no matter where I move the camera to. Anyone know what's wrong?
Thanks
Perhaps you have disabled your depth test writing ? Even though you might not get any obvious artifacts (depends on your scene) you could be running without a depth buffer. Look in the panda tutorial about depth buffer writing it also tells you about some scenes work better with depth sorting (you perhaps tested this but not reverted your depth buffer disabling code?)
I ran into the same problem. I had to create a custom shader to extract the depth. Since I wanted more than 8 bits of depth information, I had to convert the depth into 3 8-bit fields that could go in the RGB components of the image.
In Panda3D Python:
# Set up Shader
dcam = loader.loadShader('Dcam.sha')
# render everything through this camera and shader
self.terrain.getRoot().setShader(dcam)
The shader inputs and outputs also need to be set up (i.e. vtx_position, mat_modelproj, etc. See the examples in the Panda3D documentation.
In 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);
}
精彩评论