mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 04:00:37 -06:00
Revert to working atm code, before optimization. Stereo now working.
This commit is contained in:
@@ -1,62 +1,62 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2018 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
****************************************************************************************/
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2018 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this *
|
||||
* software and associated documentation files (the "Software"), to deal in the Software *
|
||||
* without restriction, including without limitation the rights to use, copy, modify, *
|
||||
* merge, publish, distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to the following *
|
||||
* conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be included in all copies *
|
||||
* or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
|
||||
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A *
|
||||
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT *
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF *
|
||||
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE *
|
||||
* 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.
|
||||
****************************************************************************************/
|
||||
/***************************************************************************************
|
||||
* 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.
|
||||
/**
|
||||
* 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 <modules/atmosphere/rendering/renderableatmosphere.h>
|
||||
@@ -90,16 +90,16 @@
|
||||
|
||||
|
||||
namespace {
|
||||
const char* _loggerCat = "AtmosphereDeferredcaster";
|
||||
const char* GlslDeferredcastPath =
|
||||
"${MODULES}/atmosphere/shaders/atmosphere_deferred_fs.glsl";
|
||||
const char* GlslDeferredcastFSPath =
|
||||
"${MODULES}/atmosphere/shaders/atmosphere_deferred_fs.glsl";
|
||||
const char* GlslDeferredcastVsPath =
|
||||
"${MODULES}/atmosphere/shaders/atmosphere_deferred_vs.glsl";
|
||||
const char* _loggerCat = "AtmosphereDeferredcaster";
|
||||
const char* GlslDeferredcastPath =
|
||||
"${MODULES}/atmosphere/shaders/atmosphere_deferred_fs.glsl";
|
||||
const char* GlslDeferredcastFSPath =
|
||||
"${MODULES}/atmosphere/shaders/atmosphere_deferred_fs.glsl";
|
||||
const char* GlslDeferredcastVsPath =
|
||||
"${MODULES}/atmosphere/shaders/atmosphere_deferred_vs.glsl";
|
||||
|
||||
const float ATM_EPS = 2.0;
|
||||
const double KM_TO_M = 1000.0;
|
||||
const float ATM_EPS = 2.0;
|
||||
const double KM_TO_M = 1000.0;
|
||||
} // namespace
|
||||
|
||||
namespace openspace {
|
||||
@@ -162,16 +162,20 @@ void AtmosphereDeferredcaster::initialize() {
|
||||
}
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::update(const UpdateData&) {};
|
||||
|
||||
void AtmosphereDeferredcaster::initializeCachedVariables(ghoul::opengl::ProgramObject&) {}
|
||||
|
||||
void AtmosphereDeferredcaster::deinitialize() {
|
||||
_transmittanceProgramObject = nullptr;
|
||||
_irradianceProgramObject = nullptr;
|
||||
_irradianceSupTermsProgramObject = nullptr;
|
||||
_inScatteringProgramObject = nullptr;
|
||||
_transmittanceProgramObject = nullptr;
|
||||
_irradianceProgramObject = nullptr;
|
||||
_irradianceSupTermsProgramObject = nullptr;
|
||||
_inScatteringProgramObject = nullptr;
|
||||
_inScatteringSupTermsProgramObject = nullptr;
|
||||
_deltaEProgramObject = nullptr;
|
||||
_deltaSProgramObject = nullptr;
|
||||
_deltaSSupTermsProgramObject = nullptr;
|
||||
_deltaJProgramObject = nullptr;
|
||||
_deltaEProgramObject = nullptr;
|
||||
_deltaSProgramObject = nullptr;
|
||||
_deltaSSupTermsProgramObject = nullptr;
|
||||
_deltaJProgramObject = nullptr;
|
||||
|
||||
glDeleteTextures(1, &_transmittanceTableTexture);
|
||||
glDeleteTextures(1, &_irradianceTableTexture);
|
||||
@@ -184,8 +188,8 @@ void AtmosphereDeferredcaster::deinitialize() {
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData,
|
||||
const DeferredcastData&,
|
||||
ghoul::opengl::ProgramObject& program)
|
||||
const DeferredcastData&,
|
||||
ghoul::opengl::ProgramObject& program)
|
||||
{
|
||||
// Atmosphere Frustum Culling
|
||||
glm::dvec3 tPlanetPosWorld = glm::dvec3(
|
||||
@@ -207,85 +211,89 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData,
|
||||
(_atmosphereRadius + ATM_EPS)*KM_TO_M)
|
||||
)
|
||||
{
|
||||
program.setUniform(_uniformCache.cullAtmosphere, 1);
|
||||
program.setUniform("cullAtmosphere", 1);
|
||||
}
|
||||
else {
|
||||
program.setUniform(_uniformCache.cullAtmosphere, 0);
|
||||
program.setUniform(_uniformCache.Rg, _atmospherePlanetRadius);
|
||||
program.setUniform(_uniformCache.Rt, _atmosphereRadius);
|
||||
program.setUniform(_uniformCache.groundRadianceEmittion, _planetGroundRadianceEmittion);
|
||||
program.setUniform(_uniformCache.HR, _rayleighHeightScale);
|
||||
program.setUniform(_uniformCache.betaRayleigh, _rayleighScatteringCoeff);
|
||||
program.setUniform(_uniformCache.HM, _mieHeightScale);
|
||||
program.setUniform(_uniformCache.betaMieExtinction, _mieExtinctionCoeff);
|
||||
program.setUniform(_uniformCache.mieG, _miePhaseConstant);
|
||||
program.setUniform(_uniformCache.sunRadiance, _sunRadianceIntensity);
|
||||
program.setUniform(_uniformCache.ozoneLayerEnabled, _ozoneEnabled);
|
||||
program.setUniform(_uniformCache.HO, _ozoneHeightScale);
|
||||
program.setUniform(_uniformCache.betaOzoneExtinction, _ozoneExtinctionCoeff);
|
||||
program.setUniform(_uniformCache.SAMPLES_R, _r_samples);
|
||||
program.setUniform(_uniformCache.SAMPLES_MU, _mu_samples);
|
||||
program.setUniform(_uniformCache.SAMPLES_MU_S, _mu_s_samples);
|
||||
program.setUniform(_uniformCache.SAMPLES_NU, _nu_samples);
|
||||
program.setUniform("cullAtmosphere", 0);
|
||||
program.setUniform("Rg", _atmospherePlanetRadius);
|
||||
program.setUniform("Rt", _atmosphereRadius);
|
||||
program.setUniform(
|
||||
"AverageGroundReflectance",
|
||||
_planetAverageGroundReflectance
|
||||
);
|
||||
program.setUniform("groundRadianceEmittion", _planetGroundRadianceEmittion);
|
||||
program.setUniform("HR", _rayleighHeightScale);
|
||||
program.setUniform("betaRayleigh", _rayleighScatteringCoeff);
|
||||
program.setUniform("HM", _mieHeightScale);
|
||||
program.setUniform("betaMieScattering", _mieScatteringCoeff);
|
||||
program.setUniform("betaMieExtinction", _mieExtinctionCoeff);
|
||||
program.setUniform("mieG", _miePhaseConstant);
|
||||
program.setUniform("sunRadiance", _sunRadianceIntensity);
|
||||
program.setUniform("ozoneLayerEnabled", _ozoneEnabled);
|
||||
program.setUniform("HO", _ozoneHeightScale);
|
||||
program.setUniform("betaOzoneExtinction", _ozoneExtinctionCoeff);
|
||||
|
||||
program.setUniform("TRANSMITTANCE_W", _transmittance_table_width);
|
||||
program.setUniform("TRANSMITTANCE_H", _transmittance_table_height);
|
||||
program.setUniform("SKY_W", _irradiance_table_width);
|
||||
program.setUniform("SKY_H", _irradiance_table_height);
|
||||
program.setUniform("OTHER_TEXTURES_W", _delta_e_table_width);
|
||||
program.setUniform("OTHER_TEXTURES_H", _delta_e_table_height);
|
||||
program.setUniform("SAMPLES_R", _r_samples);
|
||||
program.setUniform("SAMPLES_MU", _mu_samples);
|
||||
program.setUniform("SAMPLES_MU_S", _mu_s_samples);
|
||||
program.setUniform("SAMPLES_NU", _nu_samples);
|
||||
|
||||
program.setUniform("ModelTransformMatrix", _modelTransform);
|
||||
|
||||
// Object Space
|
||||
glm::dmat4 inverseModelMatrix = glm::inverse(_modelTransform);
|
||||
program.setUniform(_uniformCache2.dInverseModelTransformMatrix, inverseModelMatrix);
|
||||
program.setUniform(_uniformCache2.dModelTransformMatrix, _modelTransform);
|
||||
program.setUniform("dInverseModelTransformMatrix", inverseModelMatrix);
|
||||
program.setUniform("dModelTransformMatrix", _modelTransform);
|
||||
|
||||
// Eye Space in SGCT to Eye Space in OS
|
||||
glm::dmat4 dSgctEye2OSEye = glm::inverse(
|
||||
glm::dmat4(renderData.camera.viewMatrix()));
|
||||
// The following scale comes from PSC transformations.
|
||||
glm::dmat4 dfScaleCamTransf = glm::scale(glm::dvec3(1.0));
|
||||
program.setUniform(
|
||||
"dInverseScaleTransformMatrix",
|
||||
glm::inverse(dfScaleCamTransf)
|
||||
);
|
||||
|
||||
glm::dmat4 dFragmentToWorldMatrix =
|
||||
program.setUniform(
|
||||
"dCamScaleTransform",
|
||||
renderData.camera.viewScaleMatrix()
|
||||
);
|
||||
|
||||
// World to Eye Space in OS
|
||||
program.setUniform(
|
||||
"dInverseCamScaleTransform",
|
||||
glm::inverse(renderData.camera.viewScaleMatrix())
|
||||
);
|
||||
|
||||
program.setUniform(
|
||||
"dInverseCamRotTransform",
|
||||
glm::mat4_cast(
|
||||
static_cast<glm::dquat>(renderData.camera.rotationQuaternion())
|
||||
) * glm::inverse(renderData.camera.viewScaleMatrix());
|
||||
)
|
||||
);
|
||||
|
||||
// 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("dSgctEyeToOSEyeTranform", dSgctEye2OSEye);
|
||||
|
||||
// Eye Space in SGCT to OS Camera Before Rotation
|
||||
program.setUniform(_uniformCache2.dFragmentToWorldMatrix,
|
||||
dFragmentToWorldMatrix);
|
||||
|
||||
// SGCT Projection to SGCT Eye Space
|
||||
glm::dmat4 dInverseProjection = glm::inverse(
|
||||
glm::dmat4(renderData.camera.projectionMatrix()));
|
||||
// Eye Space in SGCT to Projection (Clip) Space in SGCT
|
||||
glm::dmat4 dSgctEye2Clip = glm::dmat4(renderData.camera.projectionMatrix());
|
||||
glm::dmat4 dInverseProjection = glm::inverse(dSgctEye2Clip);
|
||||
|
||||
// SGCT Projection to OS Camera Before Rotation
|
||||
glm::dmat4 dProjectionToTmpRotTransformMatrix =
|
||||
glm::mat4_cast(
|
||||
static_cast<glm::dquat>(renderData.camera.rotationQuaternion())
|
||||
) *
|
||||
dSgctEye2OSEye *
|
||||
glm::inverse(renderData.camera.viewScaleMatrix()) *
|
||||
dInverseProjection;
|
||||
|
||||
// SGCT Projection to World Space
|
||||
glm::dmat4 dSgctProjectionToWorldTransformMatrix(dProjectionToTmpRotTransformMatrix);
|
||||
double *mSource = (double*)glm::value_ptr(dSgctProjectionToWorldTransformMatrix);
|
||||
|
||||
mSource[12] += renderData.camera.eyePositionVec3().x;
|
||||
mSource[13] += renderData.camera.eyePositionVec3().y;
|
||||
mSource[14] += renderData.camera.eyePositionVec3().z;
|
||||
/*
|
||||
mSource[12] += renderData.camera.positionVec3().x;
|
||||
mSource[13] += renderData.camera.positionVec3().y;
|
||||
mSource[14] += renderData.camera.positionVec3().z;
|
||||
*/
|
||||
mSource[15] = 1.0;
|
||||
|
||||
program.setUniform("dInverseSgctProjectionMatrix", dInverseProjection);
|
||||
|
||||
// SGCT Projection to Object Space
|
||||
glm::dmat4 inverseWholeMatrixPipeline = inverseModelMatrix *
|
||||
dSgctProjectionToWorldTransformMatrix;
|
||||
program.setUniform(_uniformCache2.dSgctProjectionToModelTransformMatrix,
|
||||
inverseWholeMatrixPipeline);
|
||||
program.setUniform("dObjpos", glm::dvec4(renderData.position.dvec3(), 1.0));
|
||||
|
||||
program.setUniform(_uniformCache2.dCamRigPos, renderData.camera.positionVec3());
|
||||
|
||||
glm::dvec4 camPosObjCoords = inverseModelMatrix * glm::dvec4(renderData.camera.eyePositionVec3(), 1.0);
|
||||
//glm::dvec4 camPosObjCoords = inverseModelMatrix * glm::dvec4(renderData.camera.positionVec3(), 1.0);
|
||||
program.setUniform(_uniformCache2.dCamPosObj, camPosObjCoords);
|
||||
glm::dvec3 campos = renderData.camera.eyePositionVec3();
|
||||
program.setUniform("dCampos", campos);
|
||||
|
||||
glm::dvec3 camRigPos = renderData.camera.positionVec3();
|
||||
program.setUniform("dCamRigPos", camRigPos);
|
||||
|
||||
double lt;
|
||||
glm::dvec3 sunPosWorld = SpiceManager::ref().targetPosition(
|
||||
@@ -311,7 +319,9 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData,
|
||||
}
|
||||
|
||||
// Sun Position in Object Space
|
||||
program.setUniform(_uniformCache2.sunDirectionObj, glm::normalize(glm::dvec3(sunPosObj)));
|
||||
program.setUniform("sunDirectionObj", glm::normalize(glm::dvec3(sunPosObj)));
|
||||
|
||||
program.setUniform("ellipsoidRadii", _ellipsoidRadii);
|
||||
|
||||
// Shadow calculations..
|
||||
if (!_shadowConfArray.empty()) {
|
||||
@@ -339,8 +349,8 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData,
|
||||
);
|
||||
casterPos *= KM_TO_M; // converting to meters
|
||||
|
||||
// First we determine if the caster is shadowing the current planet
|
||||
// (all calculations in World Coordinates):
|
||||
// First we determine if the caster is shadowing the current planet
|
||||
// (all calculations in World Coordinates):
|
||||
glm::dvec3 planetCasterVec = casterPos - renderData.position.dvec3();
|
||||
glm::dvec3 sourceCasterVec = casterPos - sourcePos;
|
||||
double sc_length = glm::length(sourceCasterVec);
|
||||
@@ -362,7 +372,7 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData,
|
||||
shadowData.isShadowing = false;
|
||||
|
||||
if (((d_test - rp_test) < (_atmospherePlanetRadius * KM_TO_M)) &&
|
||||
//if (((d_test - rp_test) < (_atmosphereRadius * KM_TO_M)) &&
|
||||
//if (((d_test - rp_test) < (_atmosphereRadius * KM_TO_M)) &&
|
||||
(casterDistSun < planetDistSun)) {
|
||||
// The current caster is shadowing the current planet
|
||||
shadowData.isShadowing = true;
|
||||
@@ -371,7 +381,7 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData,
|
||||
shadowData.sourceCasterVec = glm::normalize(sourceCasterVec);
|
||||
shadowData.xp = xp_test;
|
||||
shadowData.xu = shadowData.rc * sc_length /
|
||||
(shadowData.rs - shadowData.rc);
|
||||
(shadowData.rs - shadowData.rc);
|
||||
shadowData.casterPositionVec = casterPos;
|
||||
}
|
||||
shadowDataArray.push_back(shadowData);
|
||||
@@ -405,26 +415,26 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData,
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
program.setUniform(_uniformCache2.hardShadows, _hardShadowsEnabled);
|
||||
program.setUniform("hardShadows", _hardShadowsEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
_transmittanceTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _transmittanceTableTexture);
|
||||
program.setUniform(_uniformCache2.transmittanceTexture, _transmittanceTableTextureUnit);
|
||||
program.setUniform("transmittanceTexture", _transmittanceTableTextureUnit);
|
||||
|
||||
_irradianceTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _irradianceTableTexture);
|
||||
program.setUniform(_uniformCache2.irradianceTexture, _irradianceTableTextureUnit);
|
||||
program.setUniform("irradianceTexture", _irradianceTableTextureUnit);
|
||||
|
||||
_inScatteringTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_3D, _inScatteringTableTexture);
|
||||
program.setUniform(_uniformCache2.inscatterTexture, _inScatteringTableTextureUnit);
|
||||
program.setUniform("inscatterTexture", _inScatteringTableTextureUnit);
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::postRaycast(const RenderData&,
|
||||
const DeferredcastData&,
|
||||
ghoul::opengl::ProgramObject&)
|
||||
const DeferredcastData&,
|
||||
ghoul::opengl::ProgramObject&)
|
||||
{
|
||||
// Deactivate the texture units
|
||||
_transmittanceTableTextureUnit.deactivate();
|
||||
@@ -448,41 +458,6 @@ std::string AtmosphereDeferredcaster::helperPath() const {
|
||||
return ""; // no helper file
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::initializeCachedVariables(ghoul::opengl::ProgramObject& program) {
|
||||
_uniformCache.cullAtmosphere = program.uniformLocation("cullAtmosphere");
|
||||
_uniformCache.Rg = program.uniformLocation("Rg");
|
||||
_uniformCache.Rt = program.uniformLocation("Rt");
|
||||
_uniformCache.groundRadianceEmittion = program.uniformLocation("groundRadianceEmittion");
|
||||
_uniformCache.HR = program.uniformLocation("HR");
|
||||
_uniformCache.betaRayleigh = program.uniformLocation("betaRayleigh");
|
||||
_uniformCache.HM = program.uniformLocation("HM");
|
||||
_uniformCache.betaMieExtinction = program.uniformLocation("betaMieExtinction");
|
||||
_uniformCache.mieG = program.uniformLocation("mieG");
|
||||
_uniformCache.sunRadiance = program.uniformLocation("sunRadiance");
|
||||
_uniformCache.ozoneLayerEnabled = program.uniformLocation("ozoneLayerEnabled");
|
||||
_uniformCache.HO = program.uniformLocation("HO");
|
||||
_uniformCache.betaOzoneExtinction = program.uniformLocation("betaOzoneExtinction");
|
||||
_uniformCache.SAMPLES_R = program.uniformLocation("SAMPLES_R");
|
||||
_uniformCache.SAMPLES_MU = program.uniformLocation("SAMPLES_MU");
|
||||
_uniformCache.SAMPLES_MU_S = program.uniformLocation("SAMPLES_MU_S");
|
||||
_uniformCache.SAMPLES_NU = program.uniformLocation("SAMPLES_NU");
|
||||
_uniformCache2.dInverseModelTransformMatrix = program.uniformLocation("dInverseModelTransformMatrix");
|
||||
_uniformCache2.dModelTransformMatrix = program.uniformLocation("dModelTransformMatrix");
|
||||
_uniformCache2.dSgctProjectionToModelTransformMatrix = program.uniformLocation("dSgctProjectionToModelTransformMatrix");
|
||||
_uniformCache2.dFragmentToWorldMatrix = program.uniformLocation("dFragmentToWorldMatrix");
|
||||
_uniformCache2.dCamRigPos = program.uniformLocation("dCamRigPos");
|
||||
_uniformCache2.dCamPosObj = program.uniformLocation("dCamPosObj");
|
||||
_uniformCache2.sunDirectionObj = program.uniformLocation("sunDirectionObj");
|
||||
_uniformCache2.hardShadows = program.uniformLocation("hardShadows");
|
||||
_uniformCache2.transmittanceTexture = program.uniformLocation("transmittanceTexture");
|
||||
_uniformCache2.irradianceTexture = program.uniformLocation("irradianceTexture");
|
||||
_uniformCache2.inscatterTexture = program.uniformLocation("inscatterTexture");
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::update(const UpdateData&) {
|
||||
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setModelTransform(const glm::dmat4& transform) {
|
||||
_modelTransform = transform;
|
||||
}
|
||||
@@ -500,13 +475,13 @@ void AtmosphereDeferredcaster::setPlanetRadius(float planetRadius) {
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setPlanetAverageGroundReflectance(
|
||||
float averageGReflectance)
|
||||
float averageGReflectance)
|
||||
{
|
||||
_planetAverageGroundReflectance = averageGReflectance;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setPlanetGroundRadianceEmittion(
|
||||
float groundRadianceEmittion)
|
||||
float groundRadianceEmittion)
|
||||
{
|
||||
_planetGroundRadianceEmittion = groundRadianceEmittion;
|
||||
}
|
||||
@@ -537,19 +512,19 @@ void AtmosphereDeferredcaster::setSunRadianceIntensity(float sunRadiance) {
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setRayleighScatteringCoefficients(
|
||||
const glm::vec3& rayScattCoeff)
|
||||
const glm::vec3& rayScattCoeff)
|
||||
{
|
||||
_rayleighScatteringCoeff = rayScattCoeff;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setOzoneExtinctionCoefficients(
|
||||
const glm::vec3& ozoneExtCoeff)
|
||||
const glm::vec3& ozoneExtCoeff)
|
||||
{
|
||||
_ozoneExtinctionCoeff = ozoneExtCoeff;
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setMieScatteringCoefficients(
|
||||
const glm::vec3& mieScattCoeff)
|
||||
const glm::vec3& mieScattCoeff)
|
||||
{
|
||||
_mieScatteringCoeff = mieScattCoeff;
|
||||
}
|
||||
@@ -568,7 +543,7 @@ void AtmosphereDeferredcaster::setHardShadows(bool enabled) {
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setShadowConfigArray(
|
||||
const std::vector<ShadowConfiguration>& shadowConfigArray)
|
||||
const std::vector<ShadowConfiguration>& shadowConfigArray)
|
||||
{
|
||||
_shadowConfArray = shadowConfigArray;
|
||||
}
|
||||
@@ -578,7 +553,7 @@ void AtmosphereDeferredcaster::enableSunFollowing(bool enable) {
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::setPrecalculationTextureScale(
|
||||
float preCalculatedTexturesScale)
|
||||
float preCalculatedTexturesScale)
|
||||
{
|
||||
_calculationTextureScale = preCalculatedTexturesScale;
|
||||
_transmittance_table_width *= static_cast<unsigned int>(_calculationTextureScale);
|
||||
@@ -844,8 +819,8 @@ void AtmosphereDeferredcaster::deleteUnusedComputationTextures() {
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::executeCalculations(GLuint quadCalcVAO,
|
||||
GLenum drawBuffers[1],
|
||||
GLsizei vertexSize)
|
||||
GLenum drawBuffers[1],
|
||||
GLsizei vertexSize)
|
||||
{
|
||||
ghoul::opengl::TextureUnit transmittanceTableTextureUnit;
|
||||
ghoul::opengl::TextureUnit irradianceTableTextureUnit;
|
||||
@@ -1070,9 +1045,9 @@ void AtmosphereDeferredcaster::executeCalculations(GLuint quadCalcVAO,
|
||||
}
|
||||
std::stringstream sst;
|
||||
if (_saveCalculationTextures) {
|
||||
sst << "deltaJ_texture-scattering_order-" << scatteringOrder << ".ppm";
|
||||
saveTextureToPPMFile(GL_COLOR_ATTACHMENT0, sst.str(),
|
||||
_mu_s_samples * _nu_samples, _mu_samples);
|
||||
sst << "deltaJ_texture-scattering_order-" << scatteringOrder << ".ppm";
|
||||
saveTextureToPPMFile(GL_COLOR_ATTACHMENT0, sst.str(),
|
||||
_mu_s_samples * _nu_samples, _mu_samples);
|
||||
}
|
||||
_deltaJProgramObject->deactivate();
|
||||
|
||||
@@ -1119,10 +1094,10 @@ void AtmosphereDeferredcaster::executeCalculations(GLuint quadCalcVAO,
|
||||
loadAtmosphereDataIntoShaderProgram(_irradianceSupTermsProgramObject);
|
||||
renderQuadForCalc(quadCalcVAO, vertexSize);
|
||||
if (_saveCalculationTextures) {
|
||||
sst.str(std::string());
|
||||
sst << "deltaE_texture-scattering_order-" << scatteringOrder << ".ppm";
|
||||
saveTextureToPPMFile(GL_COLOR_ATTACHMENT0, sst.str(),
|
||||
_delta_e_table_width, _delta_e_table_height);
|
||||
sst.str(std::string());
|
||||
sst << "deltaE_texture-scattering_order-" << scatteringOrder << ".ppm";
|
||||
saveTextureToPPMFile(GL_COLOR_ATTACHMENT0, sst.str(),
|
||||
_delta_e_table_width, _delta_e_table_height);
|
||||
}
|
||||
_irradianceSupTermsProgramObject->deactivate();
|
||||
|
||||
@@ -1154,14 +1129,14 @@ void AtmosphereDeferredcaster::executeCalculations(GLuint quadCalcVAO,
|
||||
renderQuadForCalc(quadCalcVAO, vertexSize);
|
||||
}
|
||||
if (_saveCalculationTextures) {
|
||||
sst.str(std::string());
|
||||
sst << "deltaS_texture-scattering_order-" << scatteringOrder << ".ppm";
|
||||
saveTextureToPPMFile(
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
sst.str(),
|
||||
_mu_s_samples * _nu_samples,
|
||||
_mu_samples
|
||||
);
|
||||
sst.str(std::string());
|
||||
sst << "deltaS_texture-scattering_order-" << scatteringOrder << ".ppm";
|
||||
saveTextureToPPMFile(
|
||||
GL_COLOR_ATTACHMENT0,
|
||||
sst.str(),
|
||||
_mu_s_samples * _nu_samples,
|
||||
_mu_samples
|
||||
);
|
||||
}
|
||||
_inScatteringSupTermsProgramObject->deactivate();
|
||||
|
||||
@@ -1188,10 +1163,10 @@ void AtmosphereDeferredcaster::executeCalculations(GLuint quadCalcVAO,
|
||||
loadAtmosphereDataIntoShaderProgram(_irradianceFinalProgramObject);
|
||||
renderQuadForCalc(quadCalcVAO, vertexSize);
|
||||
if (_saveCalculationTextures) {
|
||||
sst.str(std::string());
|
||||
sst << "irradianceTable_order-" << scatteringOrder << ".ppm";
|
||||
saveTextureToPPMFile(GL_COLOR_ATTACHMENT0, sst.str(),
|
||||
_delta_e_table_width, _delta_e_table_height);
|
||||
sst.str(std::string());
|
||||
sst << "irradianceTable_order-" << scatteringOrder << ".ppm";
|
||||
saveTextureToPPMFile(GL_COLOR_ATTACHMENT0, sst.str(),
|
||||
_delta_e_table_width, _delta_e_table_height);
|
||||
}
|
||||
_irradianceFinalProgramObject->deactivate();
|
||||
|
||||
@@ -1217,10 +1192,10 @@ void AtmosphereDeferredcaster::executeCalculations(GLuint quadCalcVAO,
|
||||
renderQuadForCalc(quadCalcVAO, vertexSize);
|
||||
}
|
||||
if (_saveCalculationTextures) {
|
||||
sst.str(std::string());
|
||||
sst << "inscatteringTable_order-" << scatteringOrder << ".ppm";
|
||||
saveTextureToPPMFile(GL_COLOR_ATTACHMENT0, sst.str(),
|
||||
_mu_s_samples * _nu_samples, _mu_samples);
|
||||
sst.str(std::string());
|
||||
sst << "inscatteringTable_order-" << scatteringOrder << ".ppm";
|
||||
saveTextureToPPMFile(GL_COLOR_ATTACHMENT0, sst.str(),
|
||||
_mu_s_samples * _nu_samples, _mu_samples);
|
||||
}
|
||||
_deltaSSupTermsProgramObject->deactivate();
|
||||
|
||||
@@ -1323,7 +1298,7 @@ void AtmosphereDeferredcaster::createRenderQuad(GLuint* vao, GLuint* vbo, GLfloa
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::loadAtmosphereDataIntoShaderProgram(
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject>& shaderProg)
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject>& shaderProg)
|
||||
{
|
||||
shaderProg->setUniform("Rg", _atmospherePlanetRadius);
|
||||
shaderProg->setUniform("Rt", _atmosphereRadius);
|
||||
@@ -1358,7 +1333,7 @@ void AtmosphereDeferredcaster::loadAtmosphereDataIntoShaderProgram(
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::checkFrameBufferState(
|
||||
const std::string& codePosition) const
|
||||
const std::string& codePosition) const
|
||||
{
|
||||
if (glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LERROR("Framework not built. " + codePosition);
|
||||
@@ -1379,8 +1354,8 @@ void AtmosphereDeferredcaster::checkFrameBufferState(
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
|
||||
LERROR("Returned if GL_READ_BUFFER is not GL_NONE and the value of "
|
||||
"GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE for the color attachment "
|
||||
"point named by GL_READ_BUFFER.");
|
||||
"GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE for the color attachment "
|
||||
"point named by GL_READ_BUFFER.");
|
||||
break;
|
||||
case GL_FRAMEBUFFER_UNSUPPORTED:
|
||||
LERROR("Returned if the combination of internal formats of the attached "
|
||||
@@ -1418,25 +1393,25 @@ void AtmosphereDeferredcaster::renderQuadForCalc(GLuint vao, GLsizei numberOfVer
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::step3DTexture(
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject>& shaderProg,
|
||||
int layer, bool doCalc)
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject>& shaderProg,
|
||||
int layer, bool doCalc)
|
||||
{
|
||||
// See OpenGL redbook 8th Edition page 556 for Layered Rendering
|
||||
if (doCalc) {
|
||||
float earth2 = _atmospherePlanetRadius * _atmospherePlanetRadius;
|
||||
float atm2 = _atmosphereRadius * _atmosphereRadius;
|
||||
float diff = atm2 - earth2;
|
||||
float ri = static_cast<float>(layer) / static_cast<float>(_r_samples - 1);
|
||||
float ri_2 = ri * ri;
|
||||
float earth2 = _atmospherePlanetRadius * _atmospherePlanetRadius;
|
||||
float atm2 = _atmosphereRadius * _atmosphereRadius;
|
||||
float diff = atm2 - earth2;
|
||||
float ri = static_cast<float>(layer) / static_cast<float>(_r_samples - 1);
|
||||
float ri_2 = ri * ri;
|
||||
float epsilon =
|
||||
(layer == 0) ?
|
||||
0.01f :
|
||||
(layer == (static_cast<int>(_r_samples) - 1)) ? -0.001f : 0.0f;
|
||||
float r = sqrtf(earth2 + ri_2 * diff) + epsilon;
|
||||
float dminG = r - _atmospherePlanetRadius;
|
||||
float dminT = _atmosphereRadius - r;
|
||||
float dh = sqrtf(r * r - earth2);
|
||||
float dH = dh + sqrtf(diff);
|
||||
float r = sqrtf(earth2 + ri_2 * diff) + epsilon;
|
||||
float dminG = r - _atmospherePlanetRadius;
|
||||
float dminT = _atmosphereRadius - r;
|
||||
float dh = sqrtf(r * r - earth2);
|
||||
float dH = dh + sqrtf(diff);
|
||||
|
||||
shaderProg->setUniform("r", r);
|
||||
shaderProg->setUniform("dhdH", dminT, dH, dminG, dh);
|
||||
@@ -1446,8 +1421,8 @@ void AtmosphereDeferredcaster::step3DTexture(
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::saveTextureToPPMFile(GLenum color_buffer_attachment,
|
||||
const std::string& fileName,
|
||||
int width, int height) const
|
||||
const std::string& fileName,
|
||||
int width, int height) const
|
||||
{
|
||||
std::fstream ppmFile;
|
||||
|
||||
@@ -1483,8 +1458,8 @@ void AtmosphereDeferredcaster::saveTextureToPPMFile(GLenum color_buffer_attachme
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
ppmFile << static_cast<unsigned int>(pixels[k]) << " "
|
||||
<< static_cast<unsigned int>(pixels[k + 1]) << " "
|
||||
<< static_cast<unsigned int>(pixels[k + 2]) << " ";
|
||||
<< static_cast<unsigned int>(pixels[k + 1]) << " "
|
||||
<< static_cast<unsigned int>(pixels[k + 2]) << " ";
|
||||
k += 3;
|
||||
}
|
||||
ppmFile << std::endl;
|
||||
@@ -1496,8 +1471,8 @@ void AtmosphereDeferredcaster::saveTextureToPPMFile(GLenum color_buffer_attachme
|
||||
}
|
||||
|
||||
bool AtmosphereDeferredcaster::isAtmosphereInFrustum(const double* MVMatrix,
|
||||
const glm::dvec3& position,
|
||||
double radius) const
|
||||
const glm::dvec3& position,
|
||||
double radius) const
|
||||
{
|
||||
|
||||
// Frustum Planes
|
||||
@@ -1514,36 +1489,36 @@ bool AtmosphereDeferredcaster::isAtmosphereInFrustum(const double* MVMatrix,
|
||||
glm::dvec3 farNormal = col4 - col3;
|
||||
|
||||
// Plane Distances
|
||||
double leftDistance = MVMatrix[15] + MVMatrix[12];
|
||||
double rightDistance = MVMatrix[15] - MVMatrix[12];
|
||||
double leftDistance = MVMatrix[15] + MVMatrix[12];
|
||||
double rightDistance = MVMatrix[15] - MVMatrix[12];
|
||||
double bottomDistance = MVMatrix[15] + MVMatrix[13];
|
||||
double topDistance = MVMatrix[15] - MVMatrix[13];
|
||||
double nearDistance = MVMatrix[15] + MVMatrix[14];
|
||||
double farDistance = MVMatrix[15] - MVMatrix[14];
|
||||
double topDistance = MVMatrix[15] - MVMatrix[13];
|
||||
double nearDistance = MVMatrix[15] + MVMatrix[14];
|
||||
double farDistance = MVMatrix[15] - MVMatrix[14];
|
||||
|
||||
// Normalize Planes
|
||||
double invMag = 1.0 / glm::length(leftNormal);
|
||||
leftNormal *= invMag;
|
||||
leftNormal *= invMag;
|
||||
leftDistance *= invMag;
|
||||
|
||||
invMag = 1.0 / glm::length(rightNormal);
|
||||
rightNormal *= invMag;
|
||||
rightNormal *= invMag;
|
||||
rightDistance *= invMag;
|
||||
|
||||
invMag = 1.0 / glm::length(bottomNormal);
|
||||
bottomNormal *= invMag;
|
||||
bottomNormal *= invMag;
|
||||
bottomDistance *= invMag;
|
||||
|
||||
invMag = 1.0 / glm::length(topNormal);
|
||||
topNormal *= invMag;
|
||||
topNormal *= invMag;
|
||||
topDistance *= invMag;
|
||||
|
||||
invMag = 1.0 / glm::length(nearNormal);
|
||||
nearNormal *= invMag;
|
||||
nearNormal *= invMag;
|
||||
nearDistance *= invMag;
|
||||
|
||||
invMag = 1.0 / glm::length(farNormal);
|
||||
farNormal *= invMag;
|
||||
farNormal *= invMag;
|
||||
farDistance *= invMag;
|
||||
|
||||
if ((glm::dot(leftNormal, position) + leftDistance) < -radius) {
|
||||
@@ -1563,7 +1538,7 @@ bool AtmosphereDeferredcaster::isAtmosphereInFrustum(const double* MVMatrix,
|
||||
}
|
||||
// The far plane testing is disabled because the atm has no depth.
|
||||
/*else if ((glm::dot(farNormal, position) + farDistance) < -radius) {
|
||||
return false;
|
||||
return false;
|
||||
}*/
|
||||
|
||||
return true;
|
||||
|
||||
@@ -84,14 +84,21 @@ uniform sampler2DMS mainPositionTexture;
|
||||
uniform sampler2DMS mainNormalTexture;
|
||||
uniform sampler2DMS mainColorTexture;
|
||||
|
||||
// Model Transform Matrix Used for Globe Rendering
|
||||
uniform dmat4 dSgctEyeToOSEyeTranform; // SGCT Eye to OS Eye *
|
||||
uniform dmat4 dInverseSgctProjectionMatrix; // Clip to SGCT Eye *
|
||||
uniform dmat4 dCamScaleTransform;
|
||||
uniform dmat4 dInverseCamScaleTransform;
|
||||
uniform dmat4 dInverseCamRotTransform;
|
||||
uniform dmat4 dInverseModelTransformMatrix;
|
||||
uniform dmat4 dModelTransformMatrix;
|
||||
uniform dmat4 dFragmentToWorldMatrix;
|
||||
uniform dmat4 dSgctProjectionToModelTransformMatrix;
|
||||
//uniform dmat4 dSGCTEyeToOSWorldTransformMatrix;
|
||||
|
||||
uniform dvec4 dObjpos;
|
||||
uniform dvec3 dCamRigPos;
|
||||
uniform dvec4 dCamPosObj;
|
||||
uniform dvec3 dCampos;
|
||||
uniform dvec3 sunDirectionObj;
|
||||
uniform dvec3 ellipsoidRadii;
|
||||
|
||||
/*******************************************************************************
|
||||
***** ALL CALCULATIONS FOR ECLIPSE ARE IN METERS AND IN WORLD SPACE SYSTEM ****
|
||||
@@ -246,28 +253,38 @@ void dCalculateRayRenderableGlobe(in int mssaSample, out dRay ray,
|
||||
// ======================================
|
||||
// ======= Avoiding Some Matrices =======
|
||||
|
||||
// Compute positions and directions in object space.
|
||||
// Compute positions and directions in world space.
|
||||
dvec2 samplePos = dvec2(msaaSamplePatter[mssaSample],
|
||||
msaaSamplePatter[mssaSample+1]);
|
||||
dvec4 clipCoords = dvec4(interpolatedNDCPos.xy + samplePos, 0.0, 1.0);
|
||||
msaaSamplePatter[mssaSample+1]);
|
||||
dvec4 clipCoords = dvec4(interpolatedNDCPos.xy + samplePos, 1.0, 1.0);
|
||||
|
||||
// Clip to Object Coords
|
||||
dvec4 objectCoords = dSgctProjectionToModelTransformMatrix * clipCoords;
|
||||
// Clip to SGCT Eye
|
||||
dvec4 sgctEyeCoords = dInverseSgctProjectionMatrix * clipCoords;
|
||||
|
||||
// SGCT Eye to OS Eye
|
||||
dvec4 tOSEyeCoords = dSgctEyeToOSEyeTranform * sgctEyeCoords;
|
||||
|
||||
// OS Eye to World coords
|
||||
dvec4 offsetWorldCoords = dInverseCamRotTransform * dInverseCamScaleTransform * tOSEyeCoords;
|
||||
dvec4 worldCoords = dvec4(dvec3(offsetWorldCoords) + dCampos, 1.0);
|
||||
|
||||
// World to Object
|
||||
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);
|
||||
//planetPositionObjectCoords = dInverseModelTransformMatrix * dvec4(dObjpos.xyz, 1.0);
|
||||
|
||||
// Camera Position in Object Space (in meters)
|
||||
cameraPositionInObject = dCamPosObj;
|
||||
|
||||
// Camera Position in Object Space
|
||||
cameraPositionInObject = dInverseModelTransformMatrix * dvec4(dCampos, 1.0);
|
||||
|
||||
// ============================
|
||||
// ====== Building Ray ========
|
||||
// Ray in object space (in KM)
|
||||
ray.origin = cameraPositionInObject * dvec4(0.001, 0.001, 0.001, 1.0);
|
||||
//ray.direction = dvec4(normalize(objectCoords.xyz - cameraPositionInObject.xyz), 0.0);
|
||||
ray.direction = dvec4(normalize((objectCoords.xyz * dvec3(0.001))- ray.origin.xyz), 0.0);
|
||||
ray.direction = dvec4(normalize(objectCoords.xyz - cameraPositionInObject.xyz), 0.0);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -374,12 +391,11 @@ vec3 inscatterRadiance(inout vec3 x, inout float t, inout float irradianceFactor
|
||||
// From cosine law where t = distance between x and x0
|
||||
// r0^2 = r^2 + t^2 - 2 * r * t * cos(PI-theta)
|
||||
r0 = sqrt(r2 + t2 + 2.0f * r * t * mu);
|
||||
float invr0 = 1.0/r0;
|
||||
// From the dot product: cos(theta0) = (x0 dot v)/(||ro||*||v||)
|
||||
// mu0 = ((x + t) dot v) / r0
|
||||
// mu0 = (x dot v + t dot v) / r0
|
||||
// mu0 = (r*mu + t) / r0
|
||||
mu0 = (r * mu + t) * invr0;
|
||||
mu0 = (r * mu + t) / r0;
|
||||
vec4 inScatterAboveX = texture4D(inscatterTexture, r, mu, muSun, nu);
|
||||
vec4 inScatterAboveXs = texture4D(inscatterTexture, r0, mu0, muSun0, nu);
|
||||
// Attention for the attenuation.r value applied to the S_Mie
|
||||
@@ -388,7 +404,7 @@ vec3 inscatterRadiance(inout vec3 x, inout float t, inout float irradianceFactor
|
||||
// Below Horizon
|
||||
mu = muHorizon + INTERPOLATION_EPS;
|
||||
r0 = sqrt(r2 + t2 + 2.0f * r * t * mu);
|
||||
mu0 = (r * mu + t) * invr0;
|
||||
mu0 = (r * mu + t) / r0;
|
||||
vec4 inScatterBelowX = texture4D(inscatterTexture, r, mu, muSun, nu);
|
||||
vec4 inScatterBelowXs = texture4D(inscatterTexture, r0, mu0, muSun0, nu);
|
||||
// Attention for the attenuation.r value applied to the S_Mie
|
||||
@@ -453,8 +469,7 @@ vec3 groundColor(const vec3 x, const float t, const vec3 v, const vec3 s, const
|
||||
vec3 x0 = x + t * v;
|
||||
float r0 = length(x0);
|
||||
// Normal of intersection point.
|
||||
// Normal must be normalized.
|
||||
vec3 n = normal;
|
||||
vec3 n = normalize(normal);
|
||||
//vec4 groundReflectance = groundColor * vec4(.37);
|
||||
vec4 groundReflectance = groundColor *
|
||||
vec4(groundRadianceEmittion, groundRadianceEmittion, groundRadianceEmittion, 1.0f);
|
||||
@@ -532,30 +547,25 @@ vec3 sunColor(const vec3 x, const float t, const vec3 v, const vec3 s, const flo
|
||||
return transmittance * sunFinalColor;
|
||||
}
|
||||
|
||||
void main() {
|
||||
ivec2 fragCoords = ivec2(gl_FragCoord);
|
||||
|
||||
void main() {
|
||||
if (cullAtmosphere == 0) {
|
||||
|
||||
vec4 atmosphereFinalColor = vec4(0.0f);
|
||||
int nSamples = 1;
|
||||
|
||||
// First we determine if the pixel is complex (different fragments on it)
|
||||
bool complex = false;
|
||||
vec4 oldColor, currentColor;
|
||||
//vec4 colorArray[16];
|
||||
//int colorIndexArray[16];
|
||||
|
||||
oldColor = texelFetch(mainColorTexture, fragCoords, 0);
|
||||
oldColor = texelFetch(mainColorTexture, ivec2(gl_FragCoord), 0);
|
||||
//colorArray[0] = oldColor;
|
||||
//colorIndexArray[0] = 0;
|
||||
for (int i = 1; i < nAaSamples; i++) {
|
||||
//vec4 normal = texelFetch(mainNormalTexture, fragCoords, i);
|
||||
vec4 currentColor = texelFetch(mainColorTexture, fragCoords, i);
|
||||
//vec4 normal = texelFetch(mainNormalTexture, ivec2(gl_FragCoord), i);
|
||||
vec4 currentColor = texelFetch(mainColorTexture, ivec2(gl_FragCoord), i);
|
||||
//colorArray[i] = currentColor;
|
||||
if (currentColor != oldColor) {
|
||||
complex = true;
|
||||
//nSamples = nAaSamples;
|
||||
nSamples = nAaSamples > 1 ? nAaSamples / 2 : nAaSamples;
|
||||
break;
|
||||
// for (int c = 0; c < nAaSamples; c++) {
|
||||
// if (currentColor == colorArray[c]) {
|
||||
@@ -574,10 +584,18 @@ void main() {
|
||||
// }
|
||||
oldColor = currentColor;
|
||||
}
|
||||
|
||||
int nSamples = 1;
|
||||
if (complex) {
|
||||
//nSamples = nAaSamples;
|
||||
nSamples = nAaSamples > 1 ? nAaSamples/2 : nAaSamples;
|
||||
}
|
||||
|
||||
for (int i = 0; i < nSamples; i++) {
|
||||
// Color from G-Buffer
|
||||
vec4 color = texelFetch(mainColorTexture, fragCoords, i);
|
||||
vec4 normal = texelFetch(mainNormalTexture, ivec2(gl_FragCoord), i);
|
||||
vec4 color = texelFetch(mainColorTexture, ivec2(gl_FragCoord), i);
|
||||
// Data in the mainPositionTexture are written in view space (view plus camera rig)
|
||||
vec4 position = texelFetch(mainPositionTexture, ivec2(gl_FragCoord), i);
|
||||
|
||||
// Ray in object space
|
||||
dRay ray;
|
||||
@@ -589,39 +607,47 @@ void main() {
|
||||
cameraPositionInObject);
|
||||
|
||||
bool insideATM = false;
|
||||
double offset = 0.0; // in Km
|
||||
double maxLength = 0.0; // in Km
|
||||
double offset = 0.0;
|
||||
double maxLength = 0.0;
|
||||
|
||||
bool intersectATM = false;
|
||||
|
||||
intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, ray,
|
||||
Rt - (ATM_EPSILON * 0.001), insideATM, offset, maxLength );
|
||||
|
||||
// Instead of ray-ellipsoid intersection lets transform the ray to a sphere:
|
||||
dRay transfRay;
|
||||
transfRay.origin = ray.origin;
|
||||
transfRay.direction = ray.direction;
|
||||
|
||||
// transfRay.origin.z *= 1000.0/ellipsoidRadii.x;
|
||||
// transfRay.direction.z *= 1000.0/ellipsoidRadii.x;
|
||||
// transfRay.origin.x *= 1000.0/ellipsoidRadii.y;
|
||||
// transfRay.direction.x *= 1000.0/ellipsoidRadii.y;
|
||||
// transfRay.origin.y *= 1000.0/ellipsoidRadii.z;
|
||||
// transfRay.direction.y *= 1000.0/ellipsoidRadii.z;
|
||||
// transfRay.direction.xyz = normalize(transfRay.direction.xyz);
|
||||
|
||||
intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, transfRay,
|
||||
Rt - ATM_EPSILON/100.0, insideATM, offset, maxLength );
|
||||
|
||||
if ( intersectATM ) {
|
||||
// Now we check is if the atmosphere is occluded, i.e., if the distance to the pixel
|
||||
// in the depth buffer is less than the distance to the atmosphere then the atmosphere
|
||||
// is occluded
|
||||
// Fragments positions into G-Buffer are written in SGCT Eye Space (View plus Camera Rig Coords)
|
||||
// Fragments positions into G-Buffer are written in OS Eye Space (Camera Rig Coords)
|
||||
// when using their positions later, one must convert them to the planet's coords
|
||||
|
||||
// Get data from G-Buffer
|
||||
vec4 normal = texelFetch(mainNormalTexture, fragCoords, i);
|
||||
// Data in the mainPositionTexture are written in view space (view plus camera rig)
|
||||
vec4 position = texelFetch(mainPositionTexture, fragCoords, i);
|
||||
|
||||
// OS Eye to World coords
|
||||
dvec4 fragWorldCoords = dFragmentToWorldMatrix * position;
|
||||
|
||||
// OS Eye to World coords
|
||||
dvec4 fragWorldCoordsOffset = dInverseCamRotTransform * dInverseCamScaleTransform * dSgctEyeToOSEyeTranform * position;
|
||||
dvec4 fragWorldCoords = dvec4(dvec3(fragWorldCoordsOffset) + dCamRigPos, 1.0);
|
||||
|
||||
// World to Object (Normal and Position in meters)
|
||||
dvec4 fragObjectCoords = dInverseModelTransformMatrix * fragWorldCoords;
|
||||
|
||||
dvec4 fragObjectCoords = dInverseModelTransformMatrix * fragWorldCoords;
|
||||
|
||||
// Distance of the pixel in the gBuffer to the observer
|
||||
// JCC (12/12/2017): AMD distance function is buggy.
|
||||
//double pixelDepth = distance(cameraPositionInObject.xyz, fragObjectCoords.xyz);
|
||||
double pixelDepth = length(cameraPositionInObject.xyz - fragObjectCoords.xyz);
|
||||
|
||||
// JCC (12/13/2017): Trick to remove floating error in texture.
|
||||
// JCC (12/13/2017): TRick to remove floating error in texture.
|
||||
// We see a squared noise on planet's surface when seeing the planet
|
||||
// from far away.
|
||||
float dC = float(length(cameraPositionInObject.xyz));
|
||||
@@ -633,13 +659,13 @@ void main() {
|
||||
float x2 = 1e9;
|
||||
float diffGreek = beta - alpha;
|
||||
float diffDist = x2 - x1;
|
||||
float varA = diffGreek/diffDist;
|
||||
float varB = (alpha - varA * x1);
|
||||
pixelDepth += double(varA * dC + varB);
|
||||
float varA = diffGreek/diffDist;
|
||||
float varB = (alpha - varA * x1);
|
||||
pixelDepth += double(varA * dC + varB);
|
||||
}
|
||||
|
||||
// All calculations are done in Km:
|
||||
pixelDepth *= 0.001;
|
||||
pixelDepth *= 0.001;
|
||||
fragObjectCoords.xyz *= 0.001;
|
||||
|
||||
if (position.xyz != vec3(0.0) && (pixelDepth < offset)) {
|
||||
@@ -654,9 +680,9 @@ void main() {
|
||||
// If the observer is already inside the atm, offset = 0.0
|
||||
// and no changes at all.
|
||||
vec3 x = vec3(ray.origin.xyz + t*ray.direction.xyz);
|
||||
float r = 0.0f;//length(x);
|
||||
float r = 0.0;//length(x);
|
||||
vec3 v = vec3(ray.direction.xyz);
|
||||
float mu = 0.0f;//dot(x, v) / r;
|
||||
float mu = 0.0;//dot(x, v) / r;
|
||||
vec3 s = vec3(sunDirectionObj);
|
||||
float tF = float(maxLength - t);
|
||||
|
||||
@@ -665,7 +691,7 @@ void main() {
|
||||
// next comparison with the planet's ground make sense:
|
||||
pixelDepth -= offset;
|
||||
|
||||
dvec4 onATMPos = dModelTransformMatrix * dvec4(x * 1000.0, 1.0);
|
||||
dvec4 onATMPos = dModelTransformMatrix * dvec4(x*1000.0, 1.0);
|
||||
vec4 eclipseShadowATM = calcShadow(shadowDataArray, onATMPos.xyz, false);
|
||||
vec4 eclipseShadowPlanet = calcShadow(shadowDataArray, fragWorldCoords.xyz, true);
|
||||
|
||||
@@ -693,7 +719,7 @@ void main() {
|
||||
else { // no intersection
|
||||
//discard;
|
||||
atmosphereFinalColor += vec4(HDR(color.xyz * backgroundConstant, atmExposure), color.a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
renderTarget = atmosphereFinalColor / float(nSamples);
|
||||
@@ -702,7 +728,7 @@ void main() {
|
||||
if (firstPaint) {
|
||||
vec4 bColor = vec4(0.0f);
|
||||
for (int f = 0; f < nAaSamples; f++) {
|
||||
bColor += texelFetch(mainColorTexture, fragCoords, f);
|
||||
bColor += texelFetch(mainColorTexture, ivec2(gl_FragCoord), f);
|
||||
}
|
||||
bColor /= float(nAaSamples);
|
||||
renderTarget = vec4(HDR(bColor.xyz * backgroundConstant, atmExposure), bColor.a);
|
||||
@@ -714,4 +740,3 @@ void main() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user