From 8d95bf05cef09cef8f66db462f501ce94391c4e6 Mon Sep 17 00:00:00 2001 From: Jonathas Costa Date: Fri, 12 May 2017 17:53:48 -0400 Subject: [PATCH] Fixed Mars wrong radius. Added debug messages. --- data/scene/atmosphereearth.scene | 6 +-- data/scene/lodglobes/mars/mars.mod | 4 +- data/scene/mars/mars.mod | 2 +- .../rendering/atmospheredeferredcaster.cpp | 15 +++++--- .../atmosphere/shaders/deferred_test_fs.glsl | 38 +++++++++---------- 5 files changed, 35 insertions(+), 30 deletions(-) diff --git a/data/scene/atmosphereearth.scene b/data/scene/atmosphereearth.scene index 8f41e03f49..eb042eb193 100644 --- a/data/scene/atmosphereearth.scene +++ b/data/scene/atmosphereearth.scene @@ -67,8 +67,8 @@ return { ScenePath = ".", CommonFolder = "common", Camera = { - Focus = "Earth", - --Focus = "Mars", + --Focus = "Earth", + Focus = "Mars", --Position = {526781518487.171326, 257168309890.072144, -1381125204152.817383}, --Rotation = {-0.106166, 0.981574, -0.084545, 0.134513}, --Position = {-21230341452.764542, -75199905816.520981, 126295587136.952240}, @@ -82,7 +82,7 @@ return { }, Modules = { "sun", - "atmosphereearth", + --"atmosphereearth", --"lodglobes/earth", --"lodglobes/moon", --"moon", diff --git a/data/scene/lodglobes/mars/mars.mod b/data/scene/lodglobes/mars/mars.mod index 08a854f60a..07ed0a1ddd 100644 --- a/data/scene/lodglobes/mars/mars.mod +++ b/data/scene/lodglobes/mars/mars.mod @@ -37,8 +37,8 @@ return { InteractionDepthBelowEllipsoid = 10000, -- Useful when having negative height map values Atmosphere = { -- Atmosphere radius in Km - AtmoshereRadius = 6410, - PlanetRadius = 6390.0, + AtmoshereRadius = 3416.0, + PlanetRadius = 3396.19, PlanetAverageGroundReflectance = 0.1, Rayleigh = { Coefficients = { diff --git a/data/scene/mars/mars.mod b/data/scene/mars/mars.mod index 301f510e5f..e3b11debc8 100644 --- a/data/scene/mars/mars.mod +++ b/data/scene/mars/mars.mod @@ -22,7 +22,7 @@ return { Body = "MARS BARYCENTER", Geometry = { Type = "SimpleSphere", - Radius = 6.390E6, + Radius = 3.390E6, Segments = 100 }, Textures = { diff --git a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp index 785d2f78f0..c5fb160be5 100644 --- a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp +++ b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp @@ -229,7 +229,7 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData & renderData, const D SpiceManager::ref().targetPosition("SUN", "SUN", "GALACTIC", {}, _time, lt); glm::dvec4 sunPosObj = glm::inverse(_modelTransform) * glm::dvec4(sunPosWorld - renderData.position.dvec3(), 1.0); - program.setUniform("ellipsoidRadii", _ellipsoidRadii); + program.setUniform("ellipsoidRadii", _ellipsoidRadii); //program.setUniform("sunPositionObj", sunPosObj); program.setUniform("sunDirectionObj", glm::normalize(glm::dvec3(sunPosObj))); @@ -248,13 +248,18 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData & renderData, const D ghoul::opengl::TextureUnit inScatteringTableTextureUnit; inScatteringTableTextureUnit.activate(); glBindTexture(GL_TEXTURE_3D, _inScatteringTableTexture); - program.setUniform("inscatterTexture", inScatteringTableTextureUnit); + program.setUniform("inscatterTexture", inScatteringTableTextureUnit); // DEBUG: - //glm::dvec3 objP = glm::dvec3(renderData.position[0] * pow(10, renderData.position[3]), - // renderData.position[1] * pow(10, renderData.position[3]), renderData.position[2] * pow(10, renderData.position[3])); - //glm::dvec4 cameraP = glm::inverse(glm::dmat4(_modelTransform)) * glm::dvec4(-objP + renderData.camera.positionVec3(), 1.0); + glm::dvec3 objP = glm::dvec3(renderData.position[0] * pow(10, renderData.position[3]), + renderData.position[1] * pow(10, renderData.position[3]), renderData.position[2] * pow(10, renderData.position[3])); + glm::dvec4 cameraP = glm::inverse(glm::dmat4(_modelTransform)) * glm::dvec4(-objP + renderData.camera.positionVec3(), 1.0); + //std::cout << "====== Planet's position in KM: " << glm::to_string( objP/glm::dvec3(1000.0, 1000.0, 1000.0) ) << " =======" << std::endl; + + //std::cout << "====== ModelTransform: " << glm::to_string(_modelTransform) << std::endl; //std::cout << "====== Distance from Planet's ground in KM: " << glm::length(glm::dvec3(cameraP / glm::dvec4(1000.0, 1000.0, 1000.0, 1.0))) - _atmospherePlanetRadius << " =======" << std::endl; + //std::cout << "====== Camera Position: " << glm::to_string(renderData.camera.positionVec3()) << " =====" << std::endl; + //std::cout << "--- Ellipsoid Radii: " << glm::to_string(_ellipsoidRadii) << " ----" << std::endl; } void AtmosphereDeferredcaster::postRaycast(const RenderData & renderData, const DeferredcastData& deferredData, diff --git a/modules/atmosphere/shaders/deferred_test_fs.glsl b/modules/atmosphere/shaders/deferred_test_fs.glsl index 81b344f077..80b84a0602 100644 --- a/modules/atmosphere/shaders/deferred_test_fs.glsl +++ b/modules/atmosphere/shaders/deferred_test_fs.glsl @@ -767,29 +767,29 @@ void main() { bool intersectATM = false; - if ( ellipsoidRadii.x != 0.0 || ellipsoidRadii.y != 0.0 || ellipsoidRadii.z != 0.0) { - // Instead of ray-ellipsoid intersection lets transform the ray to a sphere: - dRay transfRay; - transfRay.origin = ray.origin; - transfRay.direction = ray.direction; + // if ( ellipsoidRadii.x != 0.0 || ellipsoidRadii.y != 0.0 || ellipsoidRadii.z != 0.0) { + // // 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 *= 1000.0/ellipsoidRadii.x; - transfRay.direction.x *= 1000.0/ellipsoidRadii.x; - transfRay.origin.z *= 1000.0/ellipsoidRadii.y; - transfRay.direction.z *= 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); + // transfRay.origin.x *= 1000.0/ellipsoidRadii.x; + // transfRay.direction.x *= 1000.0/ellipsoidRadii.x; + // transfRay.origin.y *= 1000.0/ellipsoidRadii.y; + // transfRay.direction.y *= 1000.0/ellipsoidRadii.y; + // transfRay.origin.z *= 1000.0/ellipsoidRadii.z; + // transfRay.direction.z *= 1000.0/ellipsoidRadii.z; + // transfRay.direction.xyz = normalize(transfRay.direction.xyz); - // intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, transfRay, 1.0 + EPSILON, - // insideATM, offset, maxLength ); + // intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, transfRay, 1.0, + // insideATM, offset, maxLength ); - intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, transfRay, Rt+EPSILON, - insideATM, offset, maxLength ); - } else { - intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, ray, Rt-10*EPSILON, + // //intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, transfRay, Rt+EPSILON, + // // insideATM, offset, maxLength ); + // } else { + intersectATM = dAtmosphereIntersection(planetPositionObjectCoords.xyz, ray, Rt-10*EPSILON, insideATM, offset, maxLength ); - } + //} if ( intersectATM ) { // Now we check is if the atmosphere is occluded, i.e., if the distance to the pixel