mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-23 04:30:09 -05:00
Added an option to have the sun following the camera when using an ATM. Removed unused code. Added missing comments.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/*****************************************************************************************
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
@@ -22,6 +22,42 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
/***************************************************************************************
|
||||
* Modified part of the code (4D texture mechanism) from Eric Bruneton is used in the
|
||||
* following code.
|
||||
****************************************************************************************/
|
||||
|
||||
/**
|
||||
* Precomputed Atmospheric Scattering
|
||||
* Copyright (c) 2008 INRIA
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
*/
|
||||
|
||||
#include <modules/atmosphere/rendering/atmospheredeferredcaster.h>
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
@@ -58,8 +94,7 @@ namespace {
|
||||
namespace openspace {
|
||||
|
||||
AtmosphereDeferredcaster::AtmosphereDeferredcaster()
|
||||
: //_programObject(nullptr)
|
||||
_transmittanceProgramObject(nullptr)
|
||||
: _transmittanceProgramObject(nullptr)
|
||||
, _irradianceProgramObject(nullptr)
|
||||
, _irradianceSupTermsProgramObject(nullptr)
|
||||
, _inScatteringProgramObject(nullptr)
|
||||
@@ -95,6 +130,7 @@ AtmosphereDeferredcaster::AtmosphereDeferredcaster()
|
||||
, _atmosphereCalculated(false)
|
||||
, _atmosphereEnabled(false)
|
||||
, _ozoneEnabled(false)
|
||||
, _sunFollowingCameraEnabled(false)
|
||||
, _atmosphereRadius(0.f)
|
||||
, _atmospherePlanetRadius(0.f)
|
||||
, _planetAverageGroundReflectance(0.f)
|
||||
@@ -129,13 +165,7 @@ void AtmosphereDeferredcaster::initialize()
|
||||
|
||||
void AtmosphereDeferredcaster::deinitialize()
|
||||
{
|
||||
// TODO
|
||||
// Review if the programs should be part of the renderEngine.
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
// if (_programObject) {
|
||||
// renderEngine.removeRenderProgram(_programObject);
|
||||
// _programObject = nullptr;
|
||||
// }
|
||||
|
||||
if (_transmittanceProgramObject) {
|
||||
_transmittanceProgramObject = nullptr;
|
||||
@@ -218,71 +248,58 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData & renderData, const D
|
||||
program.setUniform("SAMPLES_NU", (int)_nu_samples);
|
||||
|
||||
program.setUniform("ModelTransformMatrix", _modelTransform);
|
||||
program.setUniform("dInverseModelTransformMatrix", glm::inverse(_modelTransform));
|
||||
program.setUniform("dSGCTEyeToOSWorldTransformMatrix", glm::inverse(renderData.camera.combinedViewMatrix()));
|
||||
|
||||
// Object Space
|
||||
//program.setUniform("inverseTransformMatrix", glm::inverse(_modelTransform));
|
||||
program.setUniform("dInverseTransformMatrix", glm::inverse(_modelTransform));
|
||||
|
||||
// Object Space
|
||||
glm::dmat4 inverseModelMatrix = glm::inverse(_modelTransform);
|
||||
program.setUniform("dInverseModelTransformMatrix", inverseModelMatrix);
|
||||
|
||||
// The following scale comes from PSC transformations.
|
||||
float fScaleFactor = renderData.camera.scaling().x * pow(10.0, renderData.camera.scaling().y);
|
||||
glm::dmat4 dfScaleCamTransf = glm::scale(glm::dvec3(fScaleFactor));
|
||||
program.setUniform("dInverseScaleTransformMatrix", glm::inverse(dfScaleCamTransf));
|
||||
|
||||
// Object Space to World Space (in meters)
|
||||
//glm::dmat4 dObj2World = glm::translate(data.position.dvec3()) * glm::dmat4(transform);
|
||||
//glm::dmat4 dWorld2Obj = glm::inverse(dObj2World);
|
||||
//program.setUniform("dObjToWorldTransform", dObj2World);
|
||||
//program.setUniform("dWorldToObjectTransform", dWorld2Obj);
|
||||
|
||||
|
||||
// World to Eye Space in OS
|
||||
//glm::dmat4 dWorld2Eye = dfScaleCamTransf * renderData.camera.viewRotationMatrix() *
|
||||
// glm::translate(-renderData.camera.positionVec3());
|
||||
//glm::dmat4 dEye2World = glm::inverse(dWorld2Eye);
|
||||
program.setUniform("dInverseCamRotTransform", glm::mat4_cast((glm::dquat)renderData.camera.rotationQuaternion()));
|
||||
//program.setUniform("dWorldToOsEyeTransform", dWorld2Eye);
|
||||
//program.setUniform("dOsEyeToWorldTransform", dEye2World);
|
||||
|
||||
|
||||
program.setUniform("dInverseSgctEyeToWorldTranform", glm::inverse(renderData.camera.combinedViewMatrix()));
|
||||
|
||||
// Eye Space in OS to Eye Space in SGCT
|
||||
glm::dmat4 dOsEye2SGCTEye = glm::dmat4(renderData.camera.viewMatrix());
|
||||
glm::dmat4 dSgctEye2OSEye = glm::inverse(dOsEye2SGCTEye);
|
||||
|
||||
//program.setUniform("dOsEyeToSGCTEyeTranform", dOsEye2SGCTEye);
|
||||
glm::dmat4 dSgctEye2OSEye = glm::inverse(dOsEye2SGCTEye);
|
||||
program.setUniform("dSgctEyeToOSEyeTranform", dSgctEye2OSEye);
|
||||
|
||||
// Eye Space in SGCT to Projection (Clip) Space in SGCT
|
||||
glm::dmat4 dSgctEye2Clip = glm::dmat4(renderData.camera.projectionMatrix());
|
||||
glm::dmat4 dInverseProjection = glm::inverse(dSgctEye2Clip);
|
||||
|
||||
//program.setUniform("dSgctEyeToClipTranform", dSgctEye2Clip);
|
||||
program.setUniform("dInverseSgctProjectionMatrix", dInverseProjection);
|
||||
//program.setUniform("dSgctProjectionMatrix", glm::dmat4(data.camera.projectionMatrix()));
|
||||
|
||||
|
||||
program.setUniform("dObjpos", glm::dvec4(renderData.position.dvec3(), 1.0));
|
||||
program.setUniform("dCampos", renderData.camera.positionVec3());
|
||||
//program.setUniform("dCamrot", glm::dmat3(data.camera.viewRotationMatrix()));
|
||||
// I know it is (0,0,0). It is here just for sake of sanity. :-p
|
||||
|
||||
double lt;
|
||||
glm::dvec3 sunPosWorld = SpiceManager::ref().targetPosition("SUN", "SUN", "GALACTIC", {}, _time, lt);
|
||||
glm::dvec4 sunPosObj = glm::dvec4(0.0);
|
||||
|
||||
if (_renderableClass == RenderablePlanet) {
|
||||
sunPosObj = glm::inverse(_modelTransform) *
|
||||
glm::dvec4(sunPosWorld - renderData.position.dvec3(), 1.0);
|
||||
// Sun following camera position
|
||||
if (_sunFollowingCameraEnabled) {
|
||||
sunPosObj = inverseModelMatrix * glm::dvec4(renderData.camera.positionVec3(), 1.0);
|
||||
}
|
||||
else if (_renderableClass == RenderableGlobe) {
|
||||
sunPosObj = glm::inverse(_modelTransform) *
|
||||
glm::dvec4(sunPosWorld - renderData.modelTransform.translation, 1.0);
|
||||
}
|
||||
|
||||
program.setUniform("ellipsoidRadii", _ellipsoidRadii);
|
||||
|
||||
//program.setUniform("sunPositionObj", sunPosObj);
|
||||
else {
|
||||
if (_renderableClass == RenderablePlanet) {
|
||||
sunPosObj = inverseModelMatrix *
|
||||
glm::dvec4(sunPosWorld - renderData.position.dvec3(), 1.0);
|
||||
}
|
||||
else if (_renderableClass == RenderableGlobe) {
|
||||
sunPosObj = inverseModelMatrix *
|
||||
glm::dvec4(sunPosWorld - renderData.modelTransform.translation, 1.0);
|
||||
}
|
||||
}
|
||||
|
||||
// Sun Position in Object Space
|
||||
program.setUniform("sunDirectionObj", glm::normalize(glm::dvec3(sunPosObj)));
|
||||
//program.setUniform("_performShading", _performShading);
|
||||
|
||||
program.setUniform("ellipsoidRadii", _ellipsoidRadii);
|
||||
|
||||
_transmittanceTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _transmittanceTableTexture);
|
||||
@@ -521,6 +538,10 @@ void AtmosphereDeferredcaster::setRenderableClass(const AtmosphereDeferredcaster
|
||||
_renderableClass = rc;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::enableSunFollowing(const bool enable) {
|
||||
_sunFollowingCameraEnabled = enable;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setPrecalculationTextureScale(const float _preCalculatedTexturesScale) {
|
||||
_calculationTextureScale = _preCalculatedTexturesScale;
|
||||
_transmittance_table_width *= static_cast<unsigned int>(_calculationTextureScale);
|
||||
@@ -533,7 +554,6 @@ void AtmosphereDeferredcaster::setPrecalculationTextureScale(const float _preCal
|
||||
_mu_samples *= static_cast<unsigned int>(_calculationTextureScale);
|
||||
_mu_s_samples *= static_cast<unsigned int>(_calculationTextureScale);
|
||||
_nu_samples *= static_cast<unsigned int>(_calculationTextureScale);
|
||||
//preCalculateAtmosphereParam();
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::enablePrecalculationTexturesSaving() {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*****************************************************************************************
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
@@ -54,24 +54,6 @@ public:
|
||||
RenderableGlobe = 2
|
||||
};
|
||||
|
||||
public:
|
||||
// See: Precomputed Atmospheric Scattering from Bruneton et al.
|
||||
// for explanation of the following parameters.
|
||||
|
||||
/*const unsigned int TRANSMITTANCE_TABLE_WIDTH = 256;
|
||||
const unsigned int TRANSMITTANCE_TABLE_HEIGHT = 64;
|
||||
|
||||
const unsigned int IRRADIANCE_TABLE_WIDTH = 64;
|
||||
const unsigned int IRRADIANCE_TABLE_HEIGHT = 16;
|
||||
|
||||
const unsigned int DELTA_E_TABLE_WIDTH = 64;
|
||||
const unsigned int DELTA_E_TABLE_HEIGHT = 16;
|
||||
|
||||
const unsigned int R_SAMPLES = 32;
|
||||
const unsigned int MU_SAMPLES = 128;
|
||||
const unsigned int MU_S_SAMPLES = 32;
|
||||
const unsigned int NU_SAMPLES = 8;*/
|
||||
|
||||
public:
|
||||
AtmosphereDeferredcaster();
|
||||
virtual ~AtmosphereDeferredcaster();
|
||||
@@ -110,6 +92,7 @@ public:
|
||||
void setMieExtinctionCoefficients(const glm::vec3 & mieExtCoeff);
|
||||
void setEllipsoidRadii(const glm::dvec3 & radii);
|
||||
void setRenderableClass(const AtmosphereDeferredcaster::AtmospherRenderableClass rc);
|
||||
void enableSunFollowing(const bool enable);
|
||||
|
||||
void setPrecalculationTextureScale(const float _preCalculatedTexturesScale);
|
||||
void enablePrecalculationTexturesSaving();
|
||||
@@ -167,6 +150,7 @@ private:
|
||||
bool _atmosphereCalculated;
|
||||
bool _atmosphereEnabled;
|
||||
bool _ozoneEnabled;
|
||||
bool _sunFollowingCameraEnabled;
|
||||
float _atmosphereRadius;
|
||||
float _atmospherePlanetRadius;
|
||||
float _planetAverageGroundReflectance;
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
|
||||
#include <modules/atmosphere/rendering/renderableatmosphere.h>
|
||||
|
||||
#include <openspace/documentation/documentation.h>
|
||||
@@ -95,23 +96,14 @@ namespace openspace {
|
||||
return {
|
||||
"RenderableAtmosphere",
|
||||
"atmosphere_renderable_atmosphere",
|
||||
{
|
||||
/*
|
||||
{ /*
|
||||
{
|
||||
KeyGeometry,
|
||||
new ReferencingVerifier("space_geometry_planet"),
|
||||
"Specifies the planet geometry that is used for this RenderableAtmosphere.",
|
||||
keyAtmosphereRadius,
|
||||
new ReferencingVerifier("atmosphere"),
|
||||
"Specifies the atmosphere's height in this RenderableAtmosphere.",
|
||||
Optional::No
|
||||
},
|
||||
|
||||
{
|
||||
KeyRadius,
|
||||
new DoubleVerifier,
|
||||
"Specifies the radius of the planet. If this value is not specified, it "
|
||||
"will try to query the SPICE library for radius values.",
|
||||
Optional::Yes
|
||||
},
|
||||
|
||||
{
|
||||
KeyShading,
|
||||
new BoolVerifier,
|
||||
@@ -127,10 +119,6 @@ namespace openspace {
|
||||
|
||||
RenderableAtmosphere::RenderableAtmosphere(const ghoul::Dictionary& dictionary)
|
||||
: Renderable(dictionary)
|
||||
// TODO: Enable the shading program later to test spherical atmosphere (JCC)
|
||||
//, _programObject(nullptr)
|
||||
// TODO: Enable the geometry later to test spherical atmosphere (JCC)
|
||||
//, _geometry(nullptr)
|
||||
, _atmosphereHeightP("atmmosphereHeight", "Atmosphere Height (KM)", 60.0f, 0.1f, 99.0f)
|
||||
, _groundAverageReflectanceP("averageGroundReflectance", "Average Ground Reflectance (%)", 0.1f, 0.0f, 1.0f)
|
||||
, _rayleighHeightScaleP("rayleighHeightScale", "Rayleigh Height Scale (KM)", 8.0f, 0.1f, 20.0f)
|
||||
@@ -152,8 +140,10 @@ namespace openspace {
|
||||
, _sunIntensityP("sunIntensity", "Sun Intensity", 50.0f, 0.1f, 1000.0f)
|
||||
, _hdrExpositionP("hdrExposition", "HDR", 0.4f, 0.01f, 5.0f)
|
||||
, _gammaConstantP("gamma", "Gamma Correction", 1.8f, 0.1f, 3.0f)
|
||||
, _sunFollowingCameraEnabledP("sunFollowingCamera", "Enable Sun On Camera Position", false)
|
||||
, _atmosphereEnabled(false)
|
||||
, _ozoneLayerEnabled(false)
|
||||
, _sunFollowingCameraEnabled(false)
|
||||
, _atmosphereRadius(0.f)
|
||||
, _atmospherePlanetRadius(0.f)
|
||||
, _planetAverageGroundReflectance(0.f)
|
||||
@@ -171,7 +161,6 @@ namespace openspace {
|
||||
, _mieScatteringCoeff(glm::vec3(0.f))
|
||||
, _saveCalculationsToTexture(false)
|
||||
, _preCalculatedTexturesScale(1.0)
|
||||
//, _planetRadius(0.f)
|
||||
, _shadowEnabled(false)
|
||||
, _time(0.f)
|
||||
{
|
||||
@@ -187,32 +176,6 @@ namespace openspace {
|
||||
);
|
||||
|
||||
const std::string name = dictionary.value<std::string>(SceneGraphNode::KeyName);
|
||||
|
||||
// TODO: Enable the geometry later to test spherical atmosphere (JCC)
|
||||
/*
|
||||
ghoul::Dictionary geomDict = dictionary.value<ghoul::Dictionary>(KeyGeometry);
|
||||
|
||||
if (dictionary.hasKey(KeyRadius)) {
|
||||
// If the user specified a radius, we want to use this
|
||||
_planetRadius = static_cast<float>(dictionary.value<double>(KeyRadius));
|
||||
}
|
||||
else if (SpiceManager::ref().hasValue(name, "RADII")) {
|
||||
// If the user didn't specfify a radius, but Spice has a radius, we can use this
|
||||
glm::dvec3 radius;
|
||||
SpiceManager::ref().getValue(name, "RADII", radius);
|
||||
radius *= 1000.0; // Spice gives radii in KM.
|
||||
std::swap(radius[1], radius[2]); // z is equivalent to y in our coordinate system
|
||||
geomDict.setValue(KeyRadius, radius);
|
||||
|
||||
_planetRadius = static_cast<float>((radius.x + radius.y + radius.z) / 3.0);
|
||||
}
|
||||
else {
|
||||
LERRORC("RenderableAtmosphere", "Missing radius specification");
|
||||
}
|
||||
|
||||
_geometry = planetgeometry::PlanetGeometry::createFromDictionary(geomDict);
|
||||
addPropertySubOwner(_geometry.get());
|
||||
*/
|
||||
|
||||
//================================================================
|
||||
//======== Reads Shadow (Eclipses) Entries in mod file ===========
|
||||
@@ -528,6 +491,10 @@ namespace openspace {
|
||||
_gammaConstantP.set(_gammaConstant);
|
||||
_gammaConstantP.onChange(std::bind(&RenderableAtmosphere::updateAtmosphereParameters, this));
|
||||
addProperty(_gammaConstantP);
|
||||
|
||||
_sunFollowingCameraEnabledP.set(_sunFollowingCameraEnabled);
|
||||
_sunFollowingCameraEnabledP.onChange(std::bind(&RenderableAtmosphere::updateAtmosphereParameters, this));
|
||||
addProperty(_sunFollowingCameraEnabledP);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -535,27 +502,6 @@ namespace openspace {
|
||||
bool RenderableAtmosphere::initialize() {
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
|
||||
// TODO: Enable the shading program later to test spherical atmosphere (JCC)
|
||||
/*
|
||||
if (_programObject == nullptr ) {
|
||||
// TODO: Change for the right shading program (JCC)
|
||||
_programObject = renderEngine.buildRenderProgram(
|
||||
"shadowNightProgram",
|
||||
"${MODULE_ATMOSPHERE}/shaders/shadow_nighttexture_vs.glsl",
|
||||
"${MODULE_ATMOSPHERE}/shaders/shadow_nighttexture_fs.glsl");
|
||||
}
|
||||
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
|
||||
_programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
_programObject->setIgnoreUniformLocationError(IgnoreError::Yes);
|
||||
|
||||
// Deactivate any previously activated shader program.
|
||||
_programObject->deactivate();
|
||||
*/
|
||||
|
||||
// TODO: Enable the geometry later to test spherical atmosphere (JCC)
|
||||
//_geometry->initialize(this);
|
||||
|
||||
if (_atmosphereEnabled) {
|
||||
_deferredcaster = std::make_unique<AtmosphereDeferredcaster>();
|
||||
if (_deferredcaster) {
|
||||
@@ -578,6 +524,7 @@ namespace openspace {
|
||||
// TODO: Fix the ellipsoid nature of the renderable globe (JCC)
|
||||
//_deferredcaster->setEllipsoidRadii(_ellipsoid.radii());
|
||||
_deferredcaster->setRenderableClass(_atmosphereType);
|
||||
_deferredcaster->enableSunFollowing(_sunFollowingCameraEnabled);
|
||||
|
||||
_deferredcaster->setPrecalculationTextureScale(_preCalculatedTexturesScale);
|
||||
if (_saveCalculationsToTexture)
|
||||
@@ -604,22 +551,6 @@ namespace openspace {
|
||||
}
|
||||
|
||||
bool RenderableAtmosphere::deinitialize() {
|
||||
// TODO: Enable the geometry later to test spherical atmosphere (JCC)
|
||||
/*
|
||||
if (_geometry) {
|
||||
_geometry->deinitialize();
|
||||
}
|
||||
_geometry = nullptr;
|
||||
*/
|
||||
|
||||
RenderEngine& renderEngine = OsEng.renderEngine();
|
||||
// TODO: Enable the shading program later to test spherical atmosphere (JCC)
|
||||
/*
|
||||
if (_programObject) {
|
||||
renderEngine.removeRenderProgram(_programObject);
|
||||
}
|
||||
_programObject = nullptr;
|
||||
*/
|
||||
|
||||
if (_deferredcaster) {
|
||||
OsEng.renderEngine().deferredcasterManager().detachDeferredcaster(*_deferredcaster.get());
|
||||
@@ -631,10 +562,6 @@ namespace openspace {
|
||||
|
||||
bool RenderableAtmosphere::isReady() const {
|
||||
bool ready = true;
|
||||
// TODO: Enable the shading program later to test spherical atmosphere (JCC)
|
||||
//ready &= (_programObject != nullptr);
|
||||
// TODO: Enable the geometry later to test spherical atmosphere (JCC)
|
||||
//ready &= (_geometry != nullptr);
|
||||
ready &= (_deferredcaster != nullptr);
|
||||
return ready;
|
||||
}
|
||||
@@ -650,111 +577,6 @@ namespace openspace {
|
||||
|
||||
void RenderableAtmosphere::render(const RenderData& data, RendererTasks& renderTask) {
|
||||
|
||||
// TODO: Enable the shading program later to test spherical atmosphere (JCC)
|
||||
/*
|
||||
_programObject->activate();
|
||||
|
||||
glm::dmat4 modelTransform = glm::dmat4(1.0);
|
||||
computeModelTransformMatrix(data.modelTransform, &modelTransform);
|
||||
|
||||
glm::dmat4 modelViewTransform = data.camera.combinedViewMatrix() * modelTransform;
|
||||
|
||||
_programObject->setUniform("transparency", _alpha);
|
||||
_programObject->setUniform("modelViewTransform", modelViewTransform);
|
||||
_programObject->setUniform("modelViewProjectionTransform",
|
||||
data.camera.sgctInternal.projectionMatrix() * glm::mat4(modelViewTransform)
|
||||
);
|
||||
_programObject->setUniform("ModelTransform", glm::mat4(modelTransform));
|
||||
|
||||
setPscUniforms(*_programObject.get(), data.camera, data.position);
|
||||
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
//=============================================================================
|
||||
//============= Eclipse Shadow Calculations and Uniforms Loading ==============
|
||||
//=============================================================================
|
||||
// TODO: Move Calculations to VIEW SPACE (let's avoid precision problems...)
|
||||
double lt;
|
||||
if (!_shadowConfArray.empty()) {
|
||||
std::vector<ShadowRenderingStruct> shadowDataArray;
|
||||
shadowDataArray.reserve(_shadowConfArray.size());
|
||||
|
||||
for (const auto & shadowConf : _shadowConfArray) {
|
||||
// TO REMEMBER: all distances and lengths in world coordinates are in meters!!! We need to move this to view space...
|
||||
// Getting source and caster:
|
||||
glm::dvec3 sourcePos = SpiceManager::ref().targetPosition(shadowConf.source.first, "SUN", "GALACTIC", {}, _time, lt);
|
||||
sourcePos *= 1000.0; // converting to meters
|
||||
glm::dvec3 casterPos = SpiceManager::ref().targetPosition(shadowConf.caster.first, "SUN", "GALACTIC", {}, _time, lt);
|
||||
casterPos *= 1000.0; // converting to meters
|
||||
psc caster_pos = PowerScaledCoordinate::CreatePowerScaledCoordinate(casterPos.x, casterPos.y, casterPos.z);
|
||||
|
||||
// First we determine if the caster is shadowing the current planet (all calculations in World Coordinates):
|
||||
glm::vec3 planetCasterVec = (caster_pos - data.position).vec3();
|
||||
glm::vec3 sourceCasterVec = glm::vec3(casterPos - sourcePos);
|
||||
float sc_length = glm::length(sourceCasterVec);
|
||||
glm::vec3 planetCaster_proj = (glm::dot(planetCasterVec, sourceCasterVec) / (sc_length*sc_length)) * sourceCasterVec;
|
||||
float d_test = glm::length(planetCasterVec - planetCaster_proj);
|
||||
float xp_test = shadowConf.caster.second * sc_length / (shadowConf.source.second + shadowConf.caster.second);
|
||||
float rp_test = shadowConf.caster.second * (glm::length(planetCaster_proj) + xp_test) / xp_test;
|
||||
|
||||
double casterDistSun = glm::length(casterPos);
|
||||
float planetDistSun = glm::length(data.position.vec3());
|
||||
|
||||
ShadowRenderingStruct shadowData;
|
||||
shadowData.isShadowing = false;
|
||||
|
||||
if (((d_test - rp_test) < _planetRadius) &&
|
||||
(casterDistSun < planetDistSun)) {
|
||||
// The current caster is shadowing the current planet
|
||||
shadowData.isShadowing = true;
|
||||
shadowData.rs = shadowConf.source.second;
|
||||
shadowData.rc = shadowConf.caster.second;
|
||||
shadowData.sourceCasterVec = sourceCasterVec;
|
||||
shadowData.xp = xp_test;
|
||||
shadowData.xu = shadowData.rc * sc_length / (shadowData.rs - shadowData.rc);
|
||||
shadowData.casterPositionVec = glm::vec3(casterPos);
|
||||
}
|
||||
shadowDataArray.push_back(shadowData);
|
||||
}
|
||||
|
||||
const std::string uniformVarName("shadowDataArray[");
|
||||
unsigned int counter = 0;
|
||||
for (const auto & sd : shadowDataArray) {
|
||||
std::stringstream ss;
|
||||
ss << uniformVarName << counter << "].isShadowing";
|
||||
_programObject->setUniform(ss.str(), sd.isShadowing);
|
||||
if (sd.isShadowing) {
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].xp";
|
||||
_programObject->setUniform(ss.str(), sd.xp);
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].xu";
|
||||
_programObject->setUniform(ss.str(), sd.xu);
|
||||
//ss.str(std::string());
|
||||
//ss << uniformVarName << counter << "].rs";
|
||||
//_programObject->setUniform(ss.str(), sd.rs);
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].rc";
|
||||
_programObject->setUniform(ss.str(), sd.rc);
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].sourceCasterVec";
|
||||
_programObject->setUniform(ss.str(), sd.sourceCasterVec);
|
||||
ss.str(std::string());
|
||||
ss << uniformVarName << counter << "].casterPositionVec";
|
||||
_programObject->setUniform(ss.str(), sd.casterPositionVec);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
// render
|
||||
_geometry->render();
|
||||
|
||||
// disable shader
|
||||
_programObject->deactivate();
|
||||
*/
|
||||
|
||||
if (_atmosphereEnabled) {
|
||||
DeferredcasterTask task{ _deferredcaster.get(), data };
|
||||
renderTask.deferredcasterTasks.push_back(task);
|
||||
@@ -766,11 +588,6 @@ namespace openspace {
|
||||
_stateMatrix = data.modelTransform.rotation;
|
||||
_time = data.time.j2000Seconds();
|
||||
|
||||
// TODO: Enable the shading program later to test spherical atmosphere (JCC)
|
||||
/*
|
||||
if (_programObject && _programObject->isDirty())
|
||||
_programObject->rebuildFromFile();
|
||||
*/
|
||||
if (_deferredcaster) {
|
||||
_deferredcaster->setTime(data.time.j2000Seconds());
|
||||
glm::dmat4 modelTransform;
|
||||
@@ -794,7 +611,8 @@ namespace openspace {
|
||||
if (_sunRadianceIntensity != _sunIntensityP ||
|
||||
_hdrConstant != _hdrExpositionP ||
|
||||
_exposureBackgroundConstant != OsEng.renderEngine().renderer()->hdrBackground() ||
|
||||
_gammaConstant != _gammaConstantP)
|
||||
_gammaConstant != _gammaConstantP ||
|
||||
_sunFollowingCameraEnabled != _sunFollowingCameraEnabledP)
|
||||
executeComputation = false;
|
||||
|
||||
_atmosphereRadius = _atmospherePlanetRadius + _atmosphereHeightP;
|
||||
@@ -802,8 +620,8 @@ namespace openspace {
|
||||
_rayleighHeightScale = _rayleighHeightScaleP;
|
||||
_rayleighScatteringCoeff = glm::vec3(_rayleighScatteringCoeffXP * 0.001f, _rayleighScatteringCoeffYP * 0.001f,
|
||||
_rayleighScatteringCoeffZP * 0.001f);
|
||||
_ozoneLayerEnabled = _ozoneEnabledP.value();
|
||||
_ozoneHeightScale = _ozoneHeightScaleP.value();
|
||||
_ozoneLayerEnabled = _ozoneEnabledP;
|
||||
_ozoneHeightScale = _ozoneHeightScaleP;
|
||||
_ozoneExtinctionCoeff = glm::vec3(_ozoneCoeffXP.value() * 0.00001f,
|
||||
_ozoneCoeffYP.value() * 0.00001f,
|
||||
_ozoneCoeffZP.value() * 0.00001f);
|
||||
@@ -815,7 +633,9 @@ namespace openspace {
|
||||
_sunRadianceIntensity = _sunIntensityP;
|
||||
_hdrConstant = _hdrExpositionP;
|
||||
_exposureBackgroundConstant = OsEng.renderEngine().renderer()->hdrBackground();
|
||||
_gammaConstant = _gammaConstantP.value();
|
||||
_gammaConstant = _gammaConstantP;
|
||||
_sunFollowingCameraEnabled = _sunFollowingCameraEnabledP;
|
||||
|
||||
|
||||
if (_deferredcaster) {
|
||||
_deferredcaster->setAtmosphereRadius(_atmosphereRadius);
|
||||
@@ -835,6 +655,7 @@ namespace openspace {
|
||||
_deferredcaster->setMieScatteringCoefficients(_mieScatteringCoeff);
|
||||
_deferredcaster->setMieExtinctionCoefficients(_mieExtinctionCoeff);
|
||||
_deferredcaster->setRenderableClass(_atmosphereType);
|
||||
_deferredcaster->enableSunFollowing(_sunFollowingCameraEnabled);
|
||||
|
||||
if (executeComputation)
|
||||
_deferredcaster->preCalculateAtmosphereParam();
|
||||
|
||||
@@ -92,11 +92,6 @@ private:
|
||||
void updateAtmosphereParameters();
|
||||
|
||||
private:
|
||||
// TODO: Enable the shading program later to test spherical atmosphere (JCC)
|
||||
//std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
|
||||
// TODO: Enable the geometry later to test spherical atmosphere (JCC)
|
||||
//std::unique_ptr<planetgeometry::PlanetGeometry> _geometry;
|
||||
|
||||
AtmosphereDeferredcaster::AtmospherRenderableClass _atmosphereType;
|
||||
|
||||
@@ -120,9 +115,11 @@ private:
|
||||
properties::FloatProperty _sunIntensityP;
|
||||
properties::FloatProperty _hdrExpositionP;
|
||||
properties::FloatProperty _gammaConstantP;
|
||||
properties::BoolProperty _sunFollowingCameraEnabledP;
|
||||
|
||||
bool _atmosphereEnabled;
|
||||
bool _ozoneLayerEnabled;
|
||||
bool _sunFollowingCameraEnabled;
|
||||
float _atmosphereRadius;
|
||||
float _atmospherePlanetRadius;
|
||||
float _planetAverageGroundReflectance;
|
||||
@@ -146,8 +143,6 @@ private:
|
||||
|
||||
std::unique_ptr<AtmosphereDeferredcaster> _deferredcaster;
|
||||
|
||||
//float _alpha;
|
||||
//float _planetRadius;
|
||||
bool _shadowEnabled;
|
||||
double _time;
|
||||
|
||||
|
||||
@@ -22,6 +22,42 @@
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
|
||||
/*****************************************************************************************
|
||||
* Modified parts of the code (4D texture mechanism, analytical transmittance etc) *
|
||||
* from Eric Bruneton is used in the following code. *
|
||||
****************************************************************************************/
|
||||
|
||||
/**
|
||||
* Precomputed Atmospheric Scattering
|
||||
* Copyright (c) 2008 INRIA
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
// Atmosphere Rendering Parameters
|
||||
uniform float Rg;
|
||||
uniform float Rt;
|
||||
|
||||
@@ -21,10 +21,43 @@
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
#version __CONTEXT__
|
||||
|
||||
const int RenderablePlanet = 1;
|
||||
const int RenderableGlobe = 2;
|
||||
/*****************************************************************************************
|
||||
* Modified parts of the code (4D texture mechanism) from Eric Bruneton is used in the *
|
||||
* following code. *
|
||||
****************************************************************************************/
|
||||
|
||||
/**
|
||||
* Precomputed Atmospheric Scattering
|
||||
* Copyright (c) 2008 INRIA
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
#define EPSILON 0.0001f
|
||||
#include "floatoperations.glsl"
|
||||
@@ -32,9 +65,16 @@ const int RenderableGlobe = 2;
|
||||
#include "hdr.glsl"
|
||||
#include "atmosphere_common.glsl"
|
||||
|
||||
const int RenderablePlanet = 1;
|
||||
const int RenderableGlobe = 2;
|
||||
|
||||
out vec4 renderTarget;
|
||||
in vec3 interpolatedNDCPos;
|
||||
|
||||
// Atmosphere applied over a RenderablePlanet or
|
||||
// a RenderableGlobe
|
||||
uniform int RenderableClass;
|
||||
uniform int nAaSamples;
|
||||
|
||||
// Background exposure hack
|
||||
uniform float backgroundExposure;
|
||||
@@ -46,112 +86,28 @@ uniform sampler2DMS mainNormalTexture;
|
||||
uniform sampler2DMS mainColorTexture;
|
||||
uniform sampler2DMS otherDataTexture;
|
||||
|
||||
uniform int nAaSamples;
|
||||
|
||||
//layout(location = 0) out vec4 renderTarget;
|
||||
out vec4 renderTarget;
|
||||
|
||||
in vec3 interpolatedNDCPos;
|
||||
|
||||
// Model Transform Matrix Used for Globe Rendering
|
||||
uniform dmat4 dInverseTransformMatrix;
|
||||
uniform dmat4 dInverseSgctEyeToWorldTranform; // SGCT Eye to OS World
|
||||
uniform dmat4 dSgctEyeToOSEyeTranform; // SGCT Eye to OS Eye *
|
||||
uniform dmat4 dInverseSgctProjectionMatrix; // Clip to SGCT Eye *
|
||||
uniform dmat4 dInverseCamRotTransform;
|
||||
uniform dmat4 dInverseModelTransformMatrix;
|
||||
uniform dmat4 dSGCTEyeToOSWorldTransformMatrix;
|
||||
//uniform dmat4 dSGCTEyeToOSWorldTransformMatrix;
|
||||
|
||||
// Double Precision Versions:
|
||||
uniform dvec4 dObjpos;
|
||||
uniform dvec3 dCampos;
|
||||
|
||||
uniform dvec3 sunDirectionObj;
|
||||
|
||||
uniform dvec3 ellipsoidRadii;
|
||||
|
||||
/*******************************************************************************
|
||||
****** ALL CALCULATIONS FOR ATMOSPHERE ARE KM AND IN OBJECT SPACE SYSTEM ******
|
||||
*******************************************************************************/
|
||||
|
||||
/* Calculates the intersection of the view ray direction with the atmosphere and
|
||||
* returns the first intersection (0.0 when inside atmosphere): offset
|
||||
* and the second intersection: maxLength
|
||||
*/
|
||||
|
||||
struct dRay {
|
||||
dvec4 origin;
|
||||
dvec4 direction;
|
||||
};
|
||||
|
||||
struct Ellipsoid {
|
||||
dvec4 center;
|
||||
dvec3 size;
|
||||
};
|
||||
|
||||
bool dIntersectEllipsoid(const dRay ray, const Ellipsoid ellipsoid, out double offset, out double maxLength) {
|
||||
dvec4 O_C = ray.origin - ellipsoid.center;
|
||||
dvec4 dir = normalize(ray.direction);
|
||||
|
||||
offset = 0.0f;
|
||||
maxLength = 0.0f;
|
||||
|
||||
double a =
|
||||
((dir.x*dir.x)/(ellipsoid.size.x*ellipsoid.size.x))
|
||||
+ ((dir.y*dir.y)/(ellipsoid.size.y*ellipsoid.size.y))
|
||||
+ ((dir.z*dir.z)/(ellipsoid.size.z*ellipsoid.size.z));
|
||||
double b =
|
||||
((2.f*O_C.x*dir.x)/(ellipsoid.size.x*ellipsoid.size.x))
|
||||
+ ((2.f*O_C.y*dir.y)/(ellipsoid.size.y*ellipsoid.size.y))
|
||||
+ ((2.f*O_C.z*dir.z)/(ellipsoid.size.z*ellipsoid.size.z));
|
||||
double c =
|
||||
((O_C.x*O_C.x)/(ellipsoid.size.x*ellipsoid.size.x))
|
||||
+ ((O_C.y*O_C.y)/(ellipsoid.size.y*ellipsoid.size.y))
|
||||
+ ((O_C.z*O_C.z)/(ellipsoid.size.z*ellipsoid.size.z))
|
||||
- 1.f;
|
||||
|
||||
double d = ((b * b)-(4.0 * a * c));
|
||||
if ( d < 0.f || a == 0.f || b == 0.f || c == 0.f )
|
||||
return false;
|
||||
|
||||
d = sqrt(d);
|
||||
|
||||
double t1 = (-b+d) / (2.0 * a);
|
||||
double t2 = (-b-d) / (2.0 * a);
|
||||
|
||||
if ( t1 <= EPSILON && t2 <= EPSILON )
|
||||
return false; // both intersections are behind the ray origin
|
||||
|
||||
// If only one intersection (t>0) then we are inside the ellipsoid and the intersection is at the back of the ellipsoid
|
||||
bool back = (t1 <= EPSILON || t2 <= EPSILON);
|
||||
double t = 0.0;
|
||||
if ( t1 <= EPSILON ) {
|
||||
t = t2;
|
||||
} else {
|
||||
if( t2 <= EPSILON )
|
||||
t = t1;
|
||||
else
|
||||
t = (t1 < t2) ? t1 : t2;
|
||||
}
|
||||
|
||||
if ( t<EPSILON )
|
||||
return false; // Too close to intersection
|
||||
|
||||
offset = t;
|
||||
// dvec4 intersection = ray.origin + t * dir;
|
||||
// dvec4 normal = intersection - ellipsoid.center;
|
||||
// normal.x = 2.0 * normal.x / (ellipsoid.size.x * ellipsoid.size.x);
|
||||
// normal.y = 2.0 * normal.y / (ellipsoid.size.y * ellipsoid.size.y);
|
||||
// normal.z = 2.0 * normal.z / (ellipsoid.size.z * ellipsoid.size.z);
|
||||
|
||||
// normal.w = 0.0;
|
||||
// normal *= (back) ? -1.0 : 1.0;
|
||||
// normal = normalize(normal);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/* Function to calculate the initial intersection of the eye (camera) ray
|
||||
* with the atmosphere.
|
||||
* In (all parameters in the same coordinate system and same units):
|
||||
@@ -231,10 +187,7 @@ void dCalculateRayRenderableGlobe(out dRay ray, out dvec4 planetPositionObjectCo
|
||||
// Using the interpolated coords:
|
||||
// Assuming Red Book is right: z_ndc e [0, 1] and not [-1, 1]
|
||||
dvec4 clipCoords = dvec4(interpolatedNDCPos, 1.0) / gl_FragCoord.w;
|
||||
// This next line is needed because OS or SGCT is not inverting Y axis from
|
||||
// window space.
|
||||
//clipCoords.y = (-interpolatedNDCPos.y) / gl_FragCoord.w;
|
||||
|
||||
|
||||
// Clip to SGCT Eye
|
||||
dvec4 sgctEyeCoords = dInverseSgctProjectionMatrix * clipCoords;
|
||||
//sgctEyeCoords /= sgctEyeCoords.w;
|
||||
@@ -248,15 +201,15 @@ void dCalculateRayRenderableGlobe(out dRay ray, out dvec4 planetPositionObjectCo
|
||||
dvec4 worldCoords = dvec4(dvec3(tmpRInv) + dCampos, 1.0);
|
||||
|
||||
// World to Object
|
||||
dvec4 objectCoords = dInverseTransformMatrix * worldCoords;
|
||||
dvec4 objectCoords = dInverseModelTransformMatrix * worldCoords;
|
||||
|
||||
// Planet Position in Object Space
|
||||
// JCC: Applying the inverse of the model transformation on the object postion in World
|
||||
// space results in imprecision.
|
||||
planetPositionObjectCoords = dvec4(0.0,0.0,0.0,1.0);//dInverseTransformMatrix * dvec4(dObjpos.xyz, 1.0);
|
||||
planetPositionObjectCoords = dvec4(0.0,0.0,0.0,1.0);//dInverseModelTransformMatrix * dvec4(dObjpos.xyz, 1.0);
|
||||
|
||||
// Camera Position in Object Space
|
||||
cameraPositionInObject = dInverseTransformMatrix * dvec4(dCampos, 1.0);
|
||||
cameraPositionInObject = dInverseModelTransformMatrix * dvec4(dCampos, 1.0);
|
||||
|
||||
// ============================
|
||||
// ====== Building Ray ========
|
||||
@@ -284,9 +237,6 @@ void dCalculateRayRenderablePlanet(out dRay ray, out dvec4 planetPositionObjectC
|
||||
// Using the interpolated coords:
|
||||
// Assuming Red Book is right: z_ndc e [0, 1] and not [-1, 1]
|
||||
dvec4 clipCoords = dvec4(interpolatedNDCPos, 1.0) / gl_FragCoord.w;
|
||||
// This next line is needed because OS or SGCT is not inverting Y axis from
|
||||
// window space.
|
||||
//clipCoords.y = (-interpolatedNDCPos.y) / gl_FragCoord.w;
|
||||
|
||||
// Clip to SGCT Eye
|
||||
dvec4 sgctEyeCoords = dInverseSgctProjectionMatrix * clipCoords;
|
||||
@@ -294,13 +244,13 @@ void dCalculateRayRenderablePlanet(out dRay ray, out dvec4 planetPositionObjectC
|
||||
sgctEyeCoords.w = 1.0;
|
||||
|
||||
// SGCT Eye to OS World
|
||||
dvec4 worldCoords = dSGCTEyeToOSWorldTransformMatrix * sgctEyeCoords;
|
||||
dvec4 worldCoords = dInverseSgctEyeToWorldTranform * sgctEyeCoords;
|
||||
|
||||
// World to Object
|
||||
dvec4 objectCoords = dInverseModelTransformMatrix * worldCoords;
|
||||
|
||||
// Planet Position in Object Space
|
||||
planetPositionObjectCoords = dvec4(0.0,0.0,0.0,1.0);//dInverseTransformMatrix * dvec4(-dObjpos.xyz + dObjpos.xyz, 1.0);
|
||||
planetPositionObjectCoords = dvec4(0.0,0.0,0.0,1.0);//dInverseModelTransformMatrix * dvec4(-dObjpos.xyz + dObjpos.xyz, 1.0);
|
||||
|
||||
// Camera Position in Object Space
|
||||
cameraPositionInObject = dInverseModelTransformMatrix * dvec4(dCampos, 1.0);
|
||||
@@ -488,9 +438,7 @@ vec3 groundColor(const vec3 x, const float t, const vec3 v, const vec3 s, const
|
||||
float r0 = length(x0);
|
||||
// Normal of intersection point.
|
||||
vec3 n = normalize(normal);
|
||||
//n = normalize(vec3(1.0, 1.0, 1.0));
|
||||
vec4 groundReflectance = groundMeanColor * vec4(.37);
|
||||
//reflectance.w = 1.0;
|
||||
|
||||
// L0 is not included in the irradiance texture.
|
||||
// We first calculate the light attenuation from the top of the atmosphere
|
||||
@@ -620,7 +568,7 @@ void main() {
|
||||
}
|
||||
dvec3 tmpPos = dmat3(dInverseCamRotTransform) * dvec3(dInverseScaleTransformMatrix * farthestPosition);
|
||||
*/
|
||||
dvec4 fragWorldCoords = dSGCTEyeToOSWorldTransformMatrix * meanPosition;
|
||||
dvec4 fragWorldCoords = dInverseSgctEyeToWorldTranform * meanPosition;
|
||||
dvec4 fragObjectCoords = dInverseModelTransformMatrix * fragWorldCoords;
|
||||
//dvec4 fragObjectCoords = dInverseModelTransformMatrix * meanPosition;//fragWorldCoords;
|
||||
double pixelDepth = distance(cameraPositionInObject.xyz, fragObjectCoords.xyz);
|
||||
@@ -671,10 +619,7 @@ void main() {
|
||||
|
||||
renderTarget = finalRadiance;
|
||||
}
|
||||
} else {
|
||||
//renderTarget = vec4(HDR(meanColor.xyz * backgroundExposure), meanColor.a);
|
||||
//renderTarget = vec4(1.0, 0.0, 0.0, 1.0);
|
||||
}
|
||||
}
|
||||
} else if ( RenderableClass == RenderableGlobe) {
|
||||
// Get the ray from camera to atm in object space
|
||||
dCalculateRayRenderableGlobe(ray, planetPositionObjectCoords, cameraPositionInObject);
|
||||
@@ -729,6 +674,7 @@ void main() {
|
||||
}
|
||||
dvec4 tmpRInvPos = dInverseCamRotTransform * farthestPosition;
|
||||
*/
|
||||
|
||||
// Version with milkway enabled
|
||||
dvec4 tmpRInvPos = dInverseCamRotTransform * dSgctEyeToOSEyeTranform * meanPosition;
|
||||
dvec4 fragWorldCoords = dvec4(dvec3(tmpRInvPos) + dCampos, 1.0);
|
||||
@@ -736,7 +682,7 @@ void main() {
|
||||
//dvec4 fragNormalWorldCoords = dvec4(dvec3(tmpRInvNormal) + dCampos, 1.0);
|
||||
|
||||
// World to Object (Normal and Position in meters)
|
||||
dvec4 fragObjectCoords = dInverseTransformMatrix * fragWorldCoords;
|
||||
dvec4 fragObjectCoords = dInverseModelTransformMatrix * fragWorldCoords;
|
||||
//dvec4 fragNormalObjectCoords = dInverseTransformMatrix * fragNormalWorldCoords;
|
||||
|
||||
// Normal in Object Space already (changed 05/26/2017).
|
||||
@@ -786,24 +732,9 @@ void main() {
|
||||
// Final Color of ATM plus terrain:
|
||||
vec4 finalRadiance = vec4(HDR(inscatterColor + groundColor + sunColor), 1.0);
|
||||
|
||||
// Debug:
|
||||
//finalRadiance = vec4(HDR(inscatterColor + sunColor), 1.0);
|
||||
//finalRadiance = mix(finalRadiance, meanColor);
|
||||
//finalRadiance = vec4(inscatterColor, 1.0);
|
||||
//vec4 finalRadiance = vec4(HDR(groundColor), 1.0);
|
||||
//finalRadiance = vec4(HDR(inscatterColor), 1.0);
|
||||
//finalRadiance = vec4(HDR(inscatterColor + meanColor.xyz), meanColor.w);
|
||||
//vec4 finalRadiance = vec4(HDR(sunColor), 1.0);
|
||||
//finalRadiance = vec4(sunColor, 1.0);
|
||||
//finalRadiance = vec4(HDR(inscatterColor + groundColor), 1.0);
|
||||
//finalRadiance = vec4(1.0 - HDR(vec3(pixelDepth/100)),1.0);
|
||||
|
||||
renderTarget = finalRadiance;
|
||||
}
|
||||
} else {
|
||||
//renderTarget = vec4(HDR(meanColor.xyz * backgroundExposure), meanColor.a);
|
||||
//renderTarget = meanColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ uniform Layer Overlays[NUMLAYERS_OVERLAY];
|
||||
|
||||
#if USE_WATERMASK
|
||||
uniform Layer WaterMasks[NUMLAYERS_WATERMASK];
|
||||
float waterReflectance = 0.0;
|
||||
#endif // USE_WATERMASK
|
||||
|
||||
#if SHOW_HEIGHT_RESOLUTION
|
||||
@@ -58,7 +59,6 @@ uniform vec2 vertexResolution;
|
||||
|
||||
#if USE_NIGHTTEXTURE || USE_WATERMASK || USE_ATMOSPHERE || PERFORM_SHADING
|
||||
uniform vec3 lightDirectionCameraSpace;
|
||||
float waterReflectance = 0.0;
|
||||
#endif
|
||||
|
||||
#if PERFORM_SHADING
|
||||
|
||||
Reference in New Issue
Block a user