#1
|
|||
|
|||
Depth buffer
Hello,
I need the depth information of each pixel, so I'm wondering if it is possible to render scenes in the z-buffer representation? (SEE figure at top of wiki article http://en.wikipedia.org/wiki/Depth_buffer ). Thanks, Andy |
#2
|
|||
|
|||
Even a method/plug-in for capturing the depth buffer and writing this data to a file would be helpful...
|
#3
|
|||
|
|||
You can use a render node to render the scene to a depth texture and display it on screen. Here is a quick example:
Code:
import viz viz.go() viz.add('piazza.osgb') # Add render texture using depth pixel format depth = viz.addRenderTexture(format=viz.TEX_DEPTH) # Use render node to render the scene to the depth texture rn = viz.addRenderNode() rn.setRenderTexture(depth) # Display depth texture on the screen quad = viz.addTexQuad(viz.SCREEN,size=200,align=viz.TEXT_LEFT_BOTTOM) # Use shader to display depth texture in linear range frag = """ uniform sampler2D depthTex; void main() { float d = texture2D(depthTex,gl_TexCoord[0].st).r; float n = 0.1; float f = 200.0; float z = (2 * n) / (f + n - d * (f - n)); gl_FragColor = vec4(z,z,z,1.0); } """ shader = viz.addShader(frag=frag) quad.apply(viz.addUniformInt('depthTex',0)) quad.apply(shader) quad.texture(depth) # Need to specify clip plane here and in shader viz.clip(0.1,200) |
#4
|
|||
|
|||
This is great! Thanks!
|
#5
|
|||
|
|||
Alright, one more question: Is there a way to size the quad so that is fits the exact dimensions of the window? I've tried, but I'm not sure how the 'size' parameter in viz.addTexQuad method translates into window coordinates.
I have tried inserting the following code into what you have written: # Get window size winsize = viz.MainWindow.getSize(viz.WINDOW_PIXELS) # Display depth texture on the screen quad = viz.addTexQuad(viz.SCREEN, size=1 ,align=viz.TEXT_CENTER_CENTER) quad.setPosition(.5,.5,0) quad.scale(winsize[0],winsize[1]) |
#6
|
|||
|
|||
If you want to view it fullscreen, then you're better off implementing the shader as a post-process effect:
Code:
import viz viz.go() viz.add('piazza.osgb') NEAR = 0.1 FAR = 200.0 from vizfx.postprocess.effect import BaseShaderEffect class DepthEffect(BaseShaderEffect): def _getFragmentCode(self): return """ uniform sampler2D vizpp_InputDepthTex; uniform float near; uniform float far; void main() { float d = texture2D(vizpp_InputDepthTex,gl_TexCoord[0].st).r; float z = (2 * near) / (far + near - d * (far - near)); gl_FragColor = vec4(z,z,z,1.0); } """ def _createUniforms(self): self.uniforms.addFloat('near',NEAR) self.uniforms.addFloat('far',FAR) viz.clip(NEAR,FAR) import vizfx.postprocess effect = DepthEffect() vizfx.postprocess.addEffect(effect) |
Tags |
depth buffer |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
eMagin HMD Quad buffer problem | Shay | Vizard | 1 | 11-30-2012 12:00 PM |
Issue Getting Quad Buffer Working | nabrahamson | Vizard | 2 | 08-30-2012 09:43 AM |
Does the vrpn7.dle tracker plug-in clear the udp buffer? | michaelrepucci | Vizard | 2 | 09-19-2008 10:22 AM |
depth perception for a DTI 3D monitor | timbo | Vizard | 5 | 07-16-2008 12:23 PM |
accessing screen buffer | hotspur1 | Vizard | 3 | 08-22-2003 03:31 PM |