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]> > 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]> > >> 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]> >> >>> 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] >>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >>> >> >> > > > _______________________________________________ > osg-users mailing > [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

