Compositor: Added support for logarithmic depth buffer.
This commit is contained in:
parent
1b6545fc05
commit
73f00bd842
@ -129,6 +129,8 @@ Compositor::Compositor(osg::View *view,
|
|||||||
new osg::Uniform("fg_PrevProjectionMatrixInverse", osg::Matrixf()),
|
new osg::Uniform("fg_PrevProjectionMatrixInverse", osg::Matrixf()),
|
||||||
new osg::Uniform("fg_CameraPositionCart", osg::Vec3f()),
|
new osg::Uniform("fg_CameraPositionCart", osg::Vec3f()),
|
||||||
new osg::Uniform("fg_CameraPositionGeod", osg::Vec3f()),
|
new osg::Uniform("fg_CameraPositionGeod", osg::Vec3f()),
|
||||||
|
new osg::Uniform("fg_NearFarPlanes", osg::Vec3f()),
|
||||||
|
new osg::Uniform("fg_Fcoef", 0.0f),
|
||||||
new osg::Uniform("fg_LightDirection", osg::Vec3f())
|
new osg::Uniform("fg_LightDirection", osg::Vec3f())
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@ -165,6 +167,9 @@ Compositor::update(const osg::Matrix &view_matrix,
|
|||||||
SGGeod camera_pos_geod = SGGeod::fromCart(
|
SGGeod camera_pos_geod = SGGeod::fromCart(
|
||||||
SGVec3d(camera_pos.x(), camera_pos.y(), camera_pos.z()));
|
SGVec3d(camera_pos.x(), camera_pos.y(), camera_pos.z()));
|
||||||
|
|
||||||
|
double left, right, bottom, top, zNear, zFar;
|
||||||
|
proj_matrix.getFrustum(left, right, bottom, top, zNear, zFar);
|
||||||
|
|
||||||
osg::Matrixf prev_view_matrix, prev_view_matrix_inv;
|
osg::Matrixf prev_view_matrix, prev_view_matrix_inv;
|
||||||
_uniforms[VIEW_MATRIX]->get(prev_view_matrix);
|
_uniforms[VIEW_MATRIX]->get(prev_view_matrix);
|
||||||
_uniforms[VIEW_MATRIX_INV]->get(prev_view_matrix_inv);
|
_uniforms[VIEW_MATRIX_INV]->get(prev_view_matrix_inv);
|
||||||
@ -203,6 +208,12 @@ Compositor::update(const osg::Matrix &view_matrix,
|
|||||||
camera_pos_geod.getLatitudeRad(),
|
camera_pos_geod.getLatitudeRad(),
|
||||||
camera_pos_geod.getElevationM()));
|
camera_pos_geod.getElevationM()));
|
||||||
break;
|
break;
|
||||||
|
case NEAR_FAR_PLANES:
|
||||||
|
u->set(osg::Vec3f(-zFar, -zFar * zNear, zFar - zNear));
|
||||||
|
break;
|
||||||
|
case FCOEF:
|
||||||
|
u->set(2.0f / log2(float(zFar) + 1.0f));
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
// Unknown uniform
|
// Unknown uniform
|
||||||
break;
|
break;
|
||||||
|
@ -57,6 +57,8 @@ public:
|
|||||||
PREV_PROJECTION_MATRIX_INV,
|
PREV_PROJECTION_MATRIX_INV,
|
||||||
CAMERA_POSITION_CART,
|
CAMERA_POSITION_CART,
|
||||||
CAMERA_POSITION_GEOD,
|
CAMERA_POSITION_GEOD,
|
||||||
|
NEAR_FAR_PLANES,
|
||||||
|
FCOEF,
|
||||||
LIGHT_DIRECTION,
|
LIGHT_DIRECTION,
|
||||||
TOTAL_BUILTIN_UNIFORMS
|
TOTAL_BUILTIN_UNIFORMS
|
||||||
};
|
};
|
||||||
|
@ -385,7 +385,6 @@ public:
|
|||||||
|
|
||||||
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv) {
|
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv) {
|
||||||
osg::Camera *camera = static_cast<osg::Camera *>(node);
|
osg::Camera *camera = static_cast<osg::Camera *>(node);
|
||||||
EffectCullVisitor *cv = dynamic_cast<EffectCullVisitor *>(nv);
|
|
||||||
|
|
||||||
traverse(node, nv);
|
traverse(node, nv);
|
||||||
|
|
||||||
@ -720,6 +719,10 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
osg::StateSet *ss = camera->getOrCreateStateSet();
|
||||||
|
auto &uniforms = compositor->getUniforms();
|
||||||
|
ss->addUniform(uniforms[Compositor::FCOEF]);
|
||||||
|
|
||||||
return pass.release();
|
return pass.release();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user