Re: [osg-users] problem with linear depth in fragment shader
Hello Peterakos: Hello. I try to create linear values for depth using the following code: Vertex Shader float depth_in_eye_space = (gl_ModelViewMatrix * gl_Vertex).z; depth = (-depth_in_eye_space - near)/(far - near); //depth is varying Fragment Shader gl_FragColor = vec4(depth, depth, depth, 1); The problem is that in the depth texture, many different levels of depth are creating. (attached 1) As Wang Rui already said, use a floating point buffer if precision is a problem. Another option would be to use the stock depth buffer (i.e. depth buffer and don't write the depth yourself) and re-linearize it in you SSAO pass, That causes problems in my next pass which uses the depth texture to create an ssao image. (attached 2) The artifacts that you are seeing here will not disappear completely. As you didn't provide any shader code I can only guess that you are not biasing the lookups for the SSAO. In my SSAO Implementation (heavily based on http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/a-simple-and-practical-approach-to-ssao-r2753 I have this artifacts as well If I don't use correct bias values. How can i get the right depth values in depth texture ? They are right, They are just not what you want them to be ;-) hth Sebastian Thnx. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] problem with linear depth in fragment shader
Hi Peterakos, Try changing the internal format of the output buffer to float32. I guess it is a precision problem. During the SSAO implementation of effect compositor (in osgRecipes now) I also encountered the problem and using 32 bit float values seems good to me. Wang Rui 2012/11/9 Peterakos > Hello. > > I try to create linear values for depth using the following code: > > > Vertex Shader >float depth_in_eye_space = (gl_ModelViewMatrix * gl_Vertex).z; >depth = (-depth_in_eye_space - near)/(far - near); //depth is varying > > Fragment Shader >gl_FragColor = vec4(depth, depth, depth, 1); > > > The problem is that in the depth texture, many different levels of > depth are creating. (attached 1) > That causes problems in my next pass which uses the depth texture to > create an ssao image. (attached 2) > > How can i get the right depth values in depth texture ? > > Thnx. > > ___ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] problem with linear depth in fragment shader
Not sure if the different levels of depth are distinguishable in first image. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org