diff --git a/modules/globebrowsing/geodetics/ellipsoid.cpp b/modules/globebrowsing/geodetics/ellipsoid.cpp index 23a0f78a3d..9b7c4b2267 100644 --- a/modules/globebrowsing/geodetics/ellipsoid.cpp +++ b/modules/globebrowsing/geodetics/ellipsoid.cpp @@ -114,6 +114,23 @@ namespace openspace { sin(geodetic2.lat)); } + // TODO: IMPLEMENT THESE FUNCTIONS AND SEND RADIISQUARED TO THE SHADER PROGRAM + + Vec3 Ellipsoid::radiiSquared() const + { + return _cachedValues._radiiSquared; + } + + Vec3 Ellipsoid::oneOverRadiiSquared() const + { + return _cachedValues._oneOverRadiiSquared; + } + + Vec3 Ellipsoid::radiiToTheFourth() const + { + return _cachedValues._radiiToTheFourth; + } + Scalar Ellipsoid::minimumRadius() const { return _cachedValues._minimumRadius; diff --git a/modules/globebrowsing/geodetics/ellipsoid.h b/modules/globebrowsing/geodetics/ellipsoid.h index 3f79a7307e..c941862678 100644 --- a/modules/globebrowsing/geodetics/ellipsoid.h +++ b/modules/globebrowsing/geodetics/ellipsoid.h @@ -69,12 +69,17 @@ public: Vec3 geodeticSurfaceNormal(const Vec3& p) const; Vec3 geodeticSurfaceNormal(Geodetic2 geodetic2) const; + + Vec3 radiiSquared() const; + Vec3 oneOverRadiiSquared() const; + Vec3 radiiToTheFourth() const; Scalar minimumRadius() const; Geodetic2 cartesianToGeodetic2(const Vec3& p) const; Vec3 geodetic2ToCartesian(const Geodetic2& geodetic2) const; Vec3 geodetic3ToCartesian(const Geodetic3& geodetic3) const; +private: struct EllipsoidCache { const Vec3 _radiiSquared; @@ -85,9 +90,6 @@ public: const Vec3 _radii; const EllipsoidCache _cachedValues; -private: - - }; } // namespace openspace diff --git a/modules/globebrowsing/globes/renderableglobe.cpp b/modules/globebrowsing/globes/renderableglobe.cpp index 904adfa57e..5e9d3b4518 100644 --- a/modules/globebrowsing/globes/renderableglobe.cpp +++ b/modules/globebrowsing/globes/renderableglobe.cpp @@ -52,7 +52,7 @@ namespace openspace { RenderableGlobe::RenderableGlobe(const ghoul::Dictionary& dictionary) : DistanceSwitch() , _rotation("rotation", "Rotation", 0, 0, 360) - , _ellipsoid(Vec3(6.3e6)) + , _ellipsoid(Vec3(6378137.0, 6378137.0, 6356752.314245)) // Earth's radii { std::string name; bool success = dictionary.getValue(SceneGraphNode::KeyName, name); diff --git a/modules/globebrowsing/meshes/trianglesoup.cpp b/modules/globebrowsing/meshes/trianglesoup.cpp index 0d47924209..33ac249a1e 100644 --- a/modules/globebrowsing/meshes/trianglesoup.cpp +++ b/modules/globebrowsing/meshes/trianglesoup.cpp @@ -165,14 +165,10 @@ void TriangleSoup::drawUsingActiveProgram() { if (_gpuDataNeedUpdate) { updateDataInGPU(); } - glBindVertexArray(_vaoID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _elementBufferID); - //glDisable(GL_CULL_FACE); - //glCullFace(GL_FRONT); glDrawElements(GL_TRIANGLES, _elementData.size(), GL_UNSIGNED_INT, 0); glBindVertexArray(0); - //glCullFace(GL_BACK); } } // namespace openspace \ No newline at end of file diff --git a/modules/globebrowsing/other/patchrenderer.cpp b/modules/globebrowsing/other/patchrenderer.cpp index 910263bf97..931078ea9c 100644 --- a/modules/globebrowsing/other/patchrenderer.cpp +++ b/modules/globebrowsing/other/patchrenderer.cpp @@ -149,9 +149,7 @@ namespace openspace { _programObject->setUniform("modelViewProjectionTransform", modelViewProjectionTransform); _programObject->setUniform("minLatLon", vec2(swCorner.toLonLatVec2())); _programObject->setUniform("lonLatScalingFactor", vec2(patch.size().toLonLatVec2())); - - // TODO : SEND ALL RADII TO GPU FOR RENDERING - _programObject->setUniform("globeRadius", float(glm::length(ellipsoid.geodetic2ToCartesian(Geodetic2(0,0))))); + _programObject->setUniform("radiiSquared", vec3(ellipsoid.radiiSquared())); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); @@ -242,9 +240,7 @@ namespace openspace { _programObject->setUniform("segmentsPerPatch", segmentsPerPatch); _programObject->setUniform("minLatLon", vec2(newPatch.southWestCorner().toLonLatVec2())); _programObject->setUniform("lonLatScalingFactor", vec2(patchSize.toLonLatVec2())); - - // TODO : SEND ALL RADII TO GPU FOR RENDERING! - _programObject->setUniform("globeRadius", float(glm::length(ellipsoid.geodetic2ToCartesian(Geodetic2(0, 0))))); + _programObject->setUniform("radiiSquared", vec3(ellipsoid.radiiSquared())); _programObject->setUniform("contraction", contraction); glEnable(GL_DEPTH_TEST); diff --git a/modules/globebrowsing/shaders/clipmappatch_spheremapping_vs.glsl b/modules/globebrowsing/shaders/clipmappatch_spheremapping_vs.glsl index cbe2a899e4..e4017013fd 100644 --- a/modules/globebrowsing/shaders/clipmappatch_spheremapping_vs.glsl +++ b/modules/globebrowsing/shaders/clipmappatch_spheremapping_vs.glsl @@ -25,7 +25,7 @@ #version __CONTEXT__ uniform mat4 modelViewProjectionTransform; -uniform float globeRadius; +uniform vec3 radiiSquared; uniform vec2 minLatLon; uniform vec2 lonLatScalingFactor; @@ -38,6 +38,34 @@ out vec2 vs_uv; #include "PowerScaling/powerScaling_vs.hglsl" +vec3 geodeticSurfaceNormal(float latitude, float longitude) +{ + float cosLat = cos(latitude); + return vec3( + cosLat * cos(longitude), + cosLat * sin(longitude), + sin(latitude)); +} + +vec3 geodetic3ToCartesian( + float latitude, + float longitude, + float height, + vec3 radiiSquared) +{ + vec3 normal = geodeticSurfaceNormal(latitude, longitude); + vec3 k = radiiSquared * normal; + float gamma = sqrt(dot(k, normal)); + vec3 rSurface = k / gamma; + return rSurface + height * normal; +} + +vec3 geodetic2ToCartesian(float latitude, float longitude, vec3 radiiSquared) +{ + // Position on surface : height = 0 + return geodetic3ToCartesian(latitude, longitude, 0, radiiSquared); +} + vec3 latLonToCartesian(float latitude, float longitude, float radius) { return radius * vec3( cos(latitude) * cos(longitude), @@ -49,7 +77,7 @@ vec3 globalInterpolation(vec2 uv) { vec2 lonLatInput; lonLatInput.y = minLatLon.y + lonLatScalingFactor.y * uv.y; // Lat lonLatInput.x = minLatLon.x + lonLatScalingFactor.x * uv.x; // Lon - vec3 positionModelSpace = latLonToCartesian(lonLatInput.y, lonLatInput.x, globeRadius); + vec3 positionModelSpace = geodetic2ToCartesian(lonLatInput.y, lonLatInput.x, radiiSquared);// latLonToCartesian(lonLatInput.y, lonLatInput.x, globeRadius); return positionModelSpace; } diff --git a/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl b/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl index 76248efcac..22bcbfef6a 100644 --- a/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl +++ b/modules/globebrowsing/shaders/latlonpatch_spheremapping_vs.glsl @@ -25,7 +25,7 @@ #version __CONTEXT__ uniform mat4 modelViewProjectionTransform; -uniform float globeRadius; +uniform vec3 radiiSquared; uniform vec2 minLatLon; uniform vec2 lonLatScalingFactor; @@ -37,6 +37,35 @@ out vec2 vs_uv; #include "PowerScaling/powerScaling_vs.hglsl" + +vec3 geodeticSurfaceNormal(float latitude, float longitude) +{ + float cosLat = cos(latitude); + return vec3( + cosLat * cos(longitude), + cosLat * sin(longitude), + sin(latitude)); +} + +vec3 geodetic3ToCartesian( + float latitude, + float longitude, + float height, + vec3 radiiSquared) +{ + vec3 normal = geodeticSurfaceNormal(latitude, longitude); + vec3 k = radiiSquared * normal; + float gamma = sqrt(dot(k, normal)); + vec3 rSurface = k / gamma; + return rSurface + height * normal; +} + +vec3 geodetic2ToCartesian(float latitude, float longitude, vec3 radiiSquared) +{ + // Position on surface : height = 0 + return geodetic3ToCartesian(latitude, longitude, 0, radiiSquared); +} + vec3 latLonToCartesian(float latitude, float longitude, float radius) { return radius * vec3( cos(latitude) * cos(longitude), @@ -48,7 +77,7 @@ vec3 globalInterpolation() { vec2 lonLatInput; lonLatInput.y = minLatLon.y + lonLatScalingFactor.y * in_UV.y; // Lat lonLatInput.x = minLatLon.x + lonLatScalingFactor.x * in_UV.x; // Lon - vec3 positionModelSpace = latLonToCartesian(lonLatInput.y, lonLatInput.x, globeRadius); + vec3 positionModelSpace = geodetic2ToCartesian(lonLatInput.y, lonLatInput.x, radiiSquared);// latLonToCartesian(lonLatInput.y, lonLatInput.x, globeRadius); return positionModelSpace; } diff --git a/modules/globebrowsing/shaders/simple_fs.glsl b/modules/globebrowsing/shaders/simple_fs.glsl index c8916ff68d..dd6dfbe913 100644 --- a/modules/globebrowsing/shaders/simple_fs.glsl +++ b/modules/globebrowsing/shaders/simple_fs.glsl @@ -51,9 +51,9 @@ Fragment getFragment() { Fragment frag; frag.color = texture(textureSampler, vec2(uvTransformPatchToTile * vec3(vs_uv.s, vs_uv.t, 1))); - frag.color = frag.color + vec4(vs_uv, 1, 1) * 0.3 + 0.999*texture(textureSampler, vs_uv); + frag.color = frag.color * 0.5 + 0.999*texture(textureSampler, vs_uv); - vec4 uvColor = vec4(fract(vs_uv * segmentsPerPatch), 0.4,1); + vec4 uvColor = vec4(fract(vs_uv * segmentsPerPatch / 10), 0.4,1); frag.color = frag.color.a < 0.1 ? uvColor * 0.5 : frag.color; frag.depth = pscDepth(vs_position);