mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-07 12:10:52 -06:00
Use separate function for getting level weights
This commit is contained in:
@@ -60,18 +60,20 @@ in vec3 ellipsoidNormalCameraSpace;
|
||||
in vec4 fs_position;
|
||||
in vec2 fs_uv;
|
||||
|
||||
in float tileInterpolationParameter;
|
||||
in float levelInterpolationParameter;
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
|
||||
frag.color = vec4(0.1,0.1,0.1,1);
|
||||
|
||||
|
||||
|
||||
#if USE_COLORTEXTURE
|
||||
|
||||
frag.color = calculateColor(
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelInterpolationParameter,
|
||||
colorTiles,
|
||||
colorTilesParent1,
|
||||
colorTilesParent2);
|
||||
@@ -83,7 +85,7 @@ Fragment getFragment() {
|
||||
frag.color = calculateWater(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelInterpolationParameter,
|
||||
waterTiles,
|
||||
waterTilesParent1,
|
||||
waterTilesParent2);
|
||||
@@ -95,7 +97,7 @@ Fragment getFragment() {
|
||||
frag.color = calculateNight(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelInterpolationParameter,
|
||||
nightTiles,
|
||||
nightTilesParent1,
|
||||
nightTilesParent2,
|
||||
@@ -112,7 +114,7 @@ Fragment getFragment() {
|
||||
frag.color = calculateOverlay(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelInterpolationParameter,
|
||||
overlayTiles,
|
||||
overlayTilesParent1,
|
||||
overlayTilesParent2);
|
||||
|
||||
@@ -54,9 +54,9 @@ layout(location = 1) in vec2 in_uv;
|
||||
out vec2 fs_uv;
|
||||
out vec4 fs_position;
|
||||
out vec3 ellipsoidNormalCameraSpace;
|
||||
// tileInterpolationParameter is used to interpolate between a tile and its parent tiles
|
||||
// levelInterpolationParameter is used to interpolate between a tile and its parent tiles
|
||||
// The value increases with the distance from the vertex (or fragment) to the camera
|
||||
out float tileInterpolationParameter;
|
||||
out float levelInterpolationParameter;
|
||||
|
||||
PositionNormalPair globalInterpolation() {
|
||||
vec2 lonLatInput;
|
||||
@@ -74,7 +74,7 @@ void main()
|
||||
float projectedScaleFactor = distanceScaleFactor / distToVertexOnEllipsoid;
|
||||
float desiredLevel = log2(projectedScaleFactor);
|
||||
|
||||
tileInterpolationParameter = chunkLevel - desiredLevel;
|
||||
levelInterpolationParameter = chunkLevel - desiredLevel;
|
||||
|
||||
float height = 0;
|
||||
|
||||
@@ -84,7 +84,7 @@ void main()
|
||||
// Before any heightmapping is done
|
||||
height = calculateHeight(
|
||||
in_uv,
|
||||
tileInterpolationParameter, // Variable to determine which texture to sample from
|
||||
levelInterpolationParameter, // Variable to determine which texture to sample from
|
||||
heightTiles, heightTilesParent1, heightTilesParent2); // Three textures to sample from
|
||||
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
@@ -51,9 +51,9 @@ uniform Tile waterTilesParent1[NUMLAYERS_WATERMASK];
|
||||
uniform Tile waterTilesParent2[NUMLAYERS_WATERMASK];
|
||||
#endif // USE_WATERMASK
|
||||
|
||||
// tileInterpolationParameter is used to interpolate between a tile and its parent tiles
|
||||
// levelInterpolationParameter is used to interpolate between a tile and its parent tiles
|
||||
// The value increases with the distance from the vertex (or fragment) to the camera
|
||||
in float tileInterpolationParameter;
|
||||
in float levelInterpolationParameter;
|
||||
|
||||
in vec4 fs_position;
|
||||
in vec2 fs_uv;
|
||||
@@ -68,7 +68,7 @@ Fragment getFragment() {
|
||||
|
||||
frag.color = calculateColor(
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelInterpolationParameter,
|
||||
colorTiles,
|
||||
colorTilesParent1,
|
||||
colorTilesParent2);
|
||||
@@ -81,7 +81,7 @@ Fragment getFragment() {
|
||||
frag.color = calculateWater(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelInterpolationParameter,
|
||||
waterTiles,
|
||||
waterTilesParent1,
|
||||
waterTilesParent2);
|
||||
@@ -94,7 +94,7 @@ Fragment getFragment() {
|
||||
frag.color = calculateNight(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelInterpolationParameter,
|
||||
nightTiles,
|
||||
nightTilesParent1,
|
||||
nightTilesParent2,
|
||||
@@ -111,7 +111,7 @@ Fragment getFragment() {
|
||||
frag.color = calculateOverlay(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
tileInterpolationParameter,
|
||||
levelInterpolationParameter,
|
||||
overlayTiles,
|
||||
overlayTilesParent1,
|
||||
overlayTilesParent2);
|
||||
|
||||
@@ -59,9 +59,9 @@ out vec2 fs_uv;
|
||||
out vec4 fs_position;
|
||||
out vec3 ellipsoidNormalCameraSpace;
|
||||
|
||||
// tileInterpolationParameter is used to interpolate between a tile and its parent tiles
|
||||
// levelInterpolationParameter is used to interpolate between a tile and its parent tiles
|
||||
// The value increases with the distance from the vertex (or fragment) to the camera
|
||||
out float tileInterpolationParameter;
|
||||
out float levelInterpolationParameter;
|
||||
|
||||
vec3 bilinearInterpolation(vec2 uv) {
|
||||
// Bilinear interpolation
|
||||
@@ -84,7 +84,7 @@ void main()
|
||||
float projectedScaleFactor = distanceScaleFactor / distToVertexOnEllipsoid;
|
||||
float desiredLevel = log2(projectedScaleFactor);
|
||||
|
||||
tileInterpolationParameter = chunkLevel - desiredLevel;
|
||||
levelInterpolationParameter = chunkLevel - desiredLevel;
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
|
||||
@@ -92,7 +92,7 @@ void main()
|
||||
// Before any heightmapping is done
|
||||
height = calculateHeight(
|
||||
in_uv,
|
||||
tileInterpolationParameter, // Variable to determine which texture to sample from
|
||||
levelInterpolationParameter, // Variable to determine which texture to sample from
|
||||
heightTiles, heightTilesParent1, heightTilesParent2); // Three textures to sample from
|
||||
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
@@ -100,7 +100,7 @@
|
||||
|
||||
float calculateHeight(
|
||||
const vec2 uv,
|
||||
const float tileInterpolationParameter,
|
||||
const float levelInterpolationParameter,
|
||||
const Tile heightTiles[NUMLAYERS_HEIGHTMAP],
|
||||
const Tile heightTilesParent1[NUMLAYERS_HEIGHTMAP],
|
||||
const Tile heightTilesParent2[NUMLAYERS_HEIGHTMAP]) {
|
||||
@@ -109,22 +109,19 @@ float calculateHeight(
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
LevelWeights levelWeights;
|
||||
#if HEIGHTMAP_BLENDING_ENABLED
|
||||
float w1 = clamp(1 - tileInterpolationParameter, 0 , 1);
|
||||
float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1));
|
||||
float w3 = clamp(tileInterpolationParameter - 1, 0 , 1);
|
||||
levelWeights = getLevelWeights(levelInterpolationParameter);
|
||||
#else // HEIGHTMAP_BLENDING_ENABLED
|
||||
float w1 = 1;
|
||||
float w2 = 0;
|
||||
float w3 = 0;
|
||||
levelWeights = getDefaultLevelWeights();
|
||||
#endif // HEIGHTMAP_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexHeight}
|
||||
{
|
||||
float untransformedHeight =
|
||||
w1 * getTexVal(heightTiles[#{i}], uv).r +
|
||||
w2 * getTexVal(heightTilesParent1[#{i}], uv).r +
|
||||
w3 * getTexVal(heightTilesParent2[#{i}], uv).r;
|
||||
levelWeights.w1 * getTexVal(heightTiles[#{i}], uv).r +
|
||||
levelWeights.w2 * getTexVal(heightTilesParent1[#{i}], uv).r +
|
||||
levelWeights.w3 * getTexVal(heightTilesParent2[#{i}], uv).r;
|
||||
|
||||
// OBS! Only the values from the last height map will be used!
|
||||
height = getTransformedTexVal(heightTiles[#{i}].depthTransform, untransformedHeight);
|
||||
@@ -136,7 +133,7 @@ float calculateHeight(
|
||||
|
||||
vec4 calculateColor(
|
||||
const vec2 uv,
|
||||
const float tileInterpolationParameter,
|
||||
const float levelInterpolationParameter,
|
||||
const Tile colorTiles[NUMLAYERS_COLORTEXTURE],
|
||||
const Tile colorTilesParent1[NUMLAYERS_COLORTEXTURE],
|
||||
const Tile colorTilesParent2[NUMLAYERS_COLORTEXTURE]) {
|
||||
@@ -145,22 +142,19 @@ vec4 calculateColor(
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
LevelWeights levelWeights;
|
||||
#if COLORTEXTURE_BLENDING_ENABLED
|
||||
float w1 = clamp(1 - tileInterpolationParameter, 0 , 1);
|
||||
float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1));
|
||||
float w3 = clamp(tileInterpolationParameter - 1, 0 , 1);
|
||||
levelWeights = getLevelWeights(levelInterpolationParameter);
|
||||
#else // COLORTEXTURE_BLENDING_ENABLED
|
||||
float w1 = 1;
|
||||
float w2 = 0;
|
||||
float w3 = 0;
|
||||
levelWeights = getDefaultLevelWeights();
|
||||
#endif // COLORTEXTURE_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexColor}
|
||||
{
|
||||
vec4 colorSample =
|
||||
w1 * getTexVal(colorTiles[#{i}], uv) +
|
||||
w2 * getTexVal(colorTilesParent1[#{i}], uv) +
|
||||
w3 * getTexVal(colorTilesParent2[#{i}], uv);
|
||||
levelWeights.w1 * getTexVal(colorTiles[#{i}], uv) +
|
||||
levelWeights.w2 * getTexVal(colorTilesParent1[#{i}], uv) +
|
||||
levelWeights.w3 * getTexVal(colorTilesParent2[#{i}], uv);
|
||||
|
||||
color = blendOver(color, colorSample);
|
||||
}
|
||||
@@ -172,7 +166,7 @@ vec4 calculateColor(
|
||||
vec4 calculateNight(
|
||||
const vec4 currentColor,
|
||||
const vec2 uv,
|
||||
const float tileInterpolationParameter,
|
||||
const float levelInterpolationParameter,
|
||||
const Tile nightTiles[NUMLAYERS_NIGHTTEXTURE],
|
||||
const Tile nightTilesParent1[NUMLAYERS_NIGHTTEXTURE],
|
||||
const Tile nightTilesParent2[NUMLAYERS_NIGHTTEXTURE],
|
||||
@@ -185,22 +179,19 @@ vec4 calculateNight(
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
LevelWeights levelWeights;
|
||||
#if NIGHTTEXTURE_BLENDING_ENABLED
|
||||
float w1 = clamp(1 - tileInterpolationParameter, 0 , 1);
|
||||
float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1));
|
||||
float w3 = clamp(tileInterpolationParameter - 1, 0 , 1);
|
||||
levelWeights = getLevelWeights(levelInterpolationParameter)
|
||||
#else // NIGHTTEXTURE_BLENDING_ENABLED
|
||||
float w1 = 1;
|
||||
float w2 = 0;
|
||||
float w3 = 0;
|
||||
levelWeights = getDefaultLevelWeights();
|
||||
#endif // NIGHTTEXTURE_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexNight}
|
||||
{
|
||||
vec4 colorSample =
|
||||
w1 * getTexVal(nightTiles[#{i}], uv) +
|
||||
w2 * getTexVal(nightTilesParent1[#{i}], uv) +
|
||||
w3 * getTexVal(nightTilesParent2[#{i}], uv);
|
||||
levelWeights.w1 * getTexVal(nightTiles[#{i}], uv) +
|
||||
levelWeights.w2 * getTexVal(nightTilesParent1[#{i}], uv) +
|
||||
levelWeights.w3 * getTexVal(nightTilesParent2[#{i}], uv);
|
||||
|
||||
nightColor = blendOver(nightColor, colorSample);
|
||||
}
|
||||
@@ -215,7 +206,7 @@ vec4 calculateNight(
|
||||
vec4 calculateOverlay(
|
||||
const vec4 currentColor,
|
||||
const vec2 uv,
|
||||
const float tileInterpolationParameter,
|
||||
const float levelInterpolationParameter,
|
||||
const Tile overlayTiles[NUMLAYERS_OVERLAY],
|
||||
const Tile overlayTilesParent1[NUMLAYERS_OVERLAY],
|
||||
const Tile overlayTilesParent2[NUMLAYERS_OVERLAY]) {
|
||||
@@ -224,22 +215,19 @@ vec4 calculateOverlay(
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
LevelWeights levelWeights;
|
||||
#if OVERLAY_BLENDING_ENABLED
|
||||
float w1 = clamp(1 - tileInterpolationParameter, 0 , 1);
|
||||
float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1));
|
||||
float w3 = clamp(tileInterpolationParameter - 1, 0 , 1);
|
||||
levelWeights = getLevelWeights(levelInterpolationParameter);
|
||||
#else // OVERLAY_BLENDING_ENABLED
|
||||
float w1 = 1;
|
||||
float w2 = 0;
|
||||
float w3 = 0;
|
||||
levelWeights = getDefaultLevelWeights();
|
||||
#endif // OVERLAY_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexOverlay}
|
||||
{
|
||||
vec4 colorSample =
|
||||
w1 * getTexVal(overlayTiles[#{i}], uv) +
|
||||
w2 * getTexVal(overlayTilesParent1[#{i}], uv) +
|
||||
w3 * getTexVal(overlayTilesParent2[#{i}], uv);
|
||||
levelWeights.w1 * getTexVal(overlayTiles[#{i}], uv) +
|
||||
levelWeights.w2 * getTexVal(overlayTilesParent1[#{i}], uv) +
|
||||
levelWeights.w3 * getTexVal(overlayTilesParent2[#{i}], uv);
|
||||
|
||||
color = blendOver(color, colorSample);
|
||||
}
|
||||
@@ -251,7 +239,7 @@ vec4 calculateOverlay(
|
||||
vec4 calculateWater(
|
||||
const vec4 currentColor,
|
||||
const vec2 uv,
|
||||
const float tileInterpolationParameter,
|
||||
const float levelInterpolationParameter,
|
||||
const Tile waterTiles[NUMLAYERS_WATERMASK],
|
||||
const Tile waterTilesParent1[NUMLAYERS_WATERMASK],
|
||||
const Tile waterTilesParent2[NUMLAYERS_WATERMASK]) {
|
||||
@@ -260,22 +248,19 @@ vec4 calculateWater(
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
LevelWeights levelWeights;
|
||||
#if WATERMASK_BLENDING_ENABLED
|
||||
float w1 = clamp(1 - tileInterpolationParameter, 0 , 1);
|
||||
float w2 = (clamp(tileInterpolationParameter, 0 , 1) - clamp(tileInterpolationParameter - 1, 0 , 1));
|
||||
float w3 = clamp(tileInterpolationParameter - 1, 0 , 1);
|
||||
levelWeights = getLevelWeights(levelInterpolationParameter);
|
||||
#else // WATERMASK_BLENDING_ENABLED
|
||||
float w1 = 1;
|
||||
float w2 = 0;
|
||||
float w3 = 0;
|
||||
levelWeights = getDefaultLevelWeights();
|
||||
#endif // WATERMASK_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexWater}
|
||||
{
|
||||
vec4 colorSample =
|
||||
w1 * getTexVal(waterTiles[#{i}], uv) +
|
||||
w2 * getTexVal(waterTilesParent1[#{i}], uv) +
|
||||
w3 * getTexVal(waterTilesParent2[#{i}], uv);
|
||||
levelWeights.w1 * getTexVal(waterTiles[#{i}], uv) +
|
||||
levelWeights.w2 * getTexVal(waterTilesParent1[#{i}], uv) +
|
||||
levelWeights.w3 * getTexVal(waterTilesParent2[#{i}], uv);
|
||||
|
||||
waterColor = blendOver(waterColor, colorSample);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,29 @@ struct Tile {
|
||||
TileUvTransform uvTransform;
|
||||
};
|
||||
|
||||
struct LevelWeights {
|
||||
float w1;
|
||||
float w2;
|
||||
float w3;
|
||||
};
|
||||
|
||||
LevelWeights getLevelWeights(float levelInterpolationParameter){
|
||||
LevelWeights levelWeights;
|
||||
levelWeights.w1 = clamp(1 - levelInterpolationParameter, 0 , 1);
|
||||
levelWeights.w2 = (clamp(levelInterpolationParameter, 0 , 1) - clamp(levelInterpolationParameter - 1, 0 , 1));
|
||||
levelWeights.w3 = clamp(levelInterpolationParameter - 1, 0 , 1);
|
||||
return levelWeights;
|
||||
}
|
||||
|
||||
LevelWeights getDefaultLevelWeights(){
|
||||
LevelWeights levelWeights;
|
||||
levelWeights.w1 = 1;
|
||||
levelWeights.w2 = 0;
|
||||
levelWeights.w3 = 0;
|
||||
return levelWeights;
|
||||
}
|
||||
|
||||
|
||||
vec4 patchBorderOverlay(vec2 uv, vec3 borderColor, float borderSize) {
|
||||
vec2 uvOffset = uv - vec2(0.5);
|
||||
float thres = 0.5 - borderSize/2;
|
||||
|
||||
Reference in New Issue
Block a user