Tech Forums > General Discussion

Accessing the depth buffer in GLSL

(1/4) > >>

oli3012:
Hi! I am currently trying to implement DOF in GeeXLab 0.1.14, but I am unable to access the Depth Buffer. I started from a shader of the shader library, and that's what my code looks like:

       <render_texture name="sceneBuffer" type="FRAMEBUFFER" >
      <attach_texture_depth pixel_format="DEPTH"/>
      <attach_render_buffer type="DEPTH" />
   </render_texture>


   <post_processing name="MainPostProcessing">
      <effect name="Dream_Effect">
         <phase name="Dream_Effect_Phase">
            <step name="_1" target="FRAMEBUFFER" gpu_shader="DreamShader" >
               <texture render_texture="sceneBuffer" render_texture_type="DEPTH" render_texture_index="0" />
            </step>
         </phase>
      </effect>
   </post_processing>


   <shader_program name="DreamShader" >
      <constant_1i name="sceneTex" value="0" />
      <raw_data><![CDATA[   
[Vertex_Shader]
void main(void)
{
  gl_Position = ftransform();
  gl_TexCoord[0] = gl_MultiTexCoord0;
}
[Pixel_Shader]
uniform sampler2D sceneTex; // 0
void main()
{
  vec2 uv = gl_TexCoord[0].xy;
  float c = texture2D(sceneTex, uv);
 
  gl_FragColor = c == 0.0 ? vec4(1.0) : vec4(0.0);
}
      ]]></raw_data>
   </shader_program>


My screen is completely white, which means that the depth of every pixel is equal to 0... Could someone see if I made an error here, or send me a piece of code that can access the depth buffer ? Thank you for your help!

JeGX:
I'm preparing a small demo to display the depth buffer...

JeGX:
Demo posted here:
http://www.geeks3d.com/20091216/geexlab-how-to-visualize-the-depth-buffer-in-glsl/

Hope this will help you  ;)

oli3012:
Wow thank you! This really helped me out! I finally achieved the effect I desired ; a dynamic DOF using 5x5 Gaussian blur. Here is a screenshot of the result:



There is still some optimizations to do, I must find a way to diminish the bleeding around near objects, and I will try manual down sampling to get better performances, but that's a start !

If someone wants to try it, here is the code: http://www.mediafire.com/?dojdnmwrmid

JeGX:
Absolutely nice work man!
I think I'll publish your demo officially on Geeks3D front page.

I recommend you to manage window resizing with a SIZE script like this:

--- Code: ---<script name="resize" run_mode="SIZE" >
  <raw_data><![CDATA[
  local w, h = HYP_Scene.GetWindowSize()
  id = HYP_GPUShader.GetId("HorizontalBlur")
  HYP_GPUShader.SetConstant_1f(id, "texWidth", w)
  id = HYP_GPUShader.GetId("VerticalBlur")
  HYP_GPUShader.SetConstant_1f(id, "texHeight", h)
  ]]></raw_data>
</script>

--- End code ---


Navigation

[0] Message Index

[#] Next page

Go to full version