Forums > Jitter

accessing z-buffer texture when using jit.gl.cameras @capure 1

June 11, 2014 | 9:51 am

hi

I wonder: is there a way to access the z-buffer texture when using a jit.gl.camera with @capture 1? if not, can anybody tell me the algorithm used for creating a z-buffer texture? here my current solution. but while it looks ok, it somehow does not work with the SSAO-shaders I have found on the web so far. :-(

<jittershader name="depth">
	<description>
	shader to capture depth and linearize values (0-1)
	</description>
	
	<language name="glsl" version="1.0">	
		
		<program name="vp" type="vertex">
<![CDATA[

varying float depth;

void main (void)

{
 	vec4 viewPos = gl_ModelViewProjectionMatrix * gl_Vertex;
 			
	depth = -viewPos.z / viewPos.w;
	gl_Position = ftransform();
}
]]>		
		</program>
		<program name="fp" type="fragment">
<![CDATA[

varying float depth;

void main (void)
{
	gl_FragColor = vec4(depth * 0.5 + 0.5, depth * 0.5 + 0.5, depth * 0.5 + 0.5, 1.0);
}
]]>		
		</program>
	</language>
</jittershader>
  • This topic was modified 4 months by  maybites. Reason: clean up the code

June 11, 2014 | 11:04 am

you might check out this thread.

http://cycling74.com/forums/topic/linearized-depth-buffer-values-for-depth-of-field/


June 11, 2014 | 11:24 am

thanks, but I know already that solution (I started actually based on that depth shader) but it didnt work either.

There are different ways to encode the depth information in a texture, and I wondered how the z-buffer of opengl does it.


June 12, 2014 | 7:00 am

here’s one technique that gives a linearized, normalized depth buffer:

<jittershader name="shadow-caster">
   <param name="far_clip_distance" type="float" default="100." />
	<language name="glsl" version="1.2">
       <bind param="far_clip_distance" program="fp" />
		<program name="vp" type="vertex">
<![CDATA[
varying vec4 position;
 
void main(void) {
   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
   position = gl_ModelViewMatrix * gl_Vertex;
}
]]>
		</program>
		<program name="fp" type="fragment">
<![CDATA[
 
varying vec4 position;
uniform float far_clip_distance;
 
void main(void) {
   float depth = length(position.xyz) / far_clip_distance;
	gl_FragColor = vec4(depth);
}
]]>
		</program>
	</language>
</jittershader>

June 12, 2014 | 7:30 am

rob, thank you. I assume now the answer in regards of the z-buffer for @capture 1 is: no.


Viewing 5 posts - 1 through 5 (of 5 total)