wire up zone to environment atmosphere rendering

This commit is contained in:
ZappoMan 2015-05-04 13:49:43 -07:00
parent 8c47736c3b
commit 4561c59203
9 changed files with 84 additions and 39 deletions

View file

@ -3113,9 +3113,9 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs
// compute starfield alpha based on distance from atmosphere
float alpha = 1.0f;
if (Menu::getInstance()->isOptionChecked(MenuOption::Atmosphere)) {
// TODO: handle this correctly for zones
const EnvironmentData& closestData = _environment.getClosestData(theCamera.getPosition());
float height = glm::distance(theCamera.getPosition(),
closestData.getAtmosphereCenter(theCamera.getPosition()));
float height = glm::distance(theCamera.getPosition(), closestData.getAtmosphereCenter());
if (height < closestData.getAtmosphereInnerRadius()) {
alpha = 0.0f;
@ -3126,6 +3126,7 @@ void Application::displaySide(Camera& theCamera, bool selfAvatarOnly, RenderArgs
}
// finally render the starfield
//qDebug() << "stars alpha:" << alpha;
_stars.render(theCamera.getFieldOfView(), theCamera.getAspectRatio(), theCamera.getNearClip(), alpha);
}

View file

@ -280,6 +280,9 @@ public:
virtual int getBoundaryLevelAdjust() const;
virtual PickRay computePickRay(float x, float y);
virtual const glm::vec3& getAvatarPosition() const { return _myAvatar->getPosition(); }
virtual void overrideEnvironmentData(const EnvironmentData& newData) { _environment.override(newData); }
virtual void endOverrideEnvironmentData() { _environment.endOverride(); }
NodeBounds& getNodeBoundsDisplay() { return _nodeBoundsDisplay; }

View file

@ -71,15 +71,46 @@ void Environment::resetToDefault() {
void Environment::renderAtmospheres(Camera& camera) {
// get the lock for the duration of the call
QMutexLocker locker(&_mutex);
foreach (const ServerData& serverData, _data) {
// TODO: do something about EnvironmentData
foreach (const EnvironmentData& environmentData, serverData) {
renderAtmosphere(camera, environmentData);
if (_environmentIsOverridden) {
renderAtmosphere(camera, _overrideData);
} else {
foreach (const ServerData& serverData, _data) {
// TODO: do something about EnvironmentData
foreach (const EnvironmentData& environmentData, serverData) {
renderAtmosphere(camera, environmentData);
}
}
}
}
EnvironmentData Environment::getClosestData(const glm::vec3& position) {
if (_environmentIsOverridden) {
return _overrideData;
}
// get the lock for the duration of the call
QMutexLocker locker(&_mutex);
EnvironmentData closest;
float closestDistance = FLT_MAX;
foreach (const ServerData& serverData, _data) {
foreach (const EnvironmentData& environmentData, serverData) {
float distance = glm::distance(position, environmentData.getAtmosphereCenter(position)) -
environmentData.getAtmosphereOuterRadius();
if (distance < closestDistance) {
closest = environmentData;
closestDistance = distance;
}
}
}
return closest;
}
// NOTE: Deprecated - I'm leaving this in for now, but it's not actually used. I made it private
// so that if anyone wants to start using this in the future they will consider how to make it
// work with new physics systems.
glm::vec3 Environment::getGravity (const glm::vec3& position) {
//
// 'Default' gravity pulls you downward in Y when you are near the X/Z plane
@ -115,25 +146,6 @@ glm::vec3 Environment::getGravity (const glm::vec3& position) {
return gravity;
}
const EnvironmentData Environment::getClosestData(const glm::vec3& position) {
// get the lock for the duration of the call
QMutexLocker locker(&_mutex);
EnvironmentData closest;
float closestDistance = FLT_MAX;
foreach (const ServerData& serverData, _data) {
foreach (const EnvironmentData& environmentData, serverData) {
float distance = glm::distance(position, environmentData.getAtmosphereCenter(position)) -
environmentData.getAtmosphereOuterRadius();
if (distance < closestDistance) {
closest = environmentData;
closestDistance = distance;
}
}
}
return closest;
}
bool Environment::findCapsulePenetration(const glm::vec3& start, const glm::vec3& end,
float radius, glm::vec3& penetration) {
// collide with the "floor"
@ -217,14 +229,14 @@ ProgramObject* Environment::createSkyProgram(const char* from, int* locations) {
}
void Environment::renderAtmosphere(Camera& camera, const EnvironmentData& data) {
glm::vec3 center = data.getAtmosphereCenter(camera.getPosition());
glm::vec3 center = data.getAtmosphereCenter();
glPushMatrix();
glTranslatef(center.x, center.y, center.z);
glm::vec3 relativeCameraPos = camera.getPosition() - center;
float height = glm::length(relativeCameraPos);
// use the appropriate shader depending on whether we're inside or outside
ProgramObject* program;
int* locations;

View file

@ -30,15 +30,19 @@ public:
void init();
void resetToDefault();
void renderAtmospheres(Camera& camera);
void override(const EnvironmentData& overrideData) { _overrideData = overrideData; _environmentIsOverridden = true; }
void endOverride() { _environmentIsOverridden = false; }
glm::vec3 getGravity (const glm::vec3& position);
const EnvironmentData getClosestData(const glm::vec3& position);
EnvironmentData getClosestData(const glm::vec3& position);
bool findCapsulePenetration(const glm::vec3& start, const glm::vec3& end, float radius, glm::vec3& penetration);
int parseData(const HifiSockAddr& senderSockAddr, const QByteArray& packet);
private:
glm::vec3 getGravity (const glm::vec3& position); // NOTE: Deprecated
bool findCapsulePenetration(const glm::vec3& start,
const glm::vec3& end, float radius, glm::vec3& penetration); // NOTE: Deprecated
ProgramObject* createSkyProgram(const char* from, int* locations);
@ -74,6 +78,8 @@ private:
typedef QHash<int, EnvironmentData> ServerData;
QHash<HifiSockAddr, ServerData> _data;
EnvironmentData _overrideData;
bool _environmentIsOverridden = false;
QMutex _mutex;
};

View file

@ -427,6 +427,8 @@ void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode,
_bestZone->getStageAltitude());
scene->setStageDayTime(_bestZone->getStageHour());
scene->setStageYearTime(_bestZone->getStageDay());
_viewState->overrideEnvironmentData(_bestZone->getEnvironmentData());
} else {
if (_hasPreviousZone) {
scene->setKeyLightColor(_previousKeyLightColor);
@ -440,6 +442,7 @@ void EntityTreeRenderer::render(RenderArgs::RenderMode renderMode,
scene->setStageYearTime(_previousStageDay);
_hasPreviousZone = false;
}
_viewState->endOverrideEnvironmentData();
}
// we must call endScene while we still have the tree locked so that no one deletes a model

View file

@ -66,6 +66,24 @@ ZoneEntityItem::ZoneEntityItem(const EntityItemID& entityItemID, const EntityIte
setProperties(properties);
}
EnvironmentData ZoneEntityItem::getEnvironmentData() const {
EnvironmentData result;
result.setAtmosphereCenter(_atmospherePropeties.getCenter());
result.setAtmosphereInnerRadius(_atmospherePropeties.getInnerRadius());
result.setAtmosphereOuterRadius(_atmospherePropeties.getOuterRadius());
result.setRayleighScattering(_atmospherePropeties.getRayleighScattering());
result.setMieScattering(_atmospherePropeties.getMieScattering());
result.setScatteringWavelengths(_atmospherePropeties.getScatteringWavelengths());
// defaults for now...
result.setSunLocation(glm::vec3(1000, 900, 1000));
result.setSunBrightness(20.0f);
return result;
}
EntityItemProperties ZoneEntityItem::getProperties() const {
EntityItemProperties properties = EntityItem::getProperties(); // get the properties from our base class
@ -123,9 +141,6 @@ bool ZoneEntityItem::setProperties(const EntityItemProperties& properties) {
setLastEdited(properties._lastEdited);
}
qDebug() << "ZoneEntityItem::setProperties()";
debugDump();
return somethingChanged;
}
@ -155,9 +170,6 @@ int ZoneEntityItem::readEntitySubclassDataFromBuffer(const unsigned char* data,
propertyFlags, overwriteLocalData);
qDebug() << "ZoneEntityItem::readEntitySubclassDataFromBuffer()";
debugDump();
return bytesRead;
}

View file

@ -12,6 +12,8 @@
#ifndef hifi_ZoneEntityItem_h
#define hifi_ZoneEntityItem_h
#include <EnvironmentData.h>
#include "AtmospherePropertyGroup.h"
#include "EntityItem.h"
@ -103,7 +105,8 @@ public:
void setSkyboxMode(SkyboxMode value) { _skyboxMode = value; }
SkyboxMode getSkyboxMode() const { return _skyboxMode; }
EnvironmentData getEnvironmentData() const;
virtual bool supportsDetailedRayIntersection() const { return true; }
virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,

View file

@ -18,6 +18,7 @@ class Transform;
class QThread;
class ViewFrustum;
class PickRay;
class EnvironmentData;
/// Interface provided by Application to other objects that need access to the current view state details
class AbstractViewStateInterface {
@ -32,6 +33,10 @@ public:
/// gets the current view frustum for rendering the view state
virtual ViewFrustum* getCurrentViewFrustum() = 0;
/// overrides environment data
virtual void overrideEnvironmentData(const EnvironmentData& newData) = 0;
virtual void endOverrideEnvironmentData() = 0;
/// gets the shadow view frustum for rendering the view state
virtual ViewFrustum* getShadowViewFrustum() = 0;

View file

@ -3,6 +3,6 @@ set(TARGET_NAME octree-tests)
setup_hifi_project(Script Network)
# link in the shared libraries
link_hifi_libraries(shared octree gpu model fbx networking entities avatars audio animation script-engine physics)
link_hifi_libraries(shared octree gpu model fbx networking environment entities avatars audio animation script-engine physics)
copy_dlls_beside_windows_executable()