1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-21 12:23:51 +00:00

Merge remote-tracking branch 'remotes/origin/shared_shadow_maps' into openxr_vr

This commit is contained in:
Mads Buvik Sandvei 2020-07-25 12:27:12 +02:00
commit cea73ead09
2 changed files with 40 additions and 24 deletions

View file

@ -969,6 +969,37 @@ void SceneUtil::MWShadowTechnique::shareShadowMap(osgUtil::CullVisitor& cv, View
} }
} }
bool MWShadowTechnique::trySharedShadowMap(osgUtil::CullVisitor& cv, ViewDependentData* vdd)
{
auto* sharedConfig = dynamic_cast<SharedShadowMapConfig*>(cv.getCurrentCamera()->getUserData());
if (!sharedConfig)
{
return false;
}
if (sharedConfig->_master)
{
addSharedVdd(*sharedConfig, vdd);
return false;
}
else
{
auto* sharedVdd = getSharedVdd(*sharedConfig);
if (sharedVdd)
{
OSG_INFO << "Using shared shadow map" << std::endl;
shareShadowMap(cv, vdd, sharedVdd);
return true;
}
else
{
OSG_WARN << "Warning, view configured to reuse shared shadow map but no shadow map has been shared. Shadows will be generated instead." << std::endl;
}
}
return false;
}
void MWShadowTechnique::update(osg::NodeVisitor& nv) void MWShadowTechnique::update(osg::NodeVisitor& nv)
{ {
OSG_INFO<<"MWShadowTechnique::update(osg::NodeVisitor& "<<&nv<<")"<<std::endl; OSG_INFO<<"MWShadowTechnique::update(osg::NodeVisitor& "<<&nv<<")"<<std::endl;
@ -994,29 +1025,6 @@ void MWShadowTechnique::cull(osgUtil::CullVisitor& cv)
ViewDependentData* vdd = getViewDependentData(&cv); ViewDependentData* vdd = getViewDependentData(&cv);
// Use shared shadow map if applicable
auto* sharedConfig = dynamic_cast<SharedShadowMapConfig*>(cv.getCurrentCamera()->getUserData());
if (sharedConfig)
{
if (sharedConfig->_master)
{
addSharedVdd(*sharedConfig, vdd);
}
else
{
auto* sharedVdd = getSharedVdd(*sharedConfig);
if (sharedVdd)
{
OSG_INFO << "Using shared shadow map" << std::endl;
return shareShadowMap(cv, vdd, sharedVdd);
}
else
{
OSG_INFO << "Warning, view configured to reuse shared shadow map but no shadow map has been shared. Shadows will be generated instead." << std::endl;
}
}
}
if (!vdd) if (!vdd)
{ {
OSG_INFO<<"Warning, now ViewDependentData created, unable to create shadows."<<std::endl; OSG_INFO<<"Warning, now ViewDependentData created, unable to create shadows."<<std::endl;
@ -1024,6 +1032,11 @@ void MWShadowTechnique::cull(osgUtil::CullVisitor& cv)
return; return;
} }
if (trySharedShadowMap(cv, vdd))
{
return;
}
ShadowSettings* settings = getShadowedScene()->getShadowSettings(); ShadowSettings* settings = getShadowedScene()->getShadowSettings();
OSG_INFO<<"cv->getProjectionMatrix()="<<*cv.getProjectionMatrix()<<std::endl; OSG_INFO<<"cv->getProjectionMatrix()="<<*cv.getProjectionMatrix()<<std::endl;

View file

@ -227,11 +227,14 @@ namespace SceneUtil {
virtual ViewDependentData* createViewDependentData(osgUtil::CullVisitor* cv); virtual ViewDependentData* createViewDependentData(osgUtil::CullVisitor* cv);
ViewDependentData* getViewDependentData(osgUtil::CullVisitor* cv); ViewDependentData* getViewDependentData(osgUtil::CullVisitor* cv);
ViewDependentData* getSharedVdd(const SharedShadowMapConfig& config); ViewDependentData* getSharedVdd(const SharedShadowMapConfig& config);
void addSharedVdd(const SharedShadowMapConfig& config, ViewDependentData* vdd); void addSharedVdd(const SharedShadowMapConfig& config, ViewDependentData* vdd);
void shareShadowMap(osgUtil::CullVisitor& cv, ViewDependentData* lhs, ViewDependentData* rhs); void shareShadowMap(osgUtil::CullVisitor& cv, ViewDependentData* lhs, ViewDependentData* rhs);
bool trySharedShadowMap(osgUtil::CullVisitor& cv, ViewDependentData* vdd);
virtual void createShaders(); virtual void createShaders();