mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-22 04:49:12 -06:00
Removed unsused code, started ellipsoid rendering for globebrowsing. Added deferred framebuffer.
This commit is contained in:
@@ -104,6 +104,8 @@ private:
|
||||
GLuint _mainFramebuffer;
|
||||
GLuint _exitDepthTexture;
|
||||
GLuint _exitFramebuffer;
|
||||
GLuint _deferredFramebuffer;
|
||||
GLuint _deferredColorTexture;
|
||||
|
||||
bool _dirtyDeferredcastData;
|
||||
bool _dirtyRaycastData;
|
||||
|
||||
@@ -52,10 +52,7 @@
|
||||
namespace {
|
||||
const std::string _loggerCat = "AtmosphereDeferredcaster";
|
||||
const char* GlslDeferredcastPath = "${MODULES}/atmosphere/shaders/deferred_test_fs.glsl";
|
||||
//const char* GlslDeferredcastFSPath = "${MODULES}/atmosphere/shaders/atmosphere_deferred_fs.glsl";
|
||||
//const char* GlslDeferredcastFSPath = "${MODULES}/atmosphere/shaders/atmosphere_fs.glsl";
|
||||
//const char* GlslDeferredcastFSPath = "";
|
||||
const char* GlslDeferredcastFSPath = "${MODULES}/atmosphere/shaders/deferred_test_fs.glsl";
|
||||
const char* GlslDeferredcastFSPath = "${MODULES}/atmosphere/shaders/deferred_test_fs.glsl";
|
||||
const char* GlslDeferredcastVsPath = "${MODULES}/atmosphere/shaders/atmosphere_deferred_vs.glsl";
|
||||
}
|
||||
|
||||
@@ -73,7 +70,6 @@ AtmosphereDeferredcaster::AtmosphereDeferredcaster()
|
||||
, _deltaSProgramObject(nullptr)
|
||||
, _deltaSSupTermsProgramObject(nullptr)
|
||||
, _deltaJProgramObject(nullptr)
|
||||
, _cleanTextureProgramObject(nullptr)
|
||||
, _atmosphereProgramObject(nullptr)
|
||||
, _transmittanceTableTexture(0)
|
||||
, _irradianceTableTexture(0)
|
||||
@@ -107,9 +103,7 @@ AtmosphereDeferredcaster::~AtmosphereDeferredcaster() {}
|
||||
void AtmosphereDeferredcaster::initialize()
|
||||
{
|
||||
if (!_atmosphereCalculated) {
|
||||
LWARNING("Executing Atmosphere Calculations in Deferredcaster.");
|
||||
preCalculateAtmosphereParam();
|
||||
LWARNING("Atmosphere Calculations in Deferredcaster done.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,10 +153,6 @@ void AtmosphereDeferredcaster::deinitialize()
|
||||
_deltaJProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_cleanTextureProgramObject) {
|
||||
_cleanTextureProgramObject = nullptr;
|
||||
}
|
||||
|
||||
glDeleteTextures(1, &_transmittanceTableTexture);
|
||||
glDeleteTextures(1, &_irradianceTableTexture);
|
||||
glDeleteTextures(1, &_inScatteringTableTexture);
|
||||
@@ -189,6 +179,8 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData & renderData, const D
|
||||
program.setUniform("sunRadiance", _sunRadianceIntensity);
|
||||
program.setUniform("exposure", _hdrConstant);
|
||||
|
||||
program.setUniform("ModelTransformMatrix", glm::dmat4(_modelTransform));
|
||||
|
||||
// Object Space
|
||||
//program.setUniform("inverseTransformMatrix", glm::inverse(_modelTransform));
|
||||
program.setUniform("dInverseTransformMatrix", glm::inverse(glm::dmat4(_modelTransform)));
|
||||
@@ -240,11 +232,6 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData & renderData, const D
|
||||
program.setUniform("sunDirectionObj", glm::normalize(glm::dvec3(sunPosObj)));
|
||||
//program.setUniform("_performShading", _performShading);
|
||||
|
||||
// Otherwise the transmittance is not correctly loaded. ???????
|
||||
// What about the main texture?
|
||||
ghoul::opengl::TextureUnit dummyUnit;
|
||||
dummyUnit.activate();
|
||||
|
||||
ghoul::opengl::TextureUnit transmittanceTableTextureUnit;
|
||||
transmittanceTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _transmittanceTableTexture);
|
||||
@@ -696,73 +683,6 @@ void AtmosphereDeferredcaster::loadComputationPrograms() {
|
||||
}
|
||||
_deltaJProgramObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
_deltaJProgramObject->setIgnoreUniformLocationError(IgnoreError::Yes);
|
||||
|
||||
//============== Clean Texture Program =================
|
||||
if (_cleanTextureProgramObject == nullptr) {
|
||||
// shadow program
|
||||
_cleanTextureProgramObject = ghoul::opengl::ProgramObject::Build(
|
||||
"cleanTextureProgram",
|
||||
"${MODULE_ATMOSPHERE}/shaders/texture_clean_vs.glsl",
|
||||
"${MODULE_ATMOSPHERE}/shaders/texture_clean_fs.glsl");
|
||||
if (!_cleanTextureProgramObject) {
|
||||
if (_transmittanceProgramObject) {
|
||||
_transmittanceProgramObject.reset();
|
||||
_transmittanceProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_irradianceProgramObject) {
|
||||
_irradianceProgramObject.reset();
|
||||
_irradianceProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_irradianceSupTermsProgramObject) {
|
||||
_irradianceSupTermsProgramObject.reset();
|
||||
_irradianceSupTermsProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_inScatteringProgramObject) {
|
||||
_inScatteringProgramObject.reset();
|
||||
_inScatteringProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_inScatteringSupTermsProgramObject) {
|
||||
_inScatteringSupTermsProgramObject.reset();
|
||||
_inScatteringSupTermsProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_deltaEProgramObject) {
|
||||
_deltaEProgramObject.reset();
|
||||
_deltaEProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_irradianceFinalProgramObject) {
|
||||
_irradianceFinalProgramObject.reset();
|
||||
_irradianceFinalProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_deltaSProgramObject) {
|
||||
_deltaSProgramObject.reset();
|
||||
_deltaSProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_deltaSSupTermsProgramObject) {
|
||||
_deltaSSupTermsProgramObject.reset();
|
||||
_deltaSSupTermsProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_deltaJProgramObject) {
|
||||
_deltaJProgramObject.reset();
|
||||
_deltaEProgramObject = nullptr;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
_cleanTextureProgramObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
_cleanTextureProgramObject->setIgnoreUniformLocationError(IgnoreError::Yes);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::unloadComputationPrograms() {
|
||||
@@ -818,11 +738,6 @@ void AtmosphereDeferredcaster::unloadComputationPrograms() {
|
||||
_deltaJProgramObject.reset();
|
||||
_deltaJProgramObject = nullptr;
|
||||
}
|
||||
|
||||
if (_cleanTextureProgramObject) {
|
||||
_cleanTextureProgramObject.reset();
|
||||
_cleanTextureProgramObject = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void AtmosphereDeferredcaster::createComputationTextures() {
|
||||
@@ -1163,15 +1078,15 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
_deltaJProgramObject->setUniform("firstIteraction", 0);
|
||||
transmittanceTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _transmittanceTableTexture);
|
||||
_deltaJProgramObject->setUniform("transmittanceTexture", transmittanceTableTextureUnit);
|
||||
deltaETableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _deltaETableTexture);
|
||||
_deltaJProgramObject->setUniform("deltaETexture", deltaETableTextureUnit);
|
||||
deltaSRayleighTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_3D, _deltaSRayleighTableTexture);
|
||||
_deltaJProgramObject->setUniform("deltaSRTexture", deltaSRayleighTableTextureUnit);
|
||||
deltaSMieTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_3D, _deltaSMieTableTexture);
|
||||
_deltaJProgramObject->setUniform("transmittanceTexture", transmittanceTableTextureUnit);
|
||||
_deltaJProgramObject->setUniform("deltaETexture", deltaETableTextureUnit);
|
||||
_deltaJProgramObject->setUniform("deltaSRTexture", deltaSRayleighTableTextureUnit);
|
||||
_deltaJProgramObject->setUniform("deltaSMTexture", deltaSMieTableTextureUnit);
|
||||
loadAtmosphereDataIntoShaderProgram(_deltaJProgramObject);
|
||||
for (int layer = 0; layer < R_SAMPLES; ++layer) {
|
||||
@@ -1201,12 +1116,12 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
_irradianceSupTermsProgramObject->setUniform("firstIteraction", (int)0);
|
||||
transmittanceTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _transmittanceTableTexture);
|
||||
_irradianceSupTermsProgramObject->setUniform("transmittanceTexture", transmittanceTableTextureUnit);
|
||||
deltaSRayleighTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_3D, _deltaSRayleighTableTexture);
|
||||
_irradianceSupTermsProgramObject->setUniform("deltaSRTexture", deltaSRayleighTableTextureUnit);
|
||||
deltaSMieTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_3D, _deltaSMieTableTexture);
|
||||
_irradianceSupTermsProgramObject->setUniform("transmittanceTexture", transmittanceTableTextureUnit);
|
||||
_irradianceSupTermsProgramObject->setUniform("deltaSRTexture", deltaSRayleighTableTextureUnit);
|
||||
_irradianceSupTermsProgramObject->setUniform("deltaSMTexture", deltaSMieTableTextureUnit);
|
||||
loadAtmosphereDataIntoShaderProgram(_irradianceSupTermsProgramObject);
|
||||
renderQuadForCalc(quadCalcVAO, vertexSize);
|
||||
@@ -1233,9 +1148,9 @@ void AtmosphereDeferredcaster::executeCalculations(const GLuint quadCalcVAO,
|
||||
_inScatteringSupTermsProgramObject->setUniform("firstIteraction", (int)0);*/
|
||||
transmittanceTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _transmittanceTableTexture);
|
||||
deltaJTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_3D, _deltaJTableTexture);
|
||||
_inScatteringSupTermsProgramObject->setUniform("transmittanceTexture", transmittanceTableTextureUnit);
|
||||
deltaJTableTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_3D, _deltaJTableTexture);
|
||||
_inScatteringSupTermsProgramObject->setUniform("deltaJTexture", deltaJTableTextureUnit);
|
||||
loadAtmosphereDataIntoShaderProgram(_inScatteringSupTermsProgramObject);
|
||||
for (int layer = 0; layer < R_SAMPLES; ++layer) {
|
||||
|
||||
@@ -139,7 +139,6 @@ private:
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _deltaJProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _atmosphereProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _deferredAtmosphereProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _cleanTextureProgramObject;
|
||||
|
||||
GLuint _transmittanceTableTexture;
|
||||
GLuint _irradianceTableTexture;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -72,38 +72,6 @@ namespace openspace {
|
||||
bool isShadowing;
|
||||
};
|
||||
|
||||
// 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 TRANSMITTANCE_TABLE_WIDTH = 512;
|
||||
const unsigned int TRANSMITTANCE_TABLE_HEIGHT = 128;
|
||||
|
||||
const unsigned int IRRADIANCE_TABLE_WIDTH = 128;
|
||||
const unsigned int IRRADIANCE_TABLE_HEIGHT = 32;
|
||||
|
||||
const unsigned int DELTA_E_TABLE_WIDTH = 128;
|
||||
const unsigned int DELTA_E_TABLE_HEIGHT = 32;*/
|
||||
|
||||
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;
|
||||
|
||||
/*const unsigned int R_SAMPLES = 64;
|
||||
const unsigned int MU_SAMPLES = 256;
|
||||
const unsigned int MU_S_SAMPLES = 64;
|
||||
const unsigned int NU_SAMPLES = 16;*/
|
||||
|
||||
public:
|
||||
explicit RenderablePlanetAtmosphere(const ghoul::Dictionary& dictionary);
|
||||
~RenderablePlanetAtmosphere();
|
||||
@@ -121,23 +89,8 @@ namespace openspace {
|
||||
private:
|
||||
void computeModelTransformMatrix(glm::mat4 * modelTransform);
|
||||
void computeModelTransformMatrix(glm::dmat4 * modelTransform);
|
||||
void loadComputationPrograms();
|
||||
void unloadComputationPrograms();
|
||||
void createComputationTextures();
|
||||
void deleteComputationTextures();
|
||||
void deleteUnusedComputationTextures();
|
||||
void updateAtmosphereParameters();
|
||||
void loadAtmosphereDataIntoShaderProgram(std::unique_ptr<ghoul::opengl::ProgramObject> & shaderProg);
|
||||
void executeCalculations(const GLuint quadCalcVAO, const GLenum drawBuffers[1], const GLsizei vertexSize);
|
||||
void preCalculateAtmosphereParam();
|
||||
void resetAtmosphereTextures(const GLuint vao, const GLenum drawBuffers[1], const GLsizei vertexSize);
|
||||
void createAtmosphereFBO();
|
||||
void createRenderQuad(GLuint * vao, GLuint * vbo, const GLfloat size);
|
||||
void renderQuadForCalc(const GLuint vao, const GLsizei numberOfVertices);
|
||||
void step3DTexture(std::unique_ptr<ghoul::opengl::ProgramObject> & shaderProg,
|
||||
const int layer, const bool doCalc = true);
|
||||
void saveTextureToPPMFile(const GLenum color_buffer_attachment, const std::string & fileName,
|
||||
const int width, const int height) const;
|
||||
void checkFrameBufferState(const std::string & codePosition) const;
|
||||
|
||||
|
||||
@@ -145,52 +98,16 @@ namespace openspace {
|
||||
properties::StringProperty _colorTexturePath;
|
||||
properties::StringProperty _nightTexturePath;
|
||||
properties::StringProperty _heightMapTexturePath;
|
||||
properties::StringProperty _cloudsTexturePath;
|
||||
properties::StringProperty _reflectanceTexturePath;
|
||||
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _programObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _transmittanceProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _irradianceProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _irradianceSupTermsProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _irradianceFinalProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _inScatteringProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _inScatteringSupTermsProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _deltaEProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _deltaSProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _deltaSSupTermsProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _deltaJProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _atmosphereProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _deferredAtmosphereProgramObject;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _cleanTextureProgramObject;
|
||||
|
||||
|
||||
std::unique_ptr<ghoul::opengl::Texture> _texture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _nightTexture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _reflectanceTexture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _heightMapTexture;
|
||||
std::unique_ptr<ghoul::opengl::Texture> _cloudsTexture;
|
||||
|
||||
GLuint _transmittanceTableTexture;
|
||||
GLuint _irradianceTableTexture;
|
||||
GLuint _inScatteringTableTexture;
|
||||
GLuint _deltaETableTexture;
|
||||
GLuint _deltaSRayleighTableTexture;
|
||||
GLuint _deltaSMieTableTexture;
|
||||
GLuint _deltaJTableTexture;
|
||||
GLuint _dummyTexture;
|
||||
GLuint _atmosphereTexture;
|
||||
GLuint _atmosphereDepthTexture;
|
||||
|
||||
GLuint _cameraDistanceTexture;
|
||||
|
||||
// Deferred debug rendering
|
||||
GLuint _atmosphereFBO;
|
||||
GLuint _atmosphereRenderVAO;
|
||||
GLuint _atmosphereRenderVBO;
|
||||
|
||||
properties::FloatProperty _heightExaggeration;
|
||||
|
||||
std::unique_ptr<planetgeometry::PlanetGeometry> _geometry;
|
||||
planetgeometry::PlanetGeometry* _atmosphereGeometry;
|
||||
properties::BoolProperty _performShading;
|
||||
properties::IntProperty _rotation;
|
||||
|
||||
@@ -209,11 +126,6 @@ namespace openspace {
|
||||
properties::FloatProperty _sunIntensityP;
|
||||
properties::FloatProperty _hdrExpositionP;
|
||||
|
||||
|
||||
// DEBUG Properties:
|
||||
properties::BoolProperty _saveDeferredFramebuffer;
|
||||
|
||||
|
||||
float _alpha;
|
||||
std::vector< ShadowConf > _shadowConfArray;
|
||||
float _planetRadius;
|
||||
@@ -222,14 +134,11 @@ namespace openspace {
|
||||
std::string _frame;
|
||||
std::string _target;
|
||||
bool _hasNightTexture;
|
||||
bool _hasReflectanceTexture;
|
||||
bool _hasHeightTexture;
|
||||
bool _hasCloudsTexture;
|
||||
bool _shadowEnabled;
|
||||
double _time;
|
||||
|
||||
// Atmosphere Data
|
||||
bool _atmosphereCalculated;
|
||||
bool _atmosphereEnabled;
|
||||
float _atmosphereRadius;
|
||||
float _atmospherePlanetRadius;
|
||||
@@ -243,11 +152,6 @@ namespace openspace {
|
||||
glm::vec3 _rayleighScatteringCoeff;
|
||||
glm::vec3 _mieScatteringCoeff;
|
||||
|
||||
|
||||
bool tempPic;
|
||||
|
||||
unsigned int count;
|
||||
|
||||
// Testing Deferredcast
|
||||
std::unique_ptr<AtmosphereDeferredcaster> _deferredcaster;
|
||||
|
||||
|
||||
@@ -72,12 +72,12 @@ const int SAMPLES_NU = 8;
|
||||
uniform sampler2D transmittanceTexture;
|
||||
|
||||
float opticalDepth(float H, float r, float mu, float d) {
|
||||
float a = sqrt((0.5/H)*r);
|
||||
vec2 a01 = a*vec2(mu, mu + d / r);
|
||||
vec2 a01s = sign(a01);
|
||||
float a = sqrt((0.5/H)*r);
|
||||
vec2 a01 = a*vec2(mu, mu + d / r);
|
||||
vec2 a01s = sign(a01);
|
||||
vec2 a01sq = a01*a01;
|
||||
float x = a01s.y > a01s.x ? exp(a01sq.x) : 0.0;
|
||||
vec2 y = a01s / (2.3193*abs(a01) + sqrt(1.52*a01sq + 4.0)) * vec2(1.0, exp(-d/H*(d/(2.0*r)+mu)));
|
||||
float x = a01s.y > a01s.x ? exp(a01sq.x) : 0.0;
|
||||
vec2 y = a01s / (2.3193*abs(a01) + sqrt(1.52*a01sq + 4.0)) * vec2(1.0, exp(-d/H*(d/(2.0*r)+mu)));
|
||||
return sqrt((6.2831*H)*r) * exp((Rg-r)/H) * (x + dot(y, vec2(1.0, -1.0)));
|
||||
}
|
||||
|
||||
|
||||
@@ -33,9 +33,8 @@
|
||||
//uniform sampler2D reflectanceTexture;
|
||||
uniform sampler2D irradianceTexture;
|
||||
uniform sampler3D inscatterTexture;
|
||||
|
||||
uniform sampler2DMS mainDepthTexture;
|
||||
//uniform sampler2DMS mainColorTexture;
|
||||
// uniform sampler2DMS mainDepthTexture;
|
||||
// uniform sampler2DMS mainColorTexture;
|
||||
|
||||
uniform int nAaSamples;
|
||||
|
||||
@@ -44,6 +43,7 @@ out vec4 renderTarget;
|
||||
|
||||
in vec3 interpolatedNDCPos;
|
||||
|
||||
uniform dmat4 ModelTransformMatrix;
|
||||
//uniform dmat4 dSgctProjectionMatrix;
|
||||
uniform dmat4 dInverseTransformMatrix;
|
||||
//uniform dmat4 dScaleTransformMatrix;
|
||||
@@ -82,9 +82,72 @@ struct dRay {
|
||||
|
||||
struct Ellipsoid {
|
||||
dvec4 center;
|
||||
dvec4 size;
|
||||
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):
|
||||
@@ -227,7 +290,7 @@ vec3 inscatterNoTestRadiance(inout vec3 x, inout float t, const vec3 v, const ve
|
||||
float Rt2 = Rt * Rt;
|
||||
float Rg2 = Rg * Rg;
|
||||
|
||||
// Intersects atmosphere?
|
||||
// Inside or on top of atmosphere?
|
||||
if (r <= Rt+0.1) {
|
||||
float nu = dot(v, s);
|
||||
float muSun = dot(x, s) / r;
|
||||
@@ -669,18 +732,20 @@ vec3 sunColor(const vec3 x, const float t, const vec3 v, const vec3 s, const flo
|
||||
|
||||
void main() {
|
||||
// Acessing Depth Buffer.
|
||||
float geoDepth = 0.0;
|
||||
//vec4 colorMean = vec4(0.0);
|
||||
for (int i = 0; i < nAaSamples; i++) {
|
||||
geoDepth += denormalizeFloat(texelFetch(mainDepthTexture, ivec2(gl_FragCoord), i).x);
|
||||
//colorMean += texelFetch(mainColorTexture, ivec2(gl_FragCoord), i);
|
||||
}
|
||||
geoDepth /= nAaSamples;
|
||||
//colorMean /= nAaSamples;
|
||||
// float geoDepth = 0.0;
|
||||
// vec4 colorMean = vec4(0.0);
|
||||
// for (int i = 0; i < nAaSamples; i++) {
|
||||
// geoDepth += denormalizeFloat(texelFetch(mainDepthTexture, ivec2(gl_FragCoord), i).x);
|
||||
// colorMean += texelFetch(mainColorTexture, ivec2(gl_FragCoord), i);
|
||||
// }
|
||||
// geoDepth /= nAaSamples;
|
||||
// colorMean /= nAaSamples;
|
||||
|
||||
// Ray in object space
|
||||
dRay ray;
|
||||
dvec4 planetPositionObjectCoords = dvec4(0.0);
|
||||
//dvec4 planetPositionObjectCoords = dInverseTransformMatrix * dvec4(-dObjpos.xyz + dObjpos.xyz, 1.0);
|
||||
//dvec4 planetPositionObjectCoords = dInverseTransformMatrix * dvec4(-dObjpos.xyz + dvec3(0.0), 1.0);
|
||||
dCalculateRay2(ray, planetPositionObjectCoords);
|
||||
//dCalculateInterpolatedRay(ray, planetPositionObjectCoords);
|
||||
|
||||
@@ -688,8 +753,35 @@ void main() {
|
||||
double offset = 0.0;
|
||||
double maxLength = 0.0;
|
||||
bool intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, ray, Rt+EPSILON,
|
||||
insideATM, offset, maxLength );
|
||||
insideATM, offset, maxLength );
|
||||
|
||||
//bool intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, ray, Rg,
|
||||
// insideATM, offset, maxLength );
|
||||
// Ellipsoid ellipsoid;
|
||||
// ellipsoid.center = dvec4(0.0);
|
||||
// ellipsoid.size = dvec3(6378.1, 6356.8, 6378.1);
|
||||
// bool intersectATM = dIntersectEllipsoid(ray, ellipsoid, 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.x *= 1.0/6378.1;
|
||||
// transfRay.direction.x *= 1.0/6378.1;
|
||||
// transfRay.origin.y *= 1.0/6356.8;
|
||||
// transfRay.direction.y *= 1.0/6356.8;
|
||||
// transfRay.origin.z *= 1.0/1.0/6378.1;
|
||||
// transfRay.direction.z *= 1.0/1.0/6378.1;
|
||||
// transfRay.direction.xyz = normalize(transfRay.direction.xyz);
|
||||
// bool intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, transfRay, 1.0,
|
||||
// insideATM, offset, maxLength );
|
||||
|
||||
// bool intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, transfRay, Rt+EPSILON,
|
||||
// insideATM, offset, maxLength );
|
||||
|
||||
if ( intersectATM ) {
|
||||
//renderTarget += vec4(1.0, 1.0, 1.0, 0.5);
|
||||
// Following paper nomenclature
|
||||
double t = 0.0;
|
||||
if ( offset != -1.0 ) {
|
||||
@@ -717,8 +809,8 @@ void main() {
|
||||
float tF = float(maxLength - offset);
|
||||
|
||||
vec3 inscatterColor = inscatterNoTestRadiance(x, tF, v, s, r, mu, attenuation);
|
||||
vec3 groundColor = groundColor(x, tF, v, s, r, mu, attenuation);
|
||||
vec3 sunColor = sunColor(x, tF, v, s, r, mu);
|
||||
vec3 groundColor = groundColor(x, tF, v, s, r, mu, attenuation);
|
||||
vec3 sunColor = sunColor(x, tF, v, s, r, mu);
|
||||
|
||||
//renderTarget = vec4(HDR(inscatterColor), 1.0);
|
||||
//renderTarget = vec4(HDR(groundColor), 1.0);
|
||||
@@ -736,14 +828,13 @@ void main() {
|
||||
|
||||
//renderTarget = finalRadiance + colorMean;
|
||||
renderTarget = finalRadiance;
|
||||
|
||||
//renderTarget = colorMean;
|
||||
//renderTarget += vec4(0.5, 0.0, 0.0, 0.5);
|
||||
//renderTarget = vec4(0.0);
|
||||
} else {
|
||||
renderTarget = vec4(1.0, 1.0, 1.0, 0.0);
|
||||
renderTarget = vec4(1.0, 1.0, 0.0, 0.0);
|
||||
//renderTarget = vec4(0.0);
|
||||
//renderTarget = colorMean;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,10 @@ void FramebufferRenderer::initialize() {
|
||||
glGenTextures(1, &_exitDepthTexture);
|
||||
glGenFramebuffers(1, &_exitFramebuffer);
|
||||
|
||||
// Deferred framebuffer
|
||||
glGenTextures(1, &_deferredColorTexture);
|
||||
glGenFramebuffers(1, &_deferredFramebuffer);
|
||||
|
||||
updateResolution();
|
||||
updateRendererData();
|
||||
updateRaycastData();
|
||||
@@ -109,13 +113,26 @@ void FramebufferRenderer::initialize() {
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, _mainColorTexture, 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D_MULTISAMPLE, _mainDepthTexture, 0);
|
||||
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LERROR("Main framebuffer is not complete");
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _exitFramebuffer);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _exitColorTexture, 0);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, _exitDepthTexture, 0);
|
||||
|
||||
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LERROR("Main framebuffer is not complete");
|
||||
LERROR("Exit framebuffer is not complete");
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _deferredFramebuffer);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _deferredColorTexture, 0);
|
||||
|
||||
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
if (status != GL_FRAMEBUFFER_COMPLETE) {
|
||||
LERROR("Deferred framebuffer is not complete");
|
||||
}
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, defaultFbo);
|
||||
@@ -137,11 +154,13 @@ void FramebufferRenderer::deinitialize() {
|
||||
|
||||
glDeleteFramebuffers(1, &_mainFramebuffer);
|
||||
glDeleteFramebuffers(1, &_exitFramebuffer);
|
||||
glDeleteFramebuffers(1, &_deferredFramebuffer);
|
||||
|
||||
glDeleteTextures(1, &_mainColorTexture);
|
||||
glDeleteTextures(1, &_mainDepthTexture);
|
||||
glDeleteTextures(1, &_exitColorTexture);
|
||||
glDeleteTextures(1, &_exitDepthTexture);
|
||||
glDeleteTextures(1, &_deferredColorTexture);
|
||||
|
||||
glDeleteBuffers(1, &_vertexPositionBuffer);
|
||||
glDeleteVertexArrays(1, &_screenQuad);
|
||||
@@ -279,6 +298,21 @@ void FramebufferRenderer::updateResolution() {
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, _deferredColorTexture);
|
||||
glTexImage2D(
|
||||
GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA32F,
|
||||
GLsizei(_resolution.x),
|
||||
GLsizei(_resolution.y),
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_SHORT,
|
||||
nullptr);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
|
||||
_dirtyResolution = false;
|
||||
}
|
||||
|
||||
@@ -515,6 +549,9 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
|
||||
Deferredcaster* deferredcaster = deferredcasterTask.deferredcaster;
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, _mainFramebuffer);
|
||||
//glBindFramebuffer(GL_FRAMEBUFFER, _deferredFramebuffer);
|
||||
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
ghoul::opengl::ProgramObject* deferredcastProgram = nullptr;
|
||||
|
||||
if (deferredcastProgram == _deferredcastPrograms[deferredcaster].get()) {
|
||||
@@ -529,10 +566,10 @@ void FramebufferRenderer::render(float blackoutFactor, bool doPerformanceMeasure
|
||||
_deferredcastData[deferredcaster],
|
||||
*deferredcastProgram);
|
||||
|
||||
ghoul::opengl::TextureUnit mainDepthTextureUnit;
|
||||
mainDepthTextureUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _mainDepthTexture);
|
||||
deferredcastProgram->setUniform("mainDepthTexture", mainDepthTextureUnit);
|
||||
// ghoul::opengl::TextureUnit mainDepthTextureUnit;
|
||||
// mainDepthTextureUnit.activate();
|
||||
// glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, _mainDepthTexture);
|
||||
// deferredcastProgram->setUniform("mainDepthTexture", mainDepthTextureUnit);
|
||||
|
||||
// ghoul::opengl::TextureUnit mainColorTextureUnit;
|
||||
// mainColorTextureUnit.activate();
|
||||
|
||||
Reference in New Issue
Block a user