Disabled CASTSHADOW_BIT on most of the scene graph geometry to optimize performance
This commit is contained in:
parent
c7efa81efe
commit
d1eb768de6
@ -256,7 +256,7 @@ osg::ref_ptr<EffectGeode> SGNewCloud::genCloud() {
|
||||
geode->addDrawable(sg);
|
||||
geode->setName("3D cloud");
|
||||
geode->setEffect(effect.get());
|
||||
geode->setNodeMask( ~simgear::MODELLIGHT_BIT );
|
||||
geode->setNodeMask( ~(simgear::CASTSHADOW_BIT | simgear::MODELLIGHT_BIT) );
|
||||
|
||||
return geode;
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ osg::Node* SGOceanTile(const SGBucket& b, SGMaterialLib *matlib, int latPoints,
|
||||
transform->setMatrix(osg::Matrix::rotate(toOsg(hlOr))*
|
||||
osg::Matrix::translate(toOsg(cartCenter)));
|
||||
transform->addChild(geode);
|
||||
transform->setNodeMask( ~simgear::MODELLIGHT_BIT );
|
||||
transform->setNodeMask( ~(simgear::CASTSHADOW_BIT | simgear::MODELLIGHT_BIT) );
|
||||
|
||||
return transform;
|
||||
}
|
||||
|
@ -1099,7 +1099,7 @@ public:
|
||||
if (forestNode.valid()) objectLOD->addChild(forestNode.get(), 0, 2.0 * object_range + SG_TILE_RADIUS);
|
||||
if (buildingNode.valid()) objectLOD->addChild(buildingNode.get(), 0, 2.0 * object_range + SG_TILE_RADIUS);
|
||||
|
||||
unsigned nodeMask = SG_NODEMASK_CASTSHADOW_BIT | SG_NODEMASK_RECEIVESHADOW_BIT | SG_NODEMASK_TERRAIN_BIT;
|
||||
unsigned nodeMask = SG_NODEMASK_RECEIVESHADOW_BIT | SG_NODEMASK_TERRAIN_BIT;
|
||||
objectLOD->setNodeMask(nodeMask);
|
||||
}
|
||||
|
||||
|
@ -159,6 +159,6 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options
|
||||
transform->addChild(pagedLOD);
|
||||
}
|
||||
|
||||
transform->setNodeMask( ~simgear::MODELLIGHT_BIT );
|
||||
transform->setNodeMask( ~(simgear::CASTSHADOW_BIT | simgear::MODELLIGHT_BIT) );
|
||||
return transform;
|
||||
}
|
||||
|
@ -36,6 +36,25 @@
|
||||
#include "Compositor.hxx"
|
||||
#include "CompositorUtil.hxx"
|
||||
|
||||
namespace {
|
||||
osgUtil::RenderBin::RenderBinList
|
||||
removeTransparentBins(simgear::EffectCullVisitor *cv)
|
||||
{
|
||||
osgUtil::RenderBin::RenderBinList transparent_bins;
|
||||
osgUtil::RenderStage *stage = cv->getRenderStage();
|
||||
osgUtil::RenderBin::RenderBinList &rbl = stage->getRenderBinList();
|
||||
for (auto rbi = rbl.begin(); rbi != rbl.end(); ) {
|
||||
if (rbi->second->getSortMode() == osgUtil::RenderBin::SORT_BACK_TO_FRONT) {
|
||||
transparent_bins.insert(std::make_pair(rbi->first, rbi->second));
|
||||
rbl.erase(rbi++);
|
||||
} else {
|
||||
++rbi;
|
||||
}
|
||||
}
|
||||
return transparent_bins;
|
||||
}
|
||||
} // anonymous namespace
|
||||
|
||||
namespace simgear {
|
||||
namespace compositor {
|
||||
|
||||
@ -384,9 +403,12 @@ public:
|
||||
|
||||
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv) {
|
||||
osg::Camera *camera = static_cast<osg::Camera *>(node);
|
||||
EffectCullVisitor *cv = dynamic_cast<EffectCullVisitor *>(nv);
|
||||
|
||||
traverse(node, nv);
|
||||
|
||||
removeTransparentBins(cv);
|
||||
|
||||
// The light matrix uniform is updated after the traverse in case the
|
||||
// OSG near/far plane calculations were enabled
|
||||
osg::Matrixf light_matrix =
|
||||
@ -497,19 +519,18 @@ public:
|
||||
|
||||
osg::Vec4 aim4 = osg::Vec4(bs.center(), 1.0) * view_inverse;
|
||||
osg::Vec3 aim(aim4.x(), aim4.y(), aim4.z());
|
||||
osg::Vec3 up(0.0f, 1.0f, 0.0f);
|
||||
|
||||
osg::Matrixd &light_view_matrix = camera->getViewMatrix();
|
||||
light_view_matrix.makeLookAt(
|
||||
aim + (light_dir * bs.radius() * 2.0f),
|
||||
aim + light_dir * (bs.radius() + 10.0f),
|
||||
aim,
|
||||
aim);
|
||||
osg::Vec3(0.0f, 0.0f, 1.0f));
|
||||
|
||||
osg::Matrixd &light_proj_matrix = camera->getProjectionMatrix();
|
||||
light_proj_matrix.makeOrtho(
|
||||
-bs.radius(), bs.radius(),
|
||||
-bs.radius(), bs.radius(),
|
||||
-bs.radius() * 6.0f, bs.radius() * 6.0f);
|
||||
1.0, bs.radius() * 10.0);
|
||||
|
||||
// Do texel snapping to prevent flickering or shimmering.
|
||||
// We are using double precision vectors and matrices because in FG
|
||||
@ -520,8 +541,8 @@ public:
|
||||
osg::Vec2d shadow_origin(shadow_origin4.x(), shadow_origin4.y());
|
||||
shadow_origin = osg::Vec2d(shadow_origin.x() * _half_sm_size.x(),
|
||||
shadow_origin.y() * _half_sm_size.y());
|
||||
osg::Vec2d rounded_origin(std::round(shadow_origin.x()),
|
||||
std::round(shadow_origin.y()));
|
||||
osg::Vec2d rounded_origin(std::floor(shadow_origin.x()),
|
||||
std::floor(shadow_origin.y()));
|
||||
osg::Vec2d rounding = rounded_origin - shadow_origin;
|
||||
rounding = osg::Vec2d(rounding.x() / _half_sm_size.x(),
|
||||
rounding.y() / _half_sm_size.y());
|
||||
|
Loading…
Reference in New Issue
Block a user