mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:24:00 +02:00
Deal correctly with inheritance at top-most level.
This commit is contained in:
parent
e94982a470
commit
c3f6faed00
3 changed files with 42 additions and 32 deletions
|
@ -763,7 +763,8 @@ void DefaultLightingSetup::run(const RenderContextPointer& renderContext) {
|
|||
_defaultLight = lp;
|
||||
|
||||
// Add the global light to the light stage (for later shadow rendering)
|
||||
_defaultLightID = lightStage->addLight(lp);
|
||||
// Set this light to be the default
|
||||
_defaultLightID = lightStage->addLight(lp, true);
|
||||
lightStage->addShadow(_defaultLightID);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,28 +34,31 @@ LightStage::LightStage() {
|
|||
ambientOffLight->setColor(model::Vec3(0.0));
|
||||
ambientOffLight->setIntensity(0.0f);
|
||||
ambientOffLight->setType(model::Light::Type::AMBIENT);
|
||||
_ambientOffLight = addLight(ambientOffLight);
|
||||
_ambientOffLightId = addLight(ambientOffLight);
|
||||
|
||||
const LightPointer pointOffLight { std::make_shared<model::Light>() };
|
||||
pointOffLight->setAmbientIntensity(0.0f);
|
||||
pointOffLight->setColor(model::Vec3(0.0));
|
||||
pointOffLight->setIntensity(0.0f);
|
||||
pointOffLight->setType(model::Light::Type::POINT);
|
||||
_pointOffLight = addLight(pointOffLight);
|
||||
_pointOffLightId = addLight(pointOffLight);
|
||||
|
||||
const LightPointer spotOffLight { std::make_shared<model::Light>() };
|
||||
spotOffLight->setAmbientIntensity(0.0f);
|
||||
spotOffLight->setColor(model::Vec3(0.0));
|
||||
spotOffLight->setIntensity(0.0f);
|
||||
spotOffLight->setType(model::Light::Type::SPOT);
|
||||
_spotOffLight = addLight(spotOffLight);
|
||||
_spotOffLightId = addLight(spotOffLight);
|
||||
|
||||
const LightPointer sunOffLight { std::make_shared<model::Light>() };
|
||||
sunOffLight->setAmbientIntensity(0.0f);
|
||||
sunOffLight->setColor(model::Vec3(0.0));
|
||||
sunOffLight->setIntensity(0.0f);
|
||||
sunOffLight->setType(model::Light::Type::SUN);
|
||||
_sunOffLight = addLight(sunOffLight);
|
||||
_sunOffLightId = addLight(sunOffLight);
|
||||
|
||||
// Set default light to the off ambient light (until changed)
|
||||
_defaultLightId = _ambientOffLightId;
|
||||
}
|
||||
|
||||
LightStage::Shadow::Schema::Schema() {
|
||||
|
@ -294,10 +297,12 @@ LightStage::Index LightStage::findLight(const LightPointer& light) const {
|
|||
}
|
||||
}
|
||||
|
||||
LightStage::Index LightStage::addLight(const LightPointer& light) {
|
||||
LightStage::Index LightStage::addLight(const LightPointer& light, const bool shouldSetAsDefault) {
|
||||
Index lightId;
|
||||
|
||||
auto found = _lightMap.find(light);
|
||||
if (found == _lightMap.end()) {
|
||||
auto lightId = _lights.newElement(light);
|
||||
lightId = _lights.newElement(light);
|
||||
// Avoid failing to allocate a light, just pass
|
||||
if (lightId != INVALID_INDEX) {
|
||||
|
||||
|
@ -314,10 +319,15 @@ LightStage::Index LightStage::addLight(const LightPointer& light) {
|
|||
|
||||
updateLightArrayBuffer(lightId);
|
||||
}
|
||||
return lightId;
|
||||
} else {
|
||||
return (*found).second;
|
||||
lightId = (*found).second;
|
||||
}
|
||||
|
||||
if (shouldSetAsDefault) {
|
||||
_defaultLightId = lightId;
|
||||
}
|
||||
|
||||
return lightId;
|
||||
}
|
||||
|
||||
LightStage::Index LightStage::addShadow(Index lightIndex, float maxDistance, unsigned int cascadeCount) {
|
||||
|
@ -349,24 +359,27 @@ LightStage::LightPointer LightStage::removeLight(Index index) {
|
|||
}
|
||||
|
||||
LightStage::LightPointer LightStage::getCurrentKeyLight() const {
|
||||
Index keyLightId{ 0 };
|
||||
if (!_currentFrame._sunLights.empty()) {
|
||||
Index keyLightId{ _defaultLightId };
|
||||
// There is always at least 1 light (the off light)
|
||||
if (_currentFrame._sunLights.size() > 1) {
|
||||
keyLightId = _currentFrame._sunLights.front();
|
||||
}
|
||||
return _lights.get(keyLightId);
|
||||
}
|
||||
|
||||
LightStage::LightPointer LightStage::getCurrentAmbientLight() const {
|
||||
Index keyLightId{ 0 };
|
||||
if (!_currentFrame._ambientLights.empty()) {
|
||||
Index keyLightId { _defaultLightId };
|
||||
// There is always at least 1 light (the off light)
|
||||
if (_currentFrame._ambientLights.size() > 1) {
|
||||
keyLightId = _currentFrame._ambientLights.front();
|
||||
}
|
||||
return _lights.get(keyLightId);
|
||||
}
|
||||
|
||||
LightStage::ShadowPointer LightStage::getCurrentKeyShadow() const {
|
||||
Index keyLightId{ 0 };
|
||||
if (!_currentFrame._sunLights.empty()) {
|
||||
Index keyLightId { _defaultLightId };
|
||||
// There is always at least 1 light (the off light)
|
||||
if (_currentFrame._sunLights.size() > 1) {
|
||||
keyLightId = _currentFrame._sunLights.front();
|
||||
}
|
||||
auto shadow = getShadow(keyLightId);
|
||||
|
@ -375,8 +388,9 @@ LightStage::ShadowPointer LightStage::getCurrentKeyShadow() const {
|
|||
}
|
||||
|
||||
LightStage::LightAndShadow LightStage::getCurrentKeyLightAndShadow() const {
|
||||
Index keyLightId{ 0 };
|
||||
if (!_currentFrame._sunLights.empty()) {
|
||||
Index keyLightId { _defaultLightId };
|
||||
// There is always at least 1 light (the off light)
|
||||
if (_currentFrame._sunLights.size() > 1) {
|
||||
keyLightId = _currentFrame._sunLights.front();
|
||||
}
|
||||
auto shadow = getShadow(keyLightId);
|
||||
|
|
|
@ -118,7 +118,7 @@ public:
|
|||
using Shadows = render::indexed_container::IndexedPointerVector<Shadow>;
|
||||
|
||||
Index findLight(const LightPointer& light) const;
|
||||
Index addLight(const LightPointer& light);
|
||||
Index addLight(const LightPointer& light, const bool shouldSetAsDefault = false);
|
||||
|
||||
Index addShadow(Index lightIndex, float maxDistance = 20.0f, unsigned int cascadeCount = 1U);
|
||||
|
||||
|
@ -185,10 +185,10 @@ public:
|
|||
|
||||
Frame _currentFrame;
|
||||
|
||||
Index getAmbientOffLight() { return _ambientOffLight; }
|
||||
Index getPointOffLight() { return _pointOffLight; }
|
||||
Index getSpotOffLight() { return _spotOffLight; }
|
||||
Index getSunOffLight() { return _sunOffLight; }
|
||||
Index getAmbientOffLight() { return _ambientOffLightId; }
|
||||
Index getPointOffLight() { return _pointOffLightId; }
|
||||
Index getSpotOffLight() { return _spotOffLightId; }
|
||||
Index getSunOffLight() { return _sunOffLightId; }
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -205,17 +205,12 @@ protected:
|
|||
LightMap _lightMap;
|
||||
|
||||
// define off lights
|
||||
Index _ambientOffLightId;
|
||||
Index _pointOffLightId;
|
||||
Index _spotOffLightId;
|
||||
Index _sunOffLightId;
|
||||
|
||||
const LightPointer ambientOffLight { std::make_shared<model::Light>() };
|
||||
const LightPointer pointOffLight { std::make_shared<model::Light>() };
|
||||
const LightPointer spotOffLight { std::make_shared<model::Light>() };
|
||||
const LightPointer sunOffLight { std::make_shared<model::Light>() };
|
||||
|
||||
Index _ambientOffLight;
|
||||
Index _pointOffLight;
|
||||
Index _spotOffLight;
|
||||
Index _sunOffLight;
|
||||
|
||||
Index _defaultLightId;
|
||||
};
|
||||
using LightStagePointer = std::shared_ptr<LightStage>;
|
||||
|
||||
|
|
Loading…
Reference in a new issue