Wire up zone ambientURL

This commit is contained in:
Zach Pomerantz 2016-02-24 14:58:41 -08:00
parent 13153bcf08
commit 95d98e3ed7
9 changed files with 69 additions and 55 deletions

View file

@ -3816,18 +3816,10 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
}); });
} }
// Setup the current Zone Entity lighting and skybox // Setup the current Zone Entity lighting
{ {
// FIXME: Use a zone setting to determine the ambient light mode auto sun = DependencyManager::get<SceneScriptingInterface>()->getSkyStage()->getSunLight();
DependencyManager::get<DeferredLightingEffect>()->setAmbientLightMode(-1); DependencyManager::get<DeferredLightingEffect>()->setGlobalLight(sun);
auto skyStage = DependencyManager::get<SceneScriptingInterface>()->getSkyStage();
DependencyManager::get<DeferredLightingEffect>()->setGlobalLight(skyStage->getSunLight()->getDirection(), skyStage->getSunLight()->getColor(), skyStage->getSunLight()->getIntensity(), skyStage->getSunLight()->getAmbientIntensity());
auto skybox = model::SkyboxPointer();
if (skyStage->getBackgroundMode() == model::SunSkyStage::SKY_BOX) {
skybox = skyStage->getSkybox();
}
DependencyManager::get<DeferredLightingEffect>()->setGlobalSkybox(skybox);
} }
{ {

View file

@ -140,7 +140,8 @@ void EntityTreeRenderer::update() {
// even if we haven't changed positions, if we previously attempted to set the skybox, but // even if we haven't changed positions, if we previously attempted to set the skybox, but
// have a pending download of the skybox texture, then we should attempt to reapply to // have a pending download of the skybox texture, then we should attempt to reapply to
// get the correct texture. // get the correct texture.
if (_pendingSkyboxTexture && _skyboxTexture && _skyboxTexture->isLoaded()) { if ((_pendingSkyboxTexture && _skyboxTexture && _skyboxTexture->isLoaded()) ||
(_pendingAmbientTexture && _ambientTexture && _ambientTexture->isLoaded())) {
applyZonePropertiesToScene(_bestZone); applyZonePropertiesToScene(_bestZone);
} }
@ -253,6 +254,7 @@ void EntityTreeRenderer::forceRecheckEntities() {
void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityItem> zone) { void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityItem> zone) {
auto textureCache = DependencyManager::get<TextureCache>();
auto scene = DependencyManager::get<SceneScriptingInterface>(); auto scene = DependencyManager::get<SceneScriptingInterface>();
auto sceneStage = scene->getStage(); auto sceneStage = scene->getStage();
auto skyStage = scene->getSkyStage(); auto skyStage = scene->getSkyStage();
@ -264,7 +266,11 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
_pendingSkyboxTexture = false; _pendingSkyboxTexture = false;
_skyboxTexture.clear(); _skyboxTexture.clear();
_pendingAmbientTexture = false;
_ambientTexture.clear();
if (_hasPreviousZone) { if (_hasPreviousZone) {
sceneKeyLight->resetAmbientSphere();
sceneKeyLight->setColor(_previousKeyLightColor); sceneKeyLight->setColor(_previousKeyLightColor);
sceneKeyLight->setIntensity(_previousKeyLightIntensity); sceneKeyLight->setIntensity(_previousKeyLightIntensity);
sceneKeyLight->setAmbientIntensity(_previousKeyLightAmbientIntensity); sceneKeyLight->setAmbientIntensity(_previousKeyLightAmbientIntensity);
@ -274,6 +280,7 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
_previousStageAltitude); _previousStageAltitude);
sceneTime->setHour(_previousStageHour); sceneTime->setHour(_previousStageHour);
sceneTime->setDay(_previousStageDay); sceneTime->setDay(_previousStageDay);
_hasPreviousZone = false; _hasPreviousZone = false;
} }
@ -306,6 +313,23 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
sceneTime->setHour(zone->getStageProperties().calculateHour()); sceneTime->setHour(zone->getStageProperties().calculateHour());
sceneTime->setDay(zone->getStageProperties().calculateDay()); sceneTime->setDay(zone->getStageProperties().calculateDay());
bool isAmbientTextureSet = false;
if (zone->getKeyLightProperties().getAmbientURL().isEmpty()) {
_pendingAmbientTexture = false;
_ambientTexture.clear();
} else {
_ambientTexture = textureCache->getTexture(zone->getKeyLightProperties().getAmbientURL(), CUBE_TEXTURE);
if (_ambientTexture->getGPUTexture()) {
_pendingAmbientTexture = false;
if (_ambientTexture->getGPUTexture()->getIrradiance()) {
sceneKeyLight->setAmbientSphere(_ambientTexture->getGPUTexture()->getIrradiance());
isAmbientTextureSet = true;
}
} else {
_pendingAmbientTexture = true;
}
}
switch (zone->getBackgroundMode()) { switch (zone->getBackgroundMode()) {
case BACKGROUND_MODE_SKYBOX: { case BACKGROUND_MODE_SKYBOX: {
auto skybox = std::dynamic_pointer_cast<ProceduralSkybox>(skyStage->getSkybox()); auto skybox = std::dynamic_pointer_cast<ProceduralSkybox>(skyStage->getSkybox());
@ -326,12 +350,16 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
_skyboxTexture.clear(); _skyboxTexture.clear();
} else { } else {
// Update the Texture of the Skybox with the one pointed by this zone // Update the Texture of the Skybox with the one pointed by this zone
auto textureCache = DependencyManager::get<TextureCache>();
_skyboxTexture = textureCache->getTexture(zone->getSkyboxProperties().getURL(), CUBE_TEXTURE); _skyboxTexture = textureCache->getTexture(zone->getSkyboxProperties().getURL(), CUBE_TEXTURE);
if (_skyboxTexture->getGPUTexture()) { if (_skyboxTexture->getGPUTexture()) {
skybox->setCubemap(_skyboxTexture->getGPUTexture()); auto texture = _skyboxTexture->getGPUTexture();
skybox->setCubemap(texture);
_pendingSkyboxTexture = false; _pendingSkyboxTexture = false;
if (!isAmbientTextureSet && texture->getIrradiance()) {
sceneKeyLight->setAmbientSphere(texture->getIrradiance());
isAmbientTextureSet = true;
}
} else { } else {
_pendingSkyboxTexture = true; _pendingSkyboxTexture = true;
} }
@ -348,6 +376,10 @@ void EntityTreeRenderer::applyZonePropertiesToScene(std::shared_ptr<ZoneEntityIt
_skyboxTexture.clear(); _skyboxTexture.clear();
break; break;
} }
if (!isAmbientTextureSet) {
sceneKeyLight->resetAmbientSphere();
}
} }
const FBXGeometry* EntityTreeRenderer::getGeometryForEntity(EntityItemPointer entityItem) { const FBXGeometry* EntityTreeRenderer::getGeometryForEntity(EntityItemPointer entityItem) {

View file

@ -146,6 +146,9 @@ private:
bool _pendingSkyboxTexture { false }; bool _pendingSkyboxTexture { false };
NetworkTexturePointer _skyboxTexture; NetworkTexturePointer _skyboxTexture;
bool _pendingAmbientTexture { false };
NetworkTexturePointer _ambientTexture;
bool _wantScripts; bool _wantScripts;
ScriptEngine* _entitiesScriptEngine; ScriptEngine* _entitiesScriptEngine;

View file

@ -202,14 +202,13 @@ void SunSkyStage::setSunModelEnable(bool isEnabled) {
invalidate(); invalidate();
} }
void SunSkyStage::setSunColor(const Vec3& color) { void SunSkyStage::setSunAmbientSphere(const gpu::SHPointer& sphere) {
_sunLight->setColor(color); if (sphere) {
} _sunLight->setAmbientSphere(*sphere);
void SunSkyStage::setSunIntensity(float intensity) { } else {
_sunLight->setIntensity(intensity); const gpu::SphericalHarmonics::Preset DEFAULT_AMBIENT_SPHERE = gpu::SphericalHarmonics::OLD_TOWN_SQUARE;
} _sunLight->setAmbientSpherePreset(DEFAULT_AMBIENT_SPHERE);
void SunSkyStage::setSunAmbientIntensity(float intensity) { }
_sunLight->setAmbientIntensity(intensity);
} }
void SunSkyStage::setSunDirection(const Vec3& direction) { void SunSkyStage::setSunDirection(const Vec3& direction) {

View file

@ -11,7 +11,7 @@
#ifndef hifi_model_Stage_h #ifndef hifi_model_Stage_h
#define hifi_model_Stage_h #define hifi_model_Stage_h
#include "gpu/Pipeline.h" #include <gpu/Pipeline.h>
#include "Light.h" #include "Light.h"
#include "Skybox.h" #include "Skybox.h"
@ -143,12 +143,13 @@ public:
bool isSunModelEnabled() const { return _sunModelEnable; } bool isSunModelEnabled() const { return _sunModelEnable; }
// Sun properties // Sun properties
void setSunColor(const Vec3& color); void setSunColor(const Vec3& color) { _sunLight->setColor(color); }
const Vec3& getSunColor() const { return getSunLight()->getColor(); } const Vec3& getSunColor() const { return getSunLight()->getColor(); }
void setSunIntensity(float intensity); void setSunIntensity(float intensity) { _sunLight->setIntensity(intensity); }
float getSunIntensity() const { return getSunLight()->getIntensity(); } float getSunIntensity() const { return getSunLight()->getIntensity(); }
void setSunAmbientIntensity(float intensity); void setSunAmbientIntensity(float intensity) { _sunLight->setAmbientIntensity(intensity); }
float getSunAmbientIntensity() const { return getSunLight()->getAmbientIntensity(); } float getSunAmbientIntensity() const { return getSunLight()->getAmbientIntensity(); }
void setSunAmbientSphere(const gpu::SHPointer& sphere);
// The sun direction is expressed in the world space // The sun direction is expressed in the world space
void setSunDirection(const Vec3& direction); void setSunDirection(const Vec3& direction);

View file

@ -562,32 +562,13 @@ static void loadLightProgram(const char* vertSource, const char* fragSource, boo
} }
void DeferredLightingEffect::setAmbientLightMode(int preset) { void DeferredLightingEffect::setGlobalLight(const model::LightPointer& light) {
if ((preset >= 0) && (preset < gpu::SphericalHarmonics::NUM_PRESET)) { auto globalLight = _allocatedLights.front();
_ambientLightMode = preset; globalLight->setDirection(light->getDirection());
auto light = _allocatedLights.front(); globalLight->setColor(light->getColor());
light->setAmbientSpherePreset(gpu::SphericalHarmonics::Preset(preset % gpu::SphericalHarmonics::NUM_PRESET)); globalLight->setIntensity(light->getIntensity());
} else { globalLight->setAmbientIntensity(light->getAmbientIntensity());
// force to preset 0 globalLight->setAmbientSphere(light->getAmbientSphere());
setAmbientLightMode(0);
}
}
void DeferredLightingEffect::setGlobalLight(const glm::vec3& direction, const glm::vec3& diffuse, float intensity, float ambientIntensity) {
auto light = _allocatedLights.front();
light->setDirection(direction);
light->setColor(diffuse);
light->setIntensity(intensity);
light->setAmbientIntensity(ambientIntensity);
}
void DeferredLightingEffect::setGlobalSkybox(const model::SkyboxPointer& skybox) {
_skybox = skybox;
auto light = _allocatedLights.front();
if (_skybox && _skybox->getCubemap() && _skybox->getCubemap()->isDefined() && _skybox->getCubemap()->getIrradiance()) {
light->setAmbientSphere( (*_skybox->getCubemap()->getIrradiance()) );
}
} }
model::MeshPointer DeferredLightingEffect::getSpotLightMesh() { model::MeshPointer DeferredLightingEffect::getSpotLightMesh() {

View file

@ -49,9 +49,7 @@ public:
void setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int skyboxCubemapUnit); void setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int skyboxCubemapUnit);
// update global lighting // update global lighting
void setAmbientLightMode(int preset); void setGlobalLight(const model::LightPointer& light);
void setGlobalLight(const glm::vec3& direction, const glm::vec3& diffuse, float intensity, float ambientIntensity);
void setGlobalSkybox(const model::SkyboxPointer& skybox);
const LightStage& getLightStage() { return _lightStage; } const LightStage& getLightStage() { return _lightStage; }
void setShadowMapEnabled(bool enable) { _shadowMapEnabled = enable; }; void setShadowMapEnabled(bool enable) { _shadowMapEnabled = enable; };

View file

@ -77,6 +77,10 @@ void SceneScripting::KeyLight::setAmbientIntensity(float intensity) {
_skyStage->setSunAmbientIntensity(intensity); _skyStage->setSunAmbientIntensity(intensity);
} }
void SceneScripting::KeyLight::setAmbientSphere(const gpu::SHPointer& sphere) {
_skyStage->setSunAmbientSphere(sphere);
}
glm::vec3 SceneScripting::KeyLight::getDirection() const { glm::vec3 SceneScripting::KeyLight::getDirection() const {
return _skyStage->getSunDirection(); return _skyStage->getSunDirection();
} }

View file

@ -81,6 +81,10 @@ namespace SceneScripting {
// setDirection is only effective if stage Sun model is disabled // setDirection is only effective if stage Sun model is disabled
void setDirection(const glm::vec3& direction); void setDirection(const glm::vec3& direction);
// AmbientTexture is unscriptable - it must be set through the zone entity
void setAmbientSphere(const gpu::SHPointer& sphere);
void resetAmbientSphere() { setAmbientSphere(nullptr); }
protected: protected:
model::SunSkyStagePointer _skyStage; model::SunSkyStagePointer _skyStage;
}; };