Yes it should be completely white usually. But this depends also on the format choosen for the depth buffer, the near/far plane distances and the clear value. Maybe you could place some objects of known distance and use the advice about linearizing the depth display. Also I'm not sure what fixed function fragment shader will do here, so go with your own shader and display the depth to a fullscreen quad,
First step is to do:
gl_FragColor = vec4(vec3(texture2D(depthBuffer,tex_coord).r,1.0);

Maybe you texture coordinates for the depth HUD are screwed and you are looking at some weird interpolated value (e.g. black bordercolor and top left pixel)

hth
Sebastian


But is it ok that the whole depth buffer texture is gray no matter how I turn the scene? Shouldn't it be completely white (or black) where there's no scene at all?


2013/10/9 Sebastian Messerschmidt <[email protected] <mailto:[email protected]>>

    Am 09.10.2013 10:58, schrieb michael kapelko:
    Hi.
    I've added rendering of the depth buffer of the scene to the
    depth texture from the point of view of the main camera (not the
    light), but it's always gray as seen here at the bottom left:
    http://youtu.be/qTHWE5_ZPXQ
    It only changes to black when I'm almost at the end of the scene.
    And when I'm behind it, it's gray again.
    That is perfectly normal, as the values in the depth buffer are
    not linear but logarithmic.
    So values with small distance to the near clipping plane take up
    much more "digits" than those far away.
    You should add a shader to the debug display to account for this.
    Therefore you should pass near,far clipping plane values and
    "renormalize" the displayed depth value.
    I cannot give you the code snippet right now, as I don't have the
    project here, but you should find it easily using google.
    cheers
    Sebastian


    Here's my:
    1) depth texture setup: http://goo.gl/plsc1U
    2) RTT camera that writes to the depth texture: http://goo.gl/eYS6pC
    3) display of the resulting depth texture: http://goo.gl/N5hUxb

    What am I doing wrong?
    Thanks.



    2013/10/9 michael kapelko <[email protected]
    <mailto:[email protected]>>

        Hi.
        Thanks a lot! I totally missed vec4 position when I tried to
        use only vec3 one with osg_ViewMatrixInverse.


        2013/10/8 Marcel Pursche
        <[email protected]
        <mailto:[email protected]>>

            Hi,

            I don't know if you already found the solution to your
            problem, but this is how you can calculate the camera
            position in worldspace:


            Code:

            vec4 cameraPos_wordspace = osg_ViewMatrixInverse *
            vec4(0.0, 0.0, 0.0, 1.0);




            The rotation and scale factors can be found in the first
            three rows and columns of a matrix, so if you only want
            to compute a rotation and scale it is sufficient to use a
            3x3 matrix.
            But to mathematically compute a translation of a vector
            you need to use a 4x4 matrix. The vector needs to be
            expanded to the 4th dimension, as-well to make it
            compatible with the matrix for multiplication.

            Here is how it works:


            Code:

            M * v = v'
            <==>
            1 0 0 tx * x = 1*x + 0*y + 0*z + tx * 1
            0 1 0 ty * y = 0*x + 1*y + 0*z + ty * 1
            0 0 1 tz * z = 0*x + 0*y + 1*z + tz * 1
            0 0 0 1 * 1 = 0*x + 0*y + 0*z + 1*1



            (These are the rows of a matrix not individual equations,
            I wasn't able to format it in a good way, sorry)

            no if we simplify this we get:

            Code:

              x+tx
            = y+ty
              z+tz
              1




            As we can see it all boils down to adding an offset the
            the original vector. For the rest of your computations
            you can just ignore the w component of the vector.
            I hope I was able to shed some light on the dark ;)
            Thank you!

            Cheers,
            Marcel

            ------------------
            Read this topic online here:
            http://forum.openscenegraph.org/viewtopic.php?p=56677#56677





            _______________________________________________
            osg-users mailing list
            [email protected]
            <mailto:[email protected]>
            
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org





    _______________________________________________
    osg-users mailing list
    [email protected]  
<mailto:[email protected]>
    http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


    _______________________________________________
    osg-users mailing list
    [email protected]
    <mailto:[email protected]>
    http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to