Thread: Depth buffer
View Single Post
  #6  
Old 03-22-2013, 02:54 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
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)
Reply With Quote