use lights from nontextured skyboxes

This commit is contained in:
Zach Pomerantz 2016-08-16 13:27:22 -07:00
parent 4d0c819173
commit 8c559bc65d
6 changed files with 65 additions and 102 deletions

View file

@ -4253,6 +4253,21 @@ namespace render {
auto backgroundMode = skyStage->getBackgroundMode();
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: {
auto skybox = skyStage->getSkybox();
if (skybox) {
@ -4260,33 +4275,22 @@ namespace render {
skybox->render(batch, args->getViewFrustum());
break;
}
// fall through: render defaults, if available
}
// Fall through: if no skybox is available, render the SKY_DOME
case model::SunSkyStage::SKY_DOME: {
if (Menu::getInstance()->isOptionChecked(MenuOption::DefaultSkybox)) {
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);
auto defaultSkyboxAmbientTexture = qApp->getDefaultSkyboxAmbientTexture();
// do not set the ambient sphere - it peaks too high, and causes flashing when turning
sceneKeyLight->setAmbientMap(defaultSkyboxAmbientTexture);
qApp->getDefaultSkybox()->render(batch, args->getViewFrustum());
}
case model::SunSkyStage::SKY_DEFAULT_AMBIENT_TEXTURE: {
if (Menu::getInstance()->isOptionChecked(MenuOption::DefaultSkybox)) {
auto scene = DependencyManager::get<SceneScriptingInterface>()->getStage();
auto sceneKeyLight = scene->getKeyLight();
auto defaultSkyboxAmbientTexture = qApp->getDefaultSkyboxAmbientTexture();
// do not set the ambient sphere - it peaks too high, and causes flashing when turning
sceneKeyLight->setAmbientMap(defaultSkyboxAmbientTexture);
}
// fall through: render defaults, if available
}
break;
case model::SunSkyStage::SKY_DEFAULT_TEXTURE:
if (Menu::getInstance()->isOptionChecked(MenuOption::DefaultSkybox)) {
qApp->getDefaultSkybox()->render(batch, args->getViewFrustum());
}
case model::SunSkyStage::NO_BACKGROUND:
default:
// this line intentionally left blank
@ -4503,7 +4507,7 @@ void Application::clearDomainOctreeDetails() {
auto skyStage = DependencyManager::get<SceneScriptingInterface>()->getSkyStage();
skyStage->setBackgroundMode(model::SunSkyStage::SKY_DOME);
skyStage->setBackgroundMode(model::SunSkyStage::SKY_DEFAULT);
_recentlyClearedDomain = true;
}

View file

@ -351,10 +351,10 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
// Skybox and procedural skybox data
auto skybox = std::dynamic_pointer_cast<ProceduralSkybox>(skyStage->getSkybox());
static QString userData;
// If there is no zone, use the default background
if (!zone) {
userData = QString();
_zoneUserData = QString();
skybox->clear();
_pendingSkyboxTexture = false;
@ -363,50 +363,31 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
_pendingAmbientTexture = false;
_ambientTexture.clear();
if (_hasPreviousZone) {
sceneKeyLight->resetAmbientSphere();
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);
sceneKeyLight->resetAmbientSphere();
sceneKeyLight->setAmbientMap(nullptr);
_hasPreviousZone = false;
}
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;
skyStage->setBackgroundMode(model::SunSkyStage::SKY_DEFAULT);
return;
}
// Set the keylight
sceneKeyLight->setColor(ColorUtils::toVec3(zone->getKeyLightProperties().getColor()));
sceneKeyLight->setIntensity(zone->getKeyLightProperties().getIntensity());
sceneKeyLight->setAmbientIntensity(zone->getKeyLightProperties().getAmbientIntensity());
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());
sceneTime->setHour(zone->getStageProperties().calculateHour());
sceneTime->setDay(zone->getStageProperties().calculateDay());
}
// Set the ambient texture
bool isAmbientTextureSet = false;
if (zone->getKeyLightProperties().getAmbientURL().isEmpty()) {
_pendingAmbientTexture = false;
@ -429,12 +410,13 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
}
}
// Set the skybox texture
switch (zone->getBackgroundMode()) {
case BACKGROUND_MODE_SKYBOX: {
skybox->setColor(zone->getSkyboxProperties().getColorVec3());
if (userData != zone->getUserData()) {
userData = zone->getUserData();
skybox->parse(userData);
if (_zoneUserData != zone->getUserData()) {
_zoneUserData = zone->getUserData();
skybox->parse(_zoneUserData);
}
if (zone->getSkyboxProperties().getURL().isEmpty()) {
skybox->setCubemap(nullptr);
@ -471,14 +453,18 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
case BACKGROUND_MODE_INHERIT:
default:
// Clear the skybox to release its textures
userData = QString();
_zoneUserData = QString();
skybox->clear();
_skyboxTexture.clear();
_pendingSkyboxTexture = false;
// 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;
}

View file

@ -185,25 +185,15 @@ private:
QMultiMap<QUrl, EntityItemID> _waitingOnPreload;
bool _hasPreviousZone { false };
std::shared_ptr<ZoneEntityItem> _bestZone;
float _bestZoneVolume;
QString _zoneUserData;
quint64 _lastZoneCheck { 0 };
const quint64 ZONE_CHECK_INTERVAL = USECS_PER_MSEC * 100; // ~10hz
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;
// For Scene.shouldRenderEntities
QList<EntityItemID> _entityIDsLastInScene;

View file

@ -244,21 +244,6 @@ void SunSkyStage::updateGraphicsObject() const {
double originAlt = _earthSunModel.getAltitude();
_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) {

View file

@ -160,8 +160,10 @@ public:
enum BackgroundMode {
NO_BACKGROUND = 0,
SKY_DOME,
SKY_DEFAULT,
SKY_BOX,
SKY_DEFAULT_AMBIENT_TEXTURE,
SKY_DEFAULT_TEXTURE,
NUM_BACKGROUND_MODES,
};
@ -173,7 +175,7 @@ public:
const SkyboxPointer& getSkybox() const { valid(); return _skybox; }
protected:
BackgroundMode _backgroundMode = SKY_DOME;
BackgroundMode _backgroundMode = SKY_DEFAULT;
LightPointer _sunLight;
mutable SkyboxPointer _skybox;

View file

@ -345,10 +345,6 @@ namespace render {
break;
}
}
// Fall through: if no skybox is available, render the SKY_DOME
case model::SunSkyStage::SKY_DOME:
case model::SunSkyStage::NO_BACKGROUND:
default:
// this line intentionally left blank
break;