mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-22 11:18:22 -05:00
Factor out tile vertex height calculation to separate shader file
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetilemapping.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tilevertexheight.hglsl>
|
||||
|
||||
uniform mat4 modelViewProjectionTransform;
|
||||
uniform mat4 modelViewTransform;
|
||||
@@ -35,32 +36,7 @@ uniform vec3 radiiSquared;
|
||||
|
||||
uniform vec2 minLatLon;
|
||||
uniform vec2 lonLatScalingFactor;
|
||||
|
||||
uniform int xSegments;
|
||||
uniform float skirtLength;
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
uniform Tile HeightMaps[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile HeightMapsParent1[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile HeightMapsParent2[NUMLAYERS_HEIGHTMAP];
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
#if USE_HEIGHTMAP_OVERLAY
|
||||
uniform Tile HeightMapOverlays[NUMLAYERS_HEIGHTMAP_OVERLAY];
|
||||
uniform Tile HeightMapOverlaysParent1[NUMLAYERS_HEIGHTMAP_OVERLAY];
|
||||
uniform Tile HeightMapOverlaysParent2[NUMLAYERS_HEIGHTMAP_OVERLAY];
|
||||
#endif // USE_HEIGHTMAP_OVERLAY
|
||||
|
||||
uniform vec3 cameraPosition;
|
||||
uniform float distanceScaleFactor;
|
||||
uniform int chunkLevel;
|
||||
|
||||
layout(location = 1) in vec2 in_uv;
|
||||
|
||||
out vec2 fs_uv;
|
||||
out vec4 fs_position;
|
||||
out vec3 ellipsoidNormalCameraSpace;
|
||||
out LevelWeights levelWeights;
|
||||
|
||||
PositionNormalPair globalInterpolation() {
|
||||
vec2 lonLatInput;
|
||||
@@ -70,50 +46,18 @@ PositionNormalPair globalInterpolation() {
|
||||
return positionPairModelSpace;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
void main() {
|
||||
PositionNormalPair pair = globalInterpolation();
|
||||
|
||||
float distToVertexOnEllipsoid = length(pair.position - cameraPosition);
|
||||
float projectedScaleFactor = distanceScaleFactor / distToVertexOnEllipsoid;
|
||||
float desiredLevel = log2(projectedScaleFactor);
|
||||
|
||||
float levelInterpolationParameter = chunkLevel - desiredLevel;
|
||||
levelWeights = getLevelWeights(levelInterpolationParameter);
|
||||
float height = 0;
|
||||
// Get the height value
|
||||
float height = getTileVertexHeight(distToVertexOnEllipsoid);
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
// Calculate desired level based on distance to the vertex on the ellipsoid
|
||||
// Before any heightmapping is done
|
||||
height = calculateHeight(
|
||||
in_uv,
|
||||
levelWeights, // Variable to determine which texture to sample from
|
||||
HeightMaps, HeightMapsParent1, HeightMapsParent2); // Three textures to sample from
|
||||
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
#if USE_HEIGHTMAP_OVERLAY
|
||||
height = calculateHeightOverlay(
|
||||
height,
|
||||
in_uv,
|
||||
levelWeights, // Variable to determine which texture to sample from
|
||||
HeightMapOverlays, HeightMapOverlaysParent1, HeightMapOverlaysParent2); // Three textures to sample from
|
||||
|
||||
#endif // USE_HEIGHTMAP_OVERLAY
|
||||
|
||||
// Skirts
|
||||
int vertexIDx = gl_VertexID % (xSegments + 3);
|
||||
int vertexIDy = gl_VertexID / (xSegments + 3);
|
||||
if (vertexIDx == 0 ||
|
||||
vertexIDy == 0 ||
|
||||
vertexIDx == (xSegments + 2) ||
|
||||
vertexIDy == (xSegments + 2) ) {
|
||||
height -= skirtLength;
|
||||
}
|
||||
// Apply skirts
|
||||
height -= getTileVertexSkirtLength();
|
||||
|
||||
// Add the height in the direction of the normal
|
||||
pair.position += pair.normal * height;
|
||||
|
||||
vec4 positionClippingSpace = modelViewProjectionTransform * vec4(pair.position, 1);
|
||||
|
||||
// Write output
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/ellipsoid.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetilemapping.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tilevertexheight.hglsl>
|
||||
|
||||
|
||||
uniform mat4 projectionTransform;
|
||||
|
||||
@@ -38,86 +40,27 @@ uniform vec3 p01;
|
||||
uniform vec3 p11;
|
||||
uniform vec3 patchNormalCameraSpace;
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
uniform Tile HeightMaps[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile HeightMapsParent1[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile HeightMapsParent2[NUMLAYERS_HEIGHTMAP];
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
#if USE_HEIGHTMAP_OVERLAY
|
||||
uniform Tile HeightMapOverlays[NUMLAYERS_HEIGHTMAP_OVERLAY];
|
||||
uniform Tile HeightMapOverlaysParent1[NUMLAYERS_HEIGHTMAP_OVERLAY];
|
||||
uniform Tile HeightMapOverlaysParent2[NUMLAYERS_HEIGHTMAP_OVERLAY];
|
||||
#endif // USE_HEIGHTMAP_OVERLAY
|
||||
|
||||
uniform int xSegments;
|
||||
uniform float skirtLength;
|
||||
|
||||
uniform float distanceScaleFactor;
|
||||
uniform int chunkLevel;
|
||||
|
||||
layout(location = 1) in vec2 in_uv;
|
||||
|
||||
out vec2 fs_uv;
|
||||
out vec4 fs_position;
|
||||
out vec3 ellipsoidNormalCameraSpace;
|
||||
|
||||
out LevelWeights levelWeights;
|
||||
|
||||
vec3 bilinearInterpolation(vec2 uv) {
|
||||
// Bilinear interpolation
|
||||
vec3 p0 = (1 - uv.x) * p00 + uv.x * p10;
|
||||
vec3 p1 = (1 - uv.x) * p01 + uv.x * p11;
|
||||
vec3 p = (1 - uv.y) * p0 + uv.y * p1;
|
||||
return p;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
void main() {
|
||||
|
||||
// Position in cameraspace
|
||||
vec3 p = bilinearInterpolation(in_uv);
|
||||
|
||||
float height = 0;
|
||||
|
||||
// Calculate desired level based on distance to the vertex on the ellipsoid
|
||||
// Before any heightmapping is done
|
||||
float distToVertexOnEllipsoid = length(p);
|
||||
float projectedScaleFactor = distanceScaleFactor / distToVertexOnEllipsoid;
|
||||
float desiredLevel = log2(projectedScaleFactor);
|
||||
|
||||
float levelInterpolationParameter = chunkLevel - desiredLevel;
|
||||
levelWeights = getLevelWeights(levelInterpolationParameter);
|
||||
// Get the height value
|
||||
float height = getTileVertexHeight(distToVertexOnEllipsoid);
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
|
||||
// Calculate desired level based on distance to the vertex on the ellipsoid
|
||||
// Before any heightmapping is done
|
||||
height = calculateHeight(
|
||||
in_uv,
|
||||
levelWeights, // Variable to determine which texture to sample from
|
||||
HeightMaps, HeightMapsParent1, HeightMapsParent2); // Three textures to sample from
|
||||
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
#if USE_HEIGHTMAP_OVERLAY
|
||||
// Calculate desired level based on distance to the vertex on the ellipsoid
|
||||
// Before any heightmapping is done
|
||||
height = calculateHeightOverlay(
|
||||
height,
|
||||
in_uv,
|
||||
levelWeights, // Variable to determine which texture to sample from
|
||||
HeightMapOverlays, HeightMapOverlaysParent1, HeightMapOverlaysParent2); // Three textures to sample from
|
||||
#endif // USE_HEIGHTMAP_OVERLAY
|
||||
|
||||
// Skirts
|
||||
int vertexIDx = gl_VertexID % (xSegments + 3);
|
||||
int vertexIDy = gl_VertexID / (xSegments + 3);
|
||||
if (vertexIDx == 0 ||
|
||||
vertexIDy == 0 ||
|
||||
vertexIDx == (xSegments + 2) ||
|
||||
vertexIDy == (xSegments + 2) ) {
|
||||
height -= skirtLength;
|
||||
}
|
||||
// Apply skirts
|
||||
height -= getTileVertexSkirtLength();
|
||||
|
||||
// Translate the point along normal
|
||||
p += patchNormalCameraSpace * height;
|
||||
|
||||
@@ -44,6 +44,7 @@ uniform Tile HeightMapOverlaysParent2[NUMLAYERS_HEIGHTMAP_OVERLAY];
|
||||
#endif // USE_HEIGHTMAP_OVERLAY
|
||||
|
||||
|
||||
|
||||
// Below are all the tiles that are used for contributing
|
||||
// the actual fragment color
|
||||
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.hglsl>
|
||||
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
uniform Tile HeightMaps[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile HeightMapsParent1[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile HeightMapsParent2[NUMLAYERS_HEIGHTMAP];
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
#if USE_HEIGHTMAP_OVERLAY
|
||||
uniform Tile HeightMapOverlays[NUMLAYERS_HEIGHTMAP_OVERLAY];
|
||||
uniform Tile HeightMapOverlaysParent1[NUMLAYERS_HEIGHTMAP_OVERLAY];
|
||||
uniform Tile HeightMapOverlaysParent2[NUMLAYERS_HEIGHTMAP_OVERLAY];
|
||||
#endif // USE_HEIGHTMAP_OVERLAY
|
||||
|
||||
uniform int xSegments;
|
||||
uniform float skirtLength;
|
||||
|
||||
uniform float distanceScaleFactor;
|
||||
uniform int chunkLevel;
|
||||
|
||||
layout(location = 1) in vec2 in_uv;
|
||||
|
||||
out vec2 fs_uv;
|
||||
out vec4 fs_position;
|
||||
out vec3 ellipsoidNormalCameraSpace;
|
||||
|
||||
out LevelWeights levelWeights;
|
||||
|
||||
float getTileVertexHeight(float distToVertexOnEllipsoid){
|
||||
float projectedScaleFactor = distanceScaleFactor / distToVertexOnEllipsoid;
|
||||
float desiredLevel = log2(projectedScaleFactor);
|
||||
|
||||
float levelInterpolationParameter = chunkLevel - desiredLevel;
|
||||
levelWeights = getLevelWeights(levelInterpolationParameter);
|
||||
|
||||
float height = 0;
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
// Calculate desired level based on distance to the vertex on the ellipsoid
|
||||
// Before any heightmapping is done
|
||||
height = calculateHeight(
|
||||
in_uv,
|
||||
levelWeights, // Variable to determine which texture to sample from
|
||||
HeightMaps, HeightMapsParent1, HeightMapsParent2); // Three textures to sample from
|
||||
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
#if USE_HEIGHTMAP_OVERLAY
|
||||
height = calculateHeightOverlay(
|
||||
height,
|
||||
in_uv,
|
||||
levelWeights, // Variable to determine which texture to sample from
|
||||
HeightMapOverlays, HeightMapOverlaysParent1, HeightMapOverlaysParent2); // Three textures to sample from
|
||||
|
||||
#endif // USE_HEIGHTMAP_OVERLAY
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
bool tileVertexIsSkirtVertex(){
|
||||
int vertexIDx = gl_VertexID % (xSegments + 3);
|
||||
int vertexIDy = gl_VertexID / (xSegments + 3);
|
||||
return vertexIDx == 0 || vertexIDy == 0 ||
|
||||
vertexIDx == (xSegments + 2) || vertexIDy == (xSegments + 2);
|
||||
}
|
||||
|
||||
float getTileVertexSkirtLength(){
|
||||
return tileVertexIsSkirtVertex() ? skirtLength : 0.0;
|
||||
}
|
||||
Reference in New Issue
Block a user