mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 04:00:37 -06:00
Change rendering of patches to map to ellipsoids instead of spheres.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user