Merge /u/fgarlin/simgear/ branch next into next

https://sourceforge.net/p/flightgear/simgear/merge-requests/67/
This commit is contained in:
James Turner 2019-11-05 09:32:28 +00:00
commit 012966f6a2
5 changed files with 31 additions and 10 deletions

View File

@ -256,7 +256,7 @@ osg::ref_ptr<EffectGeode> SGNewCloud::genCloud() {
geode->addDrawable(sg); geode->addDrawable(sg);
geode->setName("3D cloud"); geode->setName("3D cloud");
geode->setEffect(effect.get()); geode->setEffect(effect.get());
geode->setNodeMask( ~simgear::MODELLIGHT_BIT ); geode->setNodeMask( ~(simgear::CASTSHADOW_BIT | simgear::MODELLIGHT_BIT) );
return geode; return geode;
} }

View File

@ -338,7 +338,7 @@ osg::Node* SGOceanTile(const SGBucket& b, SGMaterialLib *matlib, int latPoints,
transform->setMatrix(osg::Matrix::rotate(toOsg(hlOr))* transform->setMatrix(osg::Matrix::rotate(toOsg(hlOr))*
osg::Matrix::translate(toOsg(cartCenter))); osg::Matrix::translate(toOsg(cartCenter)));
transform->addChild(geode); transform->addChild(geode);
transform->setNodeMask( ~simgear::MODELLIGHT_BIT ); transform->setNodeMask( ~(simgear::CASTSHADOW_BIT | simgear::MODELLIGHT_BIT) );
return transform; return transform;
} }

View File

@ -1099,7 +1099,7 @@ public:
if (forestNode.valid()) objectLOD->addChild(forestNode.get(), 0, 2.0 * object_range + SG_TILE_RADIUS); 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); 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); objectLOD->setNodeMask(nodeMask);
} }

View File

@ -159,6 +159,6 @@ SGLoadBTG(const std::string& path, const simgear::SGReaderWriterOptions* options
transform->addChild(pagedLOD); transform->addChild(pagedLOD);
} }
transform->setNodeMask( ~simgear::MODELLIGHT_BIT ); transform->setNodeMask( ~(simgear::CASTSHADOW_BIT | simgear::MODELLIGHT_BIT) );
return transform; return transform;
} }

View File

@ -36,6 +36,25 @@
#include "Compositor.hxx" #include "Compositor.hxx"
#include "CompositorUtil.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 simgear {
namespace compositor { namespace compositor {
@ -384,9 +403,12 @@ 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);
removeTransparentBins(cv);
// The light matrix uniform is updated after the traverse in case the // The light matrix uniform is updated after the traverse in case the
// OSG near/far plane calculations were enabled // OSG near/far plane calculations were enabled
osg::Matrixf light_matrix = osg::Matrixf light_matrix =
@ -497,19 +519,18 @@ public:
osg::Vec4 aim4 = osg::Vec4(bs.center(), 1.0) * view_inverse; osg::Vec4 aim4 = osg::Vec4(bs.center(), 1.0) * view_inverse;
osg::Vec3 aim(aim4.x(), aim4.y(), aim4.z()); 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(); osg::Matrixd &light_view_matrix = camera->getViewMatrix();
light_view_matrix.makeLookAt( light_view_matrix.makeLookAt(
aim + (light_dir * bs.radius() * 2.0f), aim + light_dir * (bs.radius() + 10.0f),
aim, aim,
aim); osg::Vec3(0.0f, 0.0f, 1.0f));
osg::Matrixd &light_proj_matrix = camera->getProjectionMatrix(); osg::Matrixd &light_proj_matrix = camera->getProjectionMatrix();
light_proj_matrix.makeOrtho( light_proj_matrix.makeOrtho(
-bs.radius(), bs.radius(), -bs.radius(), bs.radius(),
-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. // Do texel snapping to prevent flickering or shimmering.
// We are using double precision vectors and matrices because in FG // 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()); osg::Vec2d shadow_origin(shadow_origin4.x(), shadow_origin4.y());
shadow_origin = osg::Vec2d(shadow_origin.x() * _half_sm_size.x(), shadow_origin = osg::Vec2d(shadow_origin.x() * _half_sm_size.x(),
shadow_origin.y() * _half_sm_size.y()); shadow_origin.y() * _half_sm_size.y());
osg::Vec2d rounded_origin(std::round(shadow_origin.x()), osg::Vec2d rounded_origin(std::floor(shadow_origin.x()),
std::round(shadow_origin.y())); std::floor(shadow_origin.y()));
osg::Vec2d rounding = rounded_origin - shadow_origin; osg::Vec2d rounding = rounded_origin - shadow_origin;
rounding = osg::Vec2d(rounding.x() / _half_sm_size.x(), rounding = osg::Vec2d(rounding.x() / _half_sm_size.x(),
rounding.y() / _half_sm_size.y()); rounding.y() / _half_sm_size.y());