mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 17:01:18 +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;
|
_defaultLight = lp;
|
||||||
|
|
||||||
// Add the global light to the light stage (for later shadow rendering)
|
// 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);
|
lightStage->addShadow(_defaultLightID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,28 +34,31 @@ LightStage::LightStage() {
|
||||||
ambientOffLight->setColor(model::Vec3(0.0));
|
ambientOffLight->setColor(model::Vec3(0.0));
|
||||||
ambientOffLight->setIntensity(0.0f);
|
ambientOffLight->setIntensity(0.0f);
|
||||||
ambientOffLight->setType(model::Light::Type::AMBIENT);
|
ambientOffLight->setType(model::Light::Type::AMBIENT);
|
||||||
_ambientOffLight = addLight(ambientOffLight);
|
_ambientOffLightId = addLight(ambientOffLight);
|
||||||
|
|
||||||
const LightPointer pointOffLight { std::make_shared<model::Light>() };
|
const LightPointer pointOffLight { std::make_shared<model::Light>() };
|
||||||
pointOffLight->setAmbientIntensity(0.0f);
|
pointOffLight->setAmbientIntensity(0.0f);
|
||||||
pointOffLight->setColor(model::Vec3(0.0));
|
pointOffLight->setColor(model::Vec3(0.0));
|
||||||
pointOffLight->setIntensity(0.0f);
|
pointOffLight->setIntensity(0.0f);
|
||||||
pointOffLight->setType(model::Light::Type::POINT);
|
pointOffLight->setType(model::Light::Type::POINT);
|
||||||
_pointOffLight = addLight(pointOffLight);
|
_pointOffLightId = addLight(pointOffLight);
|
||||||
|
|
||||||
const LightPointer spotOffLight { std::make_shared<model::Light>() };
|
const LightPointer spotOffLight { std::make_shared<model::Light>() };
|
||||||
spotOffLight->setAmbientIntensity(0.0f);
|
spotOffLight->setAmbientIntensity(0.0f);
|
||||||
spotOffLight->setColor(model::Vec3(0.0));
|
spotOffLight->setColor(model::Vec3(0.0));
|
||||||
spotOffLight->setIntensity(0.0f);
|
spotOffLight->setIntensity(0.0f);
|
||||||
spotOffLight->setType(model::Light::Type::SPOT);
|
spotOffLight->setType(model::Light::Type::SPOT);
|
||||||
_spotOffLight = addLight(spotOffLight);
|
_spotOffLightId = addLight(spotOffLight);
|
||||||
|
|
||||||
const LightPointer sunOffLight { std::make_shared<model::Light>() };
|
const LightPointer sunOffLight { std::make_shared<model::Light>() };
|
||||||
sunOffLight->setAmbientIntensity(0.0f);
|
sunOffLight->setAmbientIntensity(0.0f);
|
||||||
sunOffLight->setColor(model::Vec3(0.0));
|
sunOffLight->setColor(model::Vec3(0.0));
|
||||||
sunOffLight->setIntensity(0.0f);
|
sunOffLight->setIntensity(0.0f);
|
||||||
sunOffLight->setType(model::Light::Type::SUN);
|
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() {
|
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);
|
auto found = _lightMap.find(light);
|
||||||
if (found == _lightMap.end()) {
|
if (found == _lightMap.end()) {
|
||||||
auto lightId = _lights.newElement(light);
|
lightId = _lights.newElement(light);
|
||||||
// Avoid failing to allocate a light, just pass
|
// Avoid failing to allocate a light, just pass
|
||||||
if (lightId != INVALID_INDEX) {
|
if (lightId != INVALID_INDEX) {
|
||||||
|
|
||||||
|
@ -314,10 +319,15 @@ LightStage::Index LightStage::addLight(const LightPointer& light) {
|
||||||
|
|
||||||
updateLightArrayBuffer(lightId);
|
updateLightArrayBuffer(lightId);
|
||||||
}
|
}
|
||||||
return lightId;
|
|
||||||
} else {
|
} else {
|
||||||
return (*found).second;
|
lightId = (*found).second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (shouldSetAsDefault) {
|
||||||
|
_defaultLightId = lightId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return lightId;
|
||||||
}
|
}
|
||||||
|
|
||||||
LightStage::Index LightStage::addShadow(Index lightIndex, float maxDistance, unsigned int cascadeCount) {
|
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 {
|
LightStage::LightPointer LightStage::getCurrentKeyLight() const {
|
||||||
Index keyLightId{ 0 };
|
Index keyLightId{ _defaultLightId };
|
||||||
if (!_currentFrame._sunLights.empty()) {
|
// There is always at least 1 light (the off light)
|
||||||
|
if (_currentFrame._sunLights.size() > 1) {
|
||||||
keyLightId = _currentFrame._sunLights.front();
|
keyLightId = _currentFrame._sunLights.front();
|
||||||
}
|
}
|
||||||
return _lights.get(keyLightId);
|
return _lights.get(keyLightId);
|
||||||
}
|
}
|
||||||
|
|
||||||
LightStage::LightPointer LightStage::getCurrentAmbientLight() const {
|
LightStage::LightPointer LightStage::getCurrentAmbientLight() const {
|
||||||
Index keyLightId{ 0 };
|
Index keyLightId { _defaultLightId };
|
||||||
if (!_currentFrame._ambientLights.empty()) {
|
// There is always at least 1 light (the off light)
|
||||||
|
if (_currentFrame._ambientLights.size() > 1) {
|
||||||
keyLightId = _currentFrame._ambientLights.front();
|
keyLightId = _currentFrame._ambientLights.front();
|
||||||
}
|
}
|
||||||
return _lights.get(keyLightId);
|
return _lights.get(keyLightId);
|
||||||
}
|
}
|
||||||
|
|
||||||
LightStage::ShadowPointer LightStage::getCurrentKeyShadow() const {
|
LightStage::ShadowPointer LightStage::getCurrentKeyShadow() const {
|
||||||
Index keyLightId{ 0 };
|
Index keyLightId { _defaultLightId };
|
||||||
if (!_currentFrame._sunLights.empty()) {
|
// There is always at least 1 light (the off light)
|
||||||
|
if (_currentFrame._sunLights.size() > 1) {
|
||||||
keyLightId = _currentFrame._sunLights.front();
|
keyLightId = _currentFrame._sunLights.front();
|
||||||
}
|
}
|
||||||
auto shadow = getShadow(keyLightId);
|
auto shadow = getShadow(keyLightId);
|
||||||
|
@ -375,8 +388,9 @@ LightStage::ShadowPointer LightStage::getCurrentKeyShadow() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
LightStage::LightAndShadow LightStage::getCurrentKeyLightAndShadow() const {
|
LightStage::LightAndShadow LightStage::getCurrentKeyLightAndShadow() const {
|
||||||
Index keyLightId{ 0 };
|
Index keyLightId { _defaultLightId };
|
||||||
if (!_currentFrame._sunLights.empty()) {
|
// There is always at least 1 light (the off light)
|
||||||
|
if (_currentFrame._sunLights.size() > 1) {
|
||||||
keyLightId = _currentFrame._sunLights.front();
|
keyLightId = _currentFrame._sunLights.front();
|
||||||
}
|
}
|
||||||
auto shadow = getShadow(keyLightId);
|
auto shadow = getShadow(keyLightId);
|
||||||
|
|
|
@ -118,7 +118,7 @@ public:
|
||||||
using Shadows = render::indexed_container::IndexedPointerVector<Shadow>;
|
using Shadows = render::indexed_container::IndexedPointerVector<Shadow>;
|
||||||
|
|
||||||
Index findLight(const LightPointer& light) const;
|
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);
|
Index addShadow(Index lightIndex, float maxDistance = 20.0f, unsigned int cascadeCount = 1U);
|
||||||
|
|
||||||
|
@ -185,10 +185,10 @@ public:
|
||||||
|
|
||||||
Frame _currentFrame;
|
Frame _currentFrame;
|
||||||
|
|
||||||
Index getAmbientOffLight() { return _ambientOffLight; }
|
Index getAmbientOffLight() { return _ambientOffLightId; }
|
||||||
Index getPointOffLight() { return _pointOffLight; }
|
Index getPointOffLight() { return _pointOffLightId; }
|
||||||
Index getSpotOffLight() { return _spotOffLight; }
|
Index getSpotOffLight() { return _spotOffLightId; }
|
||||||
Index getSunOffLight() { return _sunOffLight; }
|
Index getSunOffLight() { return _sunOffLightId; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -205,17 +205,12 @@ protected:
|
||||||
LightMap _lightMap;
|
LightMap _lightMap;
|
||||||
|
|
||||||
// define off lights
|
// define off lights
|
||||||
|
Index _ambientOffLightId;
|
||||||
|
Index _pointOffLightId;
|
||||||
|
Index _spotOffLightId;
|
||||||
|
Index _sunOffLightId;
|
||||||
|
|
||||||
const LightPointer ambientOffLight { std::make_shared<model::Light>() };
|
Index _defaultLightId;
|
||||||
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;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
using LightStagePointer = std::shared_ptr<LightStage>;
|
using LightStagePointer = std::shared_ptr<LightStage>;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue