--nologdepth leads to culling of near features #2374
-
Hello, I'm trying to solve the problem I outlined in issue #2366 , where @gwaldron and @timoore suggested to use the Although it looks like this solves my original problem (not sure yet, though), a new one is raised: when camera plane is orthogonal to the ground (or close to this condition), I lose a lot of content, as shown in pic. I tried messing with the near clip plane in the projection matrix but that changes nothing. Question: Is there any way to both visualize close features AND use --nologdepth? For reference, this is how I set the Projection matrix. It's as if it does not matter which near - far values I use. double cx = MY_OSG_WIDTH / 2.; //principal point x coord
double cy = MY_OSG_HEIGHT / 2.; //principal point y coord
double w = MY_OSG_WIDTH; //image width
double h = MY_OSG_HEIGHT; //image height
double near = 0.01; //near plane
double far = 10.0; //far plane
double f = 480.; // focal length in px (assume fx=fy)
// Projection matrix
osg::Matrixd K_gl(2*f/w, 0.0, (w - 2*cx)/w, 0.0,
0.0, 2*f/h, (h - 2*cy)/h, 0.0,
0.0, 0.0, (-far - near) / (far - near), -2.0*far*near/(far-near),
0.0, 0.0, -1.0, 0.0);
osg::Matrixd projMatrix;
projMatrix.transpose(K_gl);
// setComputeNearFarMode setting breaks everything (far plane is very close: very nearsighted)
// viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
viewer.getCamera()->setProjectionMatrix(projMatrix);
// I get same results setting like this, messing with near and far
// double fov = 2.0*atan( 1.0/projMatrix(1,1) ) * 180.0 / M_PI;
// double aspect = projMatrix(1,1) / projMatrix(1,1);
// viewer.getCamera()->setProjectionMatrixAsPerspective(fov, aspect, near, far); Here are two screenshot of the viewport at the same view point, with and without the logarithmic depth buffer, respectively: |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I think you misunderstood. I was merely suggesting using If you disable the LDB, you do need to either Otherwise, you will need to reverse-engineer the LDB projection matrix. The shader that applies it is here: |
Beta Was this translation helpful? Give feedback.
I think you misunderstood. I was merely suggesting using
--nologdepth
to test the LDB theory, not to solve your problem.If you disable the LDB, you do need to either
(a) Use
DO_NOT_COMPUTE_NEAR_FAR
and set the clip planes manually; or(b) Use
osg::Camera::setNearFarRatio
to pull the near plane closer to the camera. (This is why your attempt to set the near plane failed - it is auto-calculated by multiplying the far plane by this ratio.)Otherwise, you will need to reverse-engineer the LDB projection matrix. The shader that applies it is here:
https://github.com/gwaldron/osgearth/blob/master/src/osgEarth/LogDepthBuffer.VertOnly.glsl