mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-07-17 14:06:19 +02:00
Merge pull request #8444 from zzmp/fix/skybox
fix flashing in default skybox, and allow skybox lighting without textures
This commit is contained in:
commit
d1fb723b01
6 changed files with 67 additions and 104 deletions
|
@ -4253,6 +4253,21 @@ namespace render {
|
||||||
auto backgroundMode = skyStage->getBackgroundMode();
|
auto backgroundMode = skyStage->getBackgroundMode();
|
||||||
|
|
||||||
switch (backgroundMode) {
|
switch (backgroundMode) {
|
||||||
|
case model::SunSkyStage::SKY_DEFAULT: {
|
||||||
|
static const glm::vec3 DEFAULT_SKYBOX_COLOR{ 255.0f / 255.0f, 220.0f / 255.0f, 194.0f / 255.0f };
|
||||||
|
static const float DEFAULT_SKYBOX_INTENSITY{ 0.2f };
|
||||||
|
static const float DEFAULT_SKYBOX_AMBIENT_INTENSITY{ 2.0f };
|
||||||
|
static const glm::vec3 DEFAULT_SKYBOX_DIRECTION{ 0.0f, 0.0f, -1.0f };
|
||||||
|
|
||||||
|
auto scene = DependencyManager::get<SceneScriptingInterface>()->getStage();
|
||||||
|
auto sceneKeyLight = scene->getKeyLight();
|
||||||
|
scene->setSunModelEnable(false);
|
||||||
|
sceneKeyLight->setColor(DEFAULT_SKYBOX_COLOR);
|
||||||
|
sceneKeyLight->setIntensity(DEFAULT_SKYBOX_INTENSITY);
|
||||||
|
sceneKeyLight->setAmbientIntensity(DEFAULT_SKYBOX_AMBIENT_INTENSITY);
|
||||||
|
sceneKeyLight->setDirection(DEFAULT_SKYBOX_DIRECTION);
|
||||||
|
// fall through: render a skybox, if available
|
||||||
|
}
|
||||||
case model::SunSkyStage::SKY_BOX: {
|
case model::SunSkyStage::SKY_BOX: {
|
||||||
auto skybox = skyStage->getSkybox();
|
auto skybox = skyStage->getSkybox();
|
||||||
if (skybox) {
|
if (skybox) {
|
||||||
|
@ -4260,33 +4275,22 @@ namespace render {
|
||||||
skybox->render(batch, args->getViewFrustum());
|
skybox->render(batch, args->getViewFrustum());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
// fall through: render defaults, if available
|
||||||
}
|
}
|
||||||
|
case model::SunSkyStage::SKY_DEFAULT_AMBIENT_TEXTURE: {
|
||||||
// Fall through: if no skybox is available, render the SKY_DOME
|
if (Menu::getInstance()->isOptionChecked(MenuOption::DefaultSkybox)) {
|
||||||
case model::SunSkyStage::SKY_DOME: {
|
auto scene = DependencyManager::get<SceneScriptingInterface>()->getStage();
|
||||||
if (Menu::getInstance()->isOptionChecked(MenuOption::DefaultSkybox)) {
|
auto sceneKeyLight = scene->getKeyLight();
|
||||||
static const glm::vec3 DEFAULT_SKYBOX_COLOR { 255.0f / 255.0f, 220.0f / 255.0f, 194.0f / 255.0f };
|
auto defaultSkyboxAmbientTexture = qApp->getDefaultSkyboxAmbientTexture();
|
||||||
static const float DEFAULT_SKYBOX_INTENSITY { 0.2f };
|
// do not set the ambient sphere - it peaks too high, and causes flashing when turning
|
||||||
static const float DEFAULT_SKYBOX_AMBIENT_INTENSITY { 2.0f };
|
sceneKeyLight->setAmbientMap(defaultSkyboxAmbientTexture);
|
||||||
static const glm::vec3 DEFAULT_SKYBOX_DIRECTION { 0.0f, 0.0f, -1.0f };
|
}
|
||||||
|
// fall through: render defaults, if available
|
||||||
auto scene = DependencyManager::get<SceneScriptingInterface>()->getStage();
|
|
||||||
auto sceneKeyLight = scene->getKeyLight();
|
|
||||||
scene->setSunModelEnable(false);
|
|
||||||
sceneKeyLight->setColor(DEFAULT_SKYBOX_COLOR);
|
|
||||||
sceneKeyLight->setIntensity(DEFAULT_SKYBOX_INTENSITY);
|
|
||||||
sceneKeyLight->setAmbientIntensity(DEFAULT_SKYBOX_AMBIENT_INTENSITY);
|
|
||||||
sceneKeyLight->setDirection(DEFAULT_SKYBOX_DIRECTION);
|
|
||||||
|
|
||||||
auto defaultSkyboxAmbientTexture = qApp->getDefaultSkyboxAmbientTexture();
|
|
||||||
sceneKeyLight->setAmbientSphere(defaultSkyboxAmbientTexture->getIrradiance());
|
|
||||||
sceneKeyLight->setAmbientMap(defaultSkyboxAmbientTexture);
|
|
||||||
|
|
||||||
qApp->getDefaultSkybox()->render(batch, args->getViewFrustum());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
case model::SunSkyStage::SKY_DEFAULT_TEXTURE:
|
||||||
|
if (Menu::getInstance()->isOptionChecked(MenuOption::DefaultSkybox)) {
|
||||||
|
qApp->getDefaultSkybox()->render(batch, args->getViewFrustum());
|
||||||
|
}
|
||||||
case model::SunSkyStage::NO_BACKGROUND:
|
case model::SunSkyStage::NO_BACKGROUND:
|
||||||
default:
|
default:
|
||||||
// this line intentionally left blank
|
// this line intentionally left blank
|
||||||
|
@ -4503,7 +4507,7 @@ void Application::clearDomainOctreeDetails() {
|
||||||
|
|
||||||
auto skyStage = DependencyManager::get<SceneScriptingInterface>()->getSkyStage();
|
auto skyStage = DependencyManager::get<SceneScriptingInterface>()->getSkyStage();
|
||||||
|
|
||||||
skyStage->setBackgroundMode(model::SunSkyStage::SKY_DOME);
|
skyStage->setBackgroundMode(model::SunSkyStage::SKY_DEFAULT);
|
||||||
|
|
||||||
_recentlyClearedDomain = true;
|
_recentlyClearedDomain = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -346,15 +346,13 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
|
||||||
auto sceneStage = scene->getStage();
|
auto sceneStage = scene->getStage();
|
||||||
auto skyStage = scene->getSkyStage();
|
auto skyStage = scene->getSkyStage();
|
||||||
auto sceneKeyLight = sceneStage->getKeyLight();
|
auto sceneKeyLight = sceneStage->getKeyLight();
|
||||||
auto sceneLocation = sceneStage->getLocation();
|
|
||||||
auto sceneTime = sceneStage->getTime();
|
|
||||||
|
|
||||||
// Skybox and procedural skybox data
|
// Skybox and procedural skybox data
|
||||||
auto skybox = std::dynamic_pointer_cast<ProceduralSkybox>(skyStage->getSkybox());
|
auto skybox = std::dynamic_pointer_cast<ProceduralSkybox>(skyStage->getSkybox());
|
||||||
static QString userData;
|
|
||||||
|
|
||||||
|
// If there is no zone, use the default background
|
||||||
if (!zone) {
|
if (!zone) {
|
||||||
userData = QString();
|
_zoneUserData = QString();
|
||||||
skybox->clear();
|
skybox->clear();
|
||||||
|
|
||||||
_pendingSkyboxTexture = false;
|
_pendingSkyboxTexture = false;
|
||||||
|
@ -363,50 +361,33 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
|
||||||
_pendingAmbientTexture = false;
|
_pendingAmbientTexture = false;
|
||||||
_ambientTexture.clear();
|
_ambientTexture.clear();
|
||||||
|
|
||||||
if (_hasPreviousZone) {
|
sceneKeyLight->resetAmbientSphere();
|
||||||
sceneKeyLight->resetAmbientSphere();
|
sceneKeyLight->setAmbientMap(nullptr);
|
||||||
sceneKeyLight->setAmbientMap(nullptr);
|
|
||||||
sceneKeyLight->setColor(_previousKeyLightColor);
|
|
||||||
sceneKeyLight->setIntensity(_previousKeyLightIntensity);
|
|
||||||
sceneKeyLight->setAmbientIntensity(_previousKeyLightAmbientIntensity);
|
|
||||||
sceneKeyLight->setDirection(_previousKeyLightDirection);
|
|
||||||
sceneStage->setSunModelEnable(_previousStageSunModelEnabled);
|
|
||||||
sceneStage->setLocation(_previousStageLongitude, _previousStageLatitude,
|
|
||||||
_previousStageAltitude);
|
|
||||||
sceneTime->setHour(_previousStageHour);
|
|
||||||
sceneTime->setDay(_previousStageDay);
|
|
||||||
|
|
||||||
_hasPreviousZone = false;
|
skyStage->setBackgroundMode(model::SunSkyStage::SKY_DEFAULT);
|
||||||
}
|
return;
|
||||||
|
|
||||||
skyStage->setBackgroundMode(model::SunSkyStage::SKY_DOME); // let the application background through
|
|
||||||
return; // Early exit
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_hasPreviousZone) {
|
|
||||||
_previousKeyLightColor = sceneKeyLight->getColor();
|
|
||||||
_previousKeyLightIntensity = sceneKeyLight->getIntensity();
|
|
||||||
_previousKeyLightAmbientIntensity = sceneKeyLight->getAmbientIntensity();
|
|
||||||
_previousKeyLightDirection = sceneKeyLight->getDirection();
|
|
||||||
_previousStageSunModelEnabled = sceneStage->isSunModelEnabled();
|
|
||||||
_previousStageLongitude = sceneLocation->getLongitude();
|
|
||||||
_previousStageLatitude = sceneLocation->getLatitude();
|
|
||||||
_previousStageAltitude = sceneLocation->getAltitude();
|
|
||||||
_previousStageHour = sceneTime->getHour();
|
|
||||||
_previousStageDay = sceneTime->getDay();
|
|
||||||
_hasPreviousZone = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the keylight
|
||||||
sceneKeyLight->setColor(ColorUtils::toVec3(zone->getKeyLightProperties().getColor()));
|
sceneKeyLight->setColor(ColorUtils::toVec3(zone->getKeyLightProperties().getColor()));
|
||||||
sceneKeyLight->setIntensity(zone->getKeyLightProperties().getIntensity());
|
sceneKeyLight->setIntensity(zone->getKeyLightProperties().getIntensity());
|
||||||
sceneKeyLight->setAmbientIntensity(zone->getKeyLightProperties().getAmbientIntensity());
|
sceneKeyLight->setAmbientIntensity(zone->getKeyLightProperties().getAmbientIntensity());
|
||||||
sceneKeyLight->setDirection(zone->getKeyLightProperties().getDirection());
|
sceneKeyLight->setDirection(zone->getKeyLightProperties().getDirection());
|
||||||
sceneStage->setSunModelEnable(zone->getStageProperties().getSunModelEnabled());
|
|
||||||
sceneStage->setLocation(zone->getStageProperties().getLongitude(), zone->getStageProperties().getLatitude(),
|
|
||||||
zone->getStageProperties().getAltitude());
|
|
||||||
sceneTime->setHour(zone->getStageProperties().calculateHour());
|
|
||||||
sceneTime->setDay(zone->getStageProperties().calculateDay());
|
|
||||||
|
|
||||||
|
// Set the stage
|
||||||
|
bool isSunModelEnabled = zone->getStageProperties().getSunModelEnabled();
|
||||||
|
sceneStage->setSunModelEnable(isSunModelEnabled);
|
||||||
|
if (isSunModelEnabled) {
|
||||||
|
sceneStage->setLocation(zone->getStageProperties().getLongitude(),
|
||||||
|
zone->getStageProperties().getLatitude(),
|
||||||
|
zone->getStageProperties().getAltitude());
|
||||||
|
|
||||||
|
auto sceneTime = sceneStage->getTime();
|
||||||
|
sceneTime->setHour(zone->getStageProperties().calculateHour());
|
||||||
|
sceneTime->setDay(zone->getStageProperties().calculateDay());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the ambient texture
|
||||||
bool isAmbientTextureSet = false;
|
bool isAmbientTextureSet = false;
|
||||||
if (zone->getKeyLightProperties().getAmbientURL().isEmpty()) {
|
if (zone->getKeyLightProperties().getAmbientURL().isEmpty()) {
|
||||||
_pendingAmbientTexture = false;
|
_pendingAmbientTexture = false;
|
||||||
|
@ -429,12 +410,13 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the skybox texture
|
||||||
switch (zone->getBackgroundMode()) {
|
switch (zone->getBackgroundMode()) {
|
||||||
case BACKGROUND_MODE_SKYBOX: {
|
case BACKGROUND_MODE_SKYBOX: {
|
||||||
skybox->setColor(zone->getSkyboxProperties().getColorVec3());
|
skybox->setColor(zone->getSkyboxProperties().getColorVec3());
|
||||||
if (userData != zone->getUserData()) {
|
if (_zoneUserData != zone->getUserData()) {
|
||||||
userData = zone->getUserData();
|
_zoneUserData = zone->getUserData();
|
||||||
skybox->parse(userData);
|
skybox->parse(_zoneUserData);
|
||||||
}
|
}
|
||||||
if (zone->getSkyboxProperties().getURL().isEmpty()) {
|
if (zone->getSkyboxProperties().getURL().isEmpty()) {
|
||||||
skybox->setCubemap(nullptr);
|
skybox->setCubemap(nullptr);
|
||||||
|
@ -471,14 +453,18 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
|
||||||
case BACKGROUND_MODE_INHERIT:
|
case BACKGROUND_MODE_INHERIT:
|
||||||
default:
|
default:
|
||||||
// Clear the skybox to release its textures
|
// Clear the skybox to release its textures
|
||||||
userData = QString();
|
_zoneUserData = QString();
|
||||||
skybox->clear();
|
skybox->clear();
|
||||||
|
|
||||||
_skyboxTexture.clear();
|
_skyboxTexture.clear();
|
||||||
_pendingSkyboxTexture = false;
|
_pendingSkyboxTexture = false;
|
||||||
|
|
||||||
// Let the application background through
|
// Let the application background through
|
||||||
skyStage->setBackgroundMode(model::SunSkyStage::SKY_DOME);
|
if (isAmbientTextureSet) {
|
||||||
|
skyStage->setBackgroundMode(model::SunSkyStage::SKY_DEFAULT_TEXTURE);
|
||||||
|
} else {
|
||||||
|
skyStage->setBackgroundMode(model::SunSkyStage::SKY_DEFAULT_AMBIENT_TEXTURE);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -185,25 +185,15 @@ private:
|
||||||
|
|
||||||
QMultiMap<QUrl, EntityItemID> _waitingOnPreload;
|
QMultiMap<QUrl, EntityItemID> _waitingOnPreload;
|
||||||
|
|
||||||
bool _hasPreviousZone { false };
|
|
||||||
std::shared_ptr<ZoneEntityItem> _bestZone;
|
std::shared_ptr<ZoneEntityItem> _bestZone;
|
||||||
float _bestZoneVolume;
|
float _bestZoneVolume;
|
||||||
|
|
||||||
|
QString _zoneUserData;
|
||||||
|
|
||||||
quint64 _lastZoneCheck { 0 };
|
quint64 _lastZoneCheck { 0 };
|
||||||
const quint64 ZONE_CHECK_INTERVAL = USECS_PER_MSEC * 100; // ~10hz
|
const quint64 ZONE_CHECK_INTERVAL = USECS_PER_MSEC * 100; // ~10hz
|
||||||
const float ZONE_CHECK_DISTANCE = 0.001f;
|
const float ZONE_CHECK_DISTANCE = 0.001f;
|
||||||
|
|
||||||
glm::vec3 _previousKeyLightColor;
|
|
||||||
float _previousKeyLightIntensity;
|
|
||||||
float _previousKeyLightAmbientIntensity;
|
|
||||||
glm::vec3 _previousKeyLightDirection;
|
|
||||||
bool _previousStageSunModelEnabled;
|
|
||||||
float _previousStageLongitude;
|
|
||||||
float _previousStageLatitude;
|
|
||||||
float _previousStageAltitude;
|
|
||||||
float _previousStageHour;
|
|
||||||
int _previousStageDay;
|
|
||||||
|
|
||||||
QHash<EntityItemID, EntityItemPointer> _entitiesInScene;
|
QHash<EntityItemID, EntityItemPointer> _entitiesInScene;
|
||||||
// For Scene.shouldRenderEntities
|
// For Scene.shouldRenderEntities
|
||||||
QList<EntityItemID> _entityIDsLastInScene;
|
QList<EntityItemID> _entityIDsLastInScene;
|
||||||
|
|
|
@ -244,21 +244,6 @@ void SunSkyStage::updateGraphicsObject() const {
|
||||||
double originAlt = _earthSunModel.getAltitude();
|
double originAlt = _earthSunModel.getAltitude();
|
||||||
_sunLight->setPosition(Vec3(0.0f, originAlt, 0.0f));
|
_sunLight->setPosition(Vec3(0.0f, originAlt, 0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Background
|
|
||||||
switch (getBackgroundMode()) {
|
|
||||||
case NO_BACKGROUND: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SKY_DOME: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case SKY_BOX: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case NUM_BACKGROUND_MODES:
|
|
||||||
Q_UNREACHABLE();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SunSkyStage::setBackgroundMode(BackgroundMode mode) {
|
void SunSkyStage::setBackgroundMode(BackgroundMode mode) {
|
||||||
|
|
|
@ -160,8 +160,10 @@ public:
|
||||||
|
|
||||||
enum BackgroundMode {
|
enum BackgroundMode {
|
||||||
NO_BACKGROUND = 0,
|
NO_BACKGROUND = 0,
|
||||||
SKY_DOME,
|
SKY_DEFAULT,
|
||||||
SKY_BOX,
|
SKY_BOX,
|
||||||
|
SKY_DEFAULT_AMBIENT_TEXTURE,
|
||||||
|
SKY_DEFAULT_TEXTURE,
|
||||||
|
|
||||||
NUM_BACKGROUND_MODES,
|
NUM_BACKGROUND_MODES,
|
||||||
};
|
};
|
||||||
|
@ -173,7 +175,7 @@ public:
|
||||||
const SkyboxPointer& getSkybox() const { valid(); return _skybox; }
|
const SkyboxPointer& getSkybox() const { valid(); return _skybox; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
BackgroundMode _backgroundMode = SKY_DOME;
|
BackgroundMode _backgroundMode = SKY_DEFAULT;
|
||||||
|
|
||||||
LightPointer _sunLight;
|
LightPointer _sunLight;
|
||||||
mutable SkyboxPointer _skybox;
|
mutable SkyboxPointer _skybox;
|
||||||
|
|
|
@ -345,10 +345,6 @@ namespace render {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fall through: if no skybox is available, render the SKY_DOME
|
|
||||||
case model::SunSkyStage::SKY_DOME:
|
|
||||||
case model::SunSkyStage::NO_BACKGROUND:
|
|
||||||
default:
|
default:
|
||||||
// this line intentionally left blank
|
// this line intentionally left blank
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue