mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-27 03:35:27 +00:00
Move CLSB changes to new shadow technique
This commit is contained in:
parent
06b2ce6646
commit
4c31b38f77
@ -293,122 +293,123 @@ void VDSMCameraCullCallback::operator()(osg::Node* node, osg::NodeVisitor* nv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MWShadowTechnique::ComputeLightSpaceBounds::ComputeLightSpaceBounds(osg::Viewport* viewport, const osg::Matrixd& projectionMatrix, osg::Matrixd& viewMatrix) :
|
||||||
class ComputeLightSpaceBounds : public osg::NodeVisitor, public osg::CullStack
|
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN)
|
||||||
{
|
{
|
||||||
public:
|
setCullingMode(osg::CullSettings::VIEW_FRUSTUM_CULLING);
|
||||||
ComputeLightSpaceBounds(osg::Viewport* viewport, const osg::Matrixd& projectionMatrix, osg::Matrixd& viewMatrix):
|
|
||||||
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN)
|
|
||||||
{
|
|
||||||
setCullingMode(osg::CullSettings::VIEW_FRUSTUM_CULLING);
|
|
||||||
|
|
||||||
pushViewport(viewport);
|
pushViewport(viewport);
|
||||||
pushProjectionMatrix(new osg::RefMatrix(projectionMatrix));
|
pushProjectionMatrix(new osg::RefMatrix(projectionMatrix));
|
||||||
pushModelViewMatrix(new osg::RefMatrix(viewMatrix),osg::Transform::ABSOLUTE_RF);
|
pushModelViewMatrix(new osg::RefMatrix(viewMatrix), osg::Transform::ABSOLUTE_RF);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Node& node)
|
||||||
|
{
|
||||||
|
if (isCulled(node)) return;
|
||||||
|
|
||||||
|
// push the culling mode.
|
||||||
|
pushCurrentMask();
|
||||||
|
|
||||||
|
traverse(node);
|
||||||
|
|
||||||
|
// pop the culling mode.
|
||||||
|
popCurrentMask();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Drawable& drawable)
|
||||||
|
{
|
||||||
|
if (isCulled(drawable)) return;
|
||||||
|
|
||||||
|
// push the culling mode.
|
||||||
|
pushCurrentMask();
|
||||||
|
|
||||||
|
updateBound(drawable.getBoundingBox());
|
||||||
|
|
||||||
|
// pop the culling mode.
|
||||||
|
popCurrentMask();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MWShadowTechnique::ComputeLightSpaceBounds::apply(Terrain::QuadTreeWorld & quadTreeWorld)
|
||||||
|
{
|
||||||
|
// For now, just expand the bounds fully as terrain will fill them up and possible ways to detect which terrain definitely won't cast shadows aren't implemented.
|
||||||
|
|
||||||
|
update(osg::Vec3(-1.0, -1.0, 0.0));
|
||||||
|
update(osg::Vec3(1.0, 1.0, 0.0));
|
||||||
|
}
|
||||||
|
|
||||||
|
void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Billboard&)
|
||||||
|
{
|
||||||
|
OSG_INFO << "Warning Billboards not yet supported" << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Projection&)
|
||||||
|
{
|
||||||
|
// projection nodes won't affect a shadow map so their subgraphs should be ignored
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Transform& transform)
|
||||||
|
{
|
||||||
|
if (isCulled(transform)) return;
|
||||||
|
|
||||||
|
// push the culling mode.
|
||||||
|
pushCurrentMask();
|
||||||
|
|
||||||
|
// absolute transforms won't affect a shadow map so their subgraphs should be ignored.
|
||||||
|
if (transform.getReferenceFrame() == osg::Transform::RELATIVE_RF)
|
||||||
|
{
|
||||||
|
osg::ref_ptr<osg::RefMatrix> matrix = new osg::RefMatrix(*getModelViewMatrix());
|
||||||
|
transform.computeLocalToWorldMatrix(*matrix, this);
|
||||||
|
pushModelViewMatrix(matrix.get(), transform.getReferenceFrame());
|
||||||
|
|
||||||
|
traverse(transform);
|
||||||
|
|
||||||
|
popModelViewMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void apply(osg::Node& node)
|
// pop the culling mode.
|
||||||
|
popCurrentMask();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MWShadowTechnique::ComputeLightSpaceBounds::apply(osg::Camera&)
|
||||||
|
{
|
||||||
|
// camera nodes won't affect a shadow map so their subgraphs should be ignored
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MWShadowTechnique::ComputeLightSpaceBounds::updateBound(const osg::BoundingBox& bb)
|
||||||
|
{
|
||||||
|
if (!bb.valid()) return;
|
||||||
|
|
||||||
|
const osg::Matrix& matrix = *getModelViewMatrix() * *getProjectionMatrix();
|
||||||
|
|
||||||
|
update(bb.corner(0) * matrix);
|
||||||
|
update(bb.corner(1) * matrix);
|
||||||
|
update(bb.corner(2) * matrix);
|
||||||
|
update(bb.corner(3) * matrix);
|
||||||
|
update(bb.corner(4) * matrix);
|
||||||
|
update(bb.corner(5) * matrix);
|
||||||
|
update(bb.corner(6) * matrix);
|
||||||
|
update(bb.corner(7) * matrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MWShadowTechnique::ComputeLightSpaceBounds::update(const osg::Vec3& v)
|
||||||
|
{
|
||||||
|
if (v.z()<-1.0f)
|
||||||
{
|
{
|
||||||
if (isCulled(node)) return;
|
//OSG_NOTICE<<"discarding("<<v<<")"<<std::endl;
|
||||||
|
|
||||||
// push the culling mode.
|
|
||||||
pushCurrentMask();
|
|
||||||
|
|
||||||
traverse(node);
|
|
||||||
|
|
||||||
// pop the culling mode.
|
|
||||||
popCurrentMask();
|
|
||||||
}
|
|
||||||
|
|
||||||
void apply(osg::Drawable& drawable)
|
|
||||||
{
|
|
||||||
if (isCulled(drawable)) return;
|
|
||||||
|
|
||||||
// push the culling mode.
|
|
||||||
pushCurrentMask();
|
|
||||||
|
|
||||||
updateBound(drawable.getBoundingBox());
|
|
||||||
|
|
||||||
// pop the culling mode.
|
|
||||||
popCurrentMask();
|
|
||||||
}
|
|
||||||
|
|
||||||
void apply(osg::Billboard&)
|
|
||||||
{
|
|
||||||
OSG_INFO<<"Warning Billboards not yet supported"<<std::endl;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
float x = v.x();
|
||||||
void apply(osg::Projection&)
|
if (x<-1.0f) x = -1.0f;
|
||||||
{
|
if (x>1.0f) x = 1.0f;
|
||||||
// projection nodes won't affect a shadow map so their subgraphs should be ignored
|
float y = v.y();
|
||||||
return;
|
if (y<-1.0f) y = -1.0f;
|
||||||
}
|
if (y>1.0f) y = 1.0f;
|
||||||
|
_bb.expandBy(osg::Vec3(x, y, v.z()));
|
||||||
void apply(osg::Transform& transform)
|
}
|
||||||
{
|
|
||||||
if (isCulled(transform)) return;
|
|
||||||
|
|
||||||
// push the culling mode.
|
|
||||||
pushCurrentMask();
|
|
||||||
|
|
||||||
// absolute transforms won't affect a shadow map so their subgraphs should be ignored.
|
|
||||||
if (transform.getReferenceFrame()==osg::Transform::RELATIVE_RF)
|
|
||||||
{
|
|
||||||
osg::ref_ptr<osg::RefMatrix> matrix = new osg::RefMatrix(*getModelViewMatrix());
|
|
||||||
transform.computeLocalToWorldMatrix(*matrix,this);
|
|
||||||
pushModelViewMatrix(matrix.get(), transform.getReferenceFrame());
|
|
||||||
|
|
||||||
traverse(transform);
|
|
||||||
|
|
||||||
popModelViewMatrix();
|
|
||||||
}
|
|
||||||
|
|
||||||
// pop the culling mode.
|
|
||||||
popCurrentMask();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void apply(osg::Camera&)
|
|
||||||
{
|
|
||||||
// camera nodes won't affect a shadow map so their subgraphs should be ignored
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateBound(const osg::BoundingBox& bb)
|
|
||||||
{
|
|
||||||
if (!bb.valid()) return;
|
|
||||||
|
|
||||||
const osg::Matrix& matrix = *getModelViewMatrix() * *getProjectionMatrix();
|
|
||||||
|
|
||||||
update(bb.corner(0) * matrix);
|
|
||||||
update(bb.corner(1) * matrix);
|
|
||||||
update(bb.corner(2) * matrix);
|
|
||||||
update(bb.corner(3) * matrix);
|
|
||||||
update(bb.corner(4) * matrix);
|
|
||||||
update(bb.corner(5) * matrix);
|
|
||||||
update(bb.corner(6) * matrix);
|
|
||||||
update(bb.corner(7) * matrix);
|
|
||||||
}
|
|
||||||
|
|
||||||
void update(const osg::Vec3& v)
|
|
||||||
{
|
|
||||||
if (v.z()<-1.0f)
|
|
||||||
{
|
|
||||||
//OSG_NOTICE<<"discarding("<<v<<")"<<std::endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
float x = v.x();
|
|
||||||
if (x<-1.0f) x=-1.0f;
|
|
||||||
if (x>1.0f) x=1.0f;
|
|
||||||
float y = v.y();
|
|
||||||
if (y<-1.0f) y=-1.0f;
|
|
||||||
if (y>1.0f) y=1.0f;
|
|
||||||
_bb.expandBy(osg::Vec3(x,y,v.z()));
|
|
||||||
}
|
|
||||||
|
|
||||||
osg::BoundingBox _bb;
|
|
||||||
};
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
//
|
//
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include <osgShadow/ShadowTechnique>
|
#include <osgShadow/ShadowTechnique>
|
||||||
|
|
||||||
|
#include <components/terrain/quadtreeworld.hpp>
|
||||||
|
|
||||||
namespace SceneUtil {
|
namespace SceneUtil {
|
||||||
|
|
||||||
/** ViewDependentShadowMap provides an base implementation of view dependent shadow mapping techniques.*/
|
/** ViewDependentShadowMap provides an base implementation of view dependent shadow mapping techniques.*/
|
||||||
@ -59,6 +61,31 @@ namespace SceneUtil {
|
|||||||
/** Clean scene graph from any shadow technique specific nodes, state and drawables.*/
|
/** Clean scene graph from any shadow technique specific nodes, state and drawables.*/
|
||||||
virtual void cleanSceneGraph();
|
virtual void cleanSceneGraph();
|
||||||
|
|
||||||
|
class ComputeLightSpaceBounds : public osg::NodeVisitor, public osg::CullStack
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ComputeLightSpaceBounds(osg::Viewport* viewport, const osg::Matrixd& projectionMatrix, osg::Matrixd& viewMatrix);
|
||||||
|
|
||||||
|
void apply(osg::Node& node);
|
||||||
|
|
||||||
|
void apply(osg::Drawable& drawable);
|
||||||
|
|
||||||
|
void apply(Terrain::QuadTreeWorld& quadTreeWorld);
|
||||||
|
|
||||||
|
void apply(osg::Billboard&);
|
||||||
|
|
||||||
|
void apply(osg::Projection&);
|
||||||
|
|
||||||
|
void apply(osg::Transform& transform);
|
||||||
|
|
||||||
|
void apply(osg::Camera&);
|
||||||
|
|
||||||
|
void updateBound(const osg::BoundingBox& bb);
|
||||||
|
|
||||||
|
void update(const osg::Vec3& v);
|
||||||
|
|
||||||
|
osg::BoundingBox _bb;
|
||||||
|
};
|
||||||
|
|
||||||
struct OSGSHADOW_EXPORT Frustum
|
struct OSGSHADOW_EXPORT Frustum
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user