Honor /sim/rendering/shadows/enabled preference
This commit is contained in:
parent
f7174f5422
commit
44de0e1df4
2 changed files with 32 additions and 2 deletions
|
@ -453,12 +453,20 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ShadowEnabledListener : public SGPropertyChangeListener {
|
||||||
|
public:
|
||||||
|
virtual void valueChanged(SGPropertyNode* node) {
|
||||||
|
globals->get_renderer()->enableShadows(node->getBoolValue());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
FGRenderer::init( void )
|
FGRenderer::init( void )
|
||||||
{
|
{
|
||||||
_classicalRenderer = !fgGetBool("/sim/rendering/rembrandt", false);
|
_classicalRenderer = !fgGetBool("/sim/rendering/rembrandt", false);
|
||||||
_shadowMapSize = fgGetInt( "/sim/rendering/shadows/map-size", 4096 );
|
_shadowMapSize = fgGetInt( "/sim/rendering/shadows/map-size", 4096 );
|
||||||
fgAddChangeListener( new ShadowMapSizeListener, "/sim/rendering/shadows/map-size" );
|
fgAddChangeListener( new ShadowMapSizeListener, "/sim/rendering/shadows/map-size" );
|
||||||
|
fgAddChangeListener( new ShadowEnabledListener, "/sim/rendering/shadows/enabled" );
|
||||||
_scenery_loaded = fgGetNode("/sim/sceneryloaded", true);
|
_scenery_loaded = fgGetNode("/sim/sceneryloaded", true);
|
||||||
_scenery_override = fgGetNode("/sim/sceneryloaded-override", true);
|
_scenery_override = fgGetNode("/sim/sceneryloaded-override", true);
|
||||||
_panel_hotspots = fgGetNode("/sim/panel-hotspots", true);
|
_panel_hotspots = fgGetNode("/sim/panel-hotspots", true);
|
||||||
|
@ -817,7 +825,10 @@ osg::Camera* FGRenderer::buildDeferredShadowCamera( flightgear::CameraInfo* info
|
||||||
shadowSwitch->addChild( cascadeCam );
|
shadowSwitch->addChild( cascadeCam );
|
||||||
info->shadowTexGen[i] = new osg::TexGen;
|
info->shadowTexGen[i] = new osg::TexGen;
|
||||||
}
|
}
|
||||||
|
if (fgGetBool("/sim/rendering/shadows/enabled", true))
|
||||||
shadowSwitch->setAllChildrenOn();
|
shadowSwitch->setAllChildrenOn();
|
||||||
|
else
|
||||||
|
shadowSwitch->setAllChildrenOff();
|
||||||
|
|
||||||
return mainShadowCamera;
|
return mainShadowCamera;
|
||||||
}
|
}
|
||||||
|
@ -858,7 +869,7 @@ void FGRenderer::updateShadowCamera(const flightgear::CameraInfo* info, const os
|
||||||
up.normalize();
|
up.normalize();
|
||||||
dir.normalize();
|
dir.normalize();
|
||||||
// cos(100 deg) == -0.17
|
// cos(100 deg) == -0.17
|
||||||
if (up * dir < -0.17 ) {
|
if (up * dir < -0.17 || !fgGetBool("/sim/rendering/shadows/enabled", true)) {
|
||||||
shadowSwitch->setAllChildrenOff();
|
shadowSwitch->setAllChildrenOff();
|
||||||
} else {
|
} else {
|
||||||
double left,right,bottom,top,zNear,zFar;
|
double left,right,bottom,top,zNear,zFar;
|
||||||
|
@ -933,6 +944,24 @@ void FGRenderer::updateShadowMapSize(int mapSize)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FGRenderer::enableShadows(bool enabled)
|
||||||
|
{
|
||||||
|
for ( CameraGroup::CameraIterator ii = CameraGroup::getDefault()->camerasBegin();
|
||||||
|
ii != CameraGroup::getDefault()->camerasEnd();
|
||||||
|
++ii )
|
||||||
|
{
|
||||||
|
CameraInfo* info = ii->get();
|
||||||
|
Camera* camera = info->getCamera(SHADOW_CAMERA);
|
||||||
|
if (camera == 0) continue;
|
||||||
|
|
||||||
|
osg::Switch* shadowSwitch = camera->getChild(0)->asSwitch();
|
||||||
|
if (enabled)
|
||||||
|
shadowSwitch->setAllChildrenOn();
|
||||||
|
else
|
||||||
|
shadowSwitch->setAllChildrenOff();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#define STRINGIFY(x) #x
|
#define STRINGIFY(x) #x
|
||||||
#define TOSTRING(x) STRINGIFY(x)
|
#define TOSTRING(x) STRINGIFY(x)
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,7 @@ public:
|
||||||
|
|
||||||
void updateShadowCamera(const flightgear::CameraInfo* info, const osg::Vec3d& position);
|
void updateShadowCamera(const flightgear::CameraInfo* info, const osg::Vec3d& position);
|
||||||
void updateShadowMapSize(int mapSize);
|
void updateShadowMapSize(int mapSize);
|
||||||
|
void enableShadows(bool enabled);
|
||||||
|
|
||||||
SGSky* getSky() const { return _sky; }
|
SGSky* getSky() const { return _sky; }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue