mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-04 01:39:47 -05:00
Add per layer settings for shading. Includes opacity.
This commit is contained in:
@@ -72,13 +72,31 @@
|
||||
#define SHOW_HEIGHT_RESOLUTION #{showHeightResolution}
|
||||
#define SHOW_HEIGHT_INTENSITIES #{showHeightIntensities}
|
||||
|
||||
float performLayerSettings(float currentValue, PerLayerSettings settings) {
|
||||
float newValue;
|
||||
|
||||
newValue = currentValue * settings.opacity;
|
||||
|
||||
return newValue;
|
||||
}
|
||||
|
||||
vec4 performLayerSettings(vec4 currentValue, PerLayerSettings settings) {
|
||||
vec4 newValue = vec4(
|
||||
performLayerSettings(currentValue.r, settings),
|
||||
performLayerSettings(currentValue.g, settings),
|
||||
performLayerSettings(currentValue.b, settings),
|
||||
performLayerSettings(currentValue.a, settings));
|
||||
|
||||
return newValue;
|
||||
}
|
||||
|
||||
float calculateUntransformedHeight(
|
||||
vec2 uv,
|
||||
LevelWeights levelWeights,
|
||||
const Tile heightTiles[NUMLAYERS_HEIGHTMAP],
|
||||
const Tile heightTilesParent1[NUMLAYERS_HEIGHTMAP],
|
||||
const Tile heightTilesParent2[NUMLAYERS_HEIGHTMAP]) {
|
||||
const Tile heightTilesParent2[NUMLAYERS_HEIGHTMAP],
|
||||
const PerLayerSettings layerSettings[NUMLAYERS_HEIGHTMAP]) {
|
||||
|
||||
float height = 0;
|
||||
|
||||
@@ -95,6 +113,8 @@ float calculateUntransformedHeight(
|
||||
levelWeights.w1 * getTexVal(heightTiles[#{i}], uv).r +
|
||||
levelWeights.w2 * getTexVal(heightTilesParent1[#{i}], uv).r +
|
||||
levelWeights.w3 * getTexVal(heightTilesParent2[#{i}], uv).r;
|
||||
|
||||
height = performLayerSettings(height, layerSettings[#{i}]);
|
||||
}
|
||||
#endfor
|
||||
return height;
|
||||
@@ -105,7 +125,8 @@ float calculateHeight(
|
||||
LevelWeights levelWeights,
|
||||
const Tile heightTiles[NUMLAYERS_HEIGHTMAP],
|
||||
const Tile heightTilesParent1[NUMLAYERS_HEIGHTMAP],
|
||||
const Tile heightTilesParent2[NUMLAYERS_HEIGHTMAP]) {
|
||||
const Tile heightTilesParent2[NUMLAYERS_HEIGHTMAP],
|
||||
const PerLayerSettings layerSettings[NUMLAYERS_HEIGHTMAP]) {
|
||||
|
||||
float height = 0;
|
||||
|
||||
@@ -124,8 +145,10 @@ float calculateHeight(
|
||||
levelWeights.w3 * getTexVal(heightTilesParent2[#{i}], uv).r;
|
||||
|
||||
float heightSample = getTransformedTexVal(heightTiles[#{i}].depthTransform, untransformedHeight);
|
||||
if (heightSample > -100000)
|
||||
if (heightSample > -100000) {
|
||||
heightSample = performLayerSettings(heightSample, layerSettings[#{i}]);
|
||||
height = heightSample;
|
||||
}
|
||||
}
|
||||
#endfor
|
||||
return height;
|
||||
@@ -136,7 +159,8 @@ vec4 calculateColor(
|
||||
LevelWeights levelWeights,
|
||||
const Tile colorTiles[NUMLAYERS_COLORTEXTURE],
|
||||
const Tile colorTilesParent1[NUMLAYERS_COLORTEXTURE],
|
||||
const Tile colorTilesParent2[NUMLAYERS_COLORTEXTURE]) {
|
||||
const Tile colorTilesParent2[NUMLAYERS_COLORTEXTURE],
|
||||
const PerLayerSettings layerSettings[NUMLAYERS_COLORTEXTURE]) {
|
||||
|
||||
vec4 color = vec4(0);
|
||||
|
||||
@@ -153,6 +177,8 @@ vec4 calculateColor(
|
||||
levelWeights.w2 * getTexVal(colorTilesParent1[#{i}], uv) +
|
||||
levelWeights.w3 * getTexVal(colorTilesParent2[#{i}], uv);
|
||||
|
||||
colorSample = performLayerSettings(colorSample, layerSettings[#{i}]);
|
||||
|
||||
color = blendOver(color, colorSample);
|
||||
}
|
||||
#endfor
|
||||
@@ -166,7 +192,8 @@ vec4 calculateGrayScale(
|
||||
LevelWeights levelWeights,
|
||||
const Tile grayscaleTextureTiles[NUMLAYERS_GRAYSCALETEXTURE],
|
||||
const Tile grayscaleTextureTilesParent1[NUMLAYERS_GRAYSCALETEXTURE],
|
||||
const Tile grayscaleTextureTilesParent2[NUMLAYERS_GRAYSCALETEXTURE]) {
|
||||
const Tile grayscaleTextureTilesParent2[NUMLAYERS_GRAYSCALETEXTURE],
|
||||
const PerLayerSettings layerSettings[NUMLAYERS_GRAYSCALETEXTURE]) {
|
||||
|
||||
vec4 colorGrayScale = currentColor;
|
||||
|
||||
@@ -184,6 +211,8 @@ vec4 calculateGrayScale(
|
||||
levelWeights.w3 * getTexVal(grayscaleTextureTilesParent2[#{i}], uv);
|
||||
|
||||
colorSample = vec4(colorSample.r, colorSample.r, colorSample.r, 1);
|
||||
colorSample = performLayerSettings(colorSample, layerSettings[#{i}]);
|
||||
|
||||
colorGrayScale = blendOver(colorGrayScale, colorSample);
|
||||
}
|
||||
#endfor
|
||||
@@ -221,6 +250,7 @@ vec4 calculateNight(
|
||||
const Tile nightTiles[NUMLAYERS_NIGHTTEXTURE],
|
||||
const Tile nightTilesParent1[NUMLAYERS_NIGHTTEXTURE],
|
||||
const Tile nightTilesParent2[NUMLAYERS_NIGHTTEXTURE],
|
||||
const PerLayerSettings layerSettings[NUMLAYERS_NIGHTTEXTURE],
|
||||
const vec3 ellipsoidNormalCameraSpace,
|
||||
const vec3 lightDirectionCameraSpace) {
|
||||
|
||||
@@ -238,6 +268,7 @@ vec4 calculateNight(
|
||||
levelWeights.w1 * getTexVal(nightTiles[#{i}], uv) +
|
||||
levelWeights.w2 * getTexVal(nightTilesParent1[#{i}], uv) +
|
||||
levelWeights.w3 * getTexVal(nightTilesParent2[#{i}], uv);
|
||||
colorSample = performLayerSettings(colorSample, layerSettings[#{i}]);
|
||||
|
||||
nightColor = blendOver(nightColor, colorSample);
|
||||
}
|
||||
@@ -265,7 +296,7 @@ vec4 calculateShadedColor(
|
||||
vec3 n = normalize(ellipsoidNormalCameraSpace);
|
||||
vec3 l = lightDirectionCameraSpace;
|
||||
|
||||
float cosineFactor = clamp(dot(-l, n) * 4, 0, 1);
|
||||
float cosineFactor = clamp(dot(-l, n) * 3, 0, 1);
|
||||
|
||||
// Blend shaded color with base color
|
||||
vec4 color = vec4(cosineFactor * currentColor.xyz + (1 - cosineFactor) * shadedColor, currentColor.a);
|
||||
@@ -278,7 +309,8 @@ vec4 calculateOverlay(
|
||||
LevelWeights levelWeights,
|
||||
const Tile overlayTiles[NUMLAYERS_OVERLAY],
|
||||
const Tile overlayTilesParent1[NUMLAYERS_OVERLAY],
|
||||
const Tile overlayTilesParent2[NUMLAYERS_OVERLAY]) {
|
||||
const Tile overlayTilesParent2[NUMLAYERS_OVERLAY],
|
||||
const PerLayerSettings layerSettings[NUMLAYERS_OVERLAY]) {
|
||||
|
||||
vec4 color = currentColor;
|
||||
|
||||
@@ -294,6 +326,7 @@ vec4 calculateOverlay(
|
||||
levelWeights.w1 * getTexVal(overlayTiles[#{i}], uv) +
|
||||
levelWeights.w2 * getTexVal(overlayTilesParent1[#{i}], uv) +
|
||||
levelWeights.w3 * getTexVal(overlayTilesParent2[#{i}], uv);
|
||||
colorSample = performLayerSettings(colorSample, layerSettings[#{i}]);
|
||||
|
||||
color = blendOver(color, colorSample);
|
||||
}
|
||||
@@ -308,7 +341,8 @@ vec4 calculateGrayScaleOverlay(
|
||||
LevelWeights levelWeights,
|
||||
const Tile grayscaleOverlayTiles[NUMLAYERS_GRAYSCALE_OVERLAY],
|
||||
const Tile grayscaleOverlayTilesParent1[NUMLAYERS_GRAYSCALE_OVERLAY],
|
||||
const Tile grayscaleOverlayTilesParent2[NUMLAYERS_GRAYSCALE_OVERLAY]) {
|
||||
const Tile grayscaleOverlayTilesParent2[NUMLAYERS_GRAYSCALE_OVERLAY],
|
||||
const PerLayerSettings layerSettings[NUMLAYERS_GRAYSCALE_OVERLAY]) {
|
||||
|
||||
vec4 colorGrayScale = currentColor;
|
||||
|
||||
@@ -326,6 +360,8 @@ vec4 calculateGrayScaleOverlay(
|
||||
levelWeights.w3 * getTexVal(grayscaleOverlayTilesParent2[#{i}], uv);
|
||||
|
||||
colorSample = vec4(colorSample.r, colorSample.r, colorSample.r, colorSample.g);
|
||||
colorSample = performLayerSettings(colorSample, layerSettings[#{i}]);
|
||||
|
||||
colorGrayScale = blendOver(colorGrayScale, colorSample);
|
||||
}
|
||||
#endfor
|
||||
@@ -355,6 +391,7 @@ vec4 calculateWater(
|
||||
const Tile waterTiles[NUMLAYERS_WATERMASK],
|
||||
const Tile waterTilesParent1[NUMLAYERS_WATERMASK],
|
||||
const Tile waterTilesParent2[NUMLAYERS_WATERMASK],
|
||||
const PerLayerSettings layerSettings[NUMLAYERS_WATERMASK],
|
||||
const vec3 ellipsoidNormalCameraSpace,
|
||||
const vec3 lightDirectionCameraSpace,
|
||||
const vec3 positionCameraSpace) {
|
||||
@@ -374,6 +411,8 @@ vec4 calculateWater(
|
||||
levelWeights.w2 * getTexVal(waterTilesParent1[#{i}], uv) +
|
||||
levelWeights.w3 * getTexVal(waterTilesParent2[#{i}], uv);
|
||||
|
||||
colorSample = performLayerSettings(colorSample, layerSettings[#{i}]);
|
||||
|
||||
waterColor = blendOver(waterColor, colorSample);
|
||||
}
|
||||
#endfor
|
||||
|
||||
@@ -139,6 +139,9 @@ vec4 getTexVal(const MultiLevelTile multiLevelTile, const LevelWeights w, const
|
||||
w.w3 * getTexVal(multiLevelTile.tile2, uv);
|
||||
}
|
||||
|
||||
|
||||
// PerLayerSettings
|
||||
struct PerLayerSettings {
|
||||
float opacity;
|
||||
};
|
||||
|
||||
#endif // TEXTURETILE_HGLSL
|
||||
@@ -37,36 +37,42 @@
|
||||
uniform Tile ColorTextures[NUMLAYERS_COLORTEXTURE];
|
||||
uniform Tile ColorTexturesParent1[NUMLAYERS_COLORTEXTURE];
|
||||
uniform Tile ColorTexturesParent2[NUMLAYERS_COLORTEXTURE];
|
||||
uniform PerLayerSettings ColorTexturesSettings[NUMLAYERS_COLORTEXTURE];
|
||||
#endif // USE_COLORTEXTURE
|
||||
|
||||
#if USE_GRAYSCALETEXTURE
|
||||
uniform Tile GrayScaleTextures[NUMLAYERS_GRAYSCALETEXTURE];
|
||||
uniform Tile GrayScaleTexturesParent1[NUMLAYERS_GRAYSCALETEXTURE];
|
||||
uniform Tile GrayScaleTexturesParent2[NUMLAYERS_GRAYSCALETEXTURE];
|
||||
uniform PerLayerSettings GrayScaleTexturesSettings[NUMLAYERS_GRAYSCALETEXTURE];
|
||||
#endif // USE_GRAYSCALETEXTURE
|
||||
|
||||
#if USE_NIGHTTEXTURE
|
||||
uniform Tile NightTextures[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform Tile NightTexturesParent1[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform Tile NightTexturesParent2[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform PerLayerSettings NightTexturesSettings[NUMLAYERS_NIGHTTEXTURE];
|
||||
#endif // USE_NIGHTTEXTURE
|
||||
|
||||
#if USE_OVERLAY
|
||||
uniform Tile Overlays[NUMLAYERS_OVERLAY];
|
||||
uniform Tile OverlaysParent1[NUMLAYERS_OVERLAY];
|
||||
uniform Tile OverlaysParent2[NUMLAYERS_OVERLAY];
|
||||
uniform PerLayerSettings OverlaysSettings[NUMLAYERS_OVERLAY];
|
||||
#endif // USE_OVERLAY
|
||||
|
||||
#if USE_GRAYSCALE_OVERLAY
|
||||
uniform Tile GrayScaleOverlays[NUMLAYERS_GRAYSCALE_OVERLAY];
|
||||
uniform Tile GrayScaleOverlaysParent1[NUMLAYERS_GRAYSCALE_OVERLAY];
|
||||
uniform Tile GrayScaleOverlaysParent2[NUMLAYERS_GRAYSCALE_OVERLAY];
|
||||
uniform PerLayerSettings GrayScaleOverlaysSettings[NUMLAYERS_GRAYSCALE_OVERLAY];
|
||||
#endif // USE_GRAYSCALE_OVERLAY
|
||||
|
||||
#if USE_WATERMASK
|
||||
uniform Tile WaterMasks[NUMLAYERS_WATERMASK];
|
||||
uniform Tile WaterMasksParent1[NUMLAYERS_WATERMASK];
|
||||
uniform Tile WaterMasksParent2[NUMLAYERS_WATERMASK];
|
||||
uniform PerLayerSettings WaterMasksSettings[NUMLAYERS_WATERMASK];
|
||||
#endif // USE_WATERMASK
|
||||
|
||||
#if SHOW_HEIGHT_RESOLUTION
|
||||
@@ -102,6 +108,7 @@ in LevelWeights levelWeights;
|
||||
uniform Tile HeightMaps[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile HeightMapsParent1[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile HeightMapsParent2[NUMLAYERS_HEIGHTMAP];
|
||||
uniform PerLayerSettings HeightMapsSettings[NUMLAYERS_HEIGHTMAP];
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
float getUntransformedTileVertexHeight(vec2 uv, LevelWeights levelWeights){
|
||||
@@ -113,7 +120,7 @@ float getUntransformedTileVertexHeight(vec2 uv, LevelWeights levelWeights){
|
||||
height = calculateUntransformedHeight(
|
||||
uv,
|
||||
levelWeights, // Variable to determine which texture to sample from
|
||||
HeightMaps, HeightMapsParent1, HeightMapsParent2); // Three textures to sample from
|
||||
HeightMaps, HeightMapsParent1, HeightMapsParent2, HeightMapsSettings); // Three textures to sample from
|
||||
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
@@ -141,7 +148,8 @@ vec4 getTileFragColor(){
|
||||
levelWeights,
|
||||
ColorTextures,
|
||||
ColorTexturesParent1,
|
||||
ColorTexturesParent2);
|
||||
ColorTexturesParent2,
|
||||
ColorTexturesSettings);
|
||||
#endif // USE_COLORTEXTURE
|
||||
|
||||
#if USE_GRAYSCALETEXTURE
|
||||
@@ -151,7 +159,8 @@ vec4 getTileFragColor(){
|
||||
levelWeights,
|
||||
GrayScaleTextures,
|
||||
GrayScaleTexturesParent1,
|
||||
GrayScaleTexturesParent2);
|
||||
GrayScaleTexturesParent2,
|
||||
GrayScaleTexturesSettings);
|
||||
#endif // USE_GRAYSCALETEXTURE
|
||||
|
||||
#if USE_GRAYSCALE_OVERLAY
|
||||
@@ -162,7 +171,8 @@ vec4 getTileFragColor(){
|
||||
levelWeights,
|
||||
GrayScaleOverlays,
|
||||
GrayScaleOverlaysParent1,
|
||||
GrayScaleOverlaysParent2);
|
||||
GrayScaleOverlaysParent2,
|
||||
GrayScaleOverlaysSettings);
|
||||
|
||||
#endif // USE_COLORTEXTURE
|
||||
|
||||
@@ -174,6 +184,7 @@ vec4 getTileFragColor(){
|
||||
WaterMasks,
|
||||
WaterMasksParent1,
|
||||
WaterMasksParent2,
|
||||
WaterMasksSettings,
|
||||
normalize(ellipsoidNormalCameraSpace),
|
||||
lightDirectionCameraSpace, // Should already be normalized
|
||||
positionCameraSpace);
|
||||
@@ -188,6 +199,7 @@ vec4 getTileFragColor(){
|
||||
NightTextures,
|
||||
NightTexturesParent1,
|
||||
NightTexturesParent2,
|
||||
NightTexturesSettings,
|
||||
normalize(ellipsoidNormalCameraSpace),
|
||||
lightDirectionCameraSpace); // Should already be normalized
|
||||
|
||||
@@ -227,7 +239,8 @@ vec4 getTileFragColor(){
|
||||
levelWeights,
|
||||
Overlays,
|
||||
OverlaysParent1,
|
||||
OverlaysParent2);
|
||||
OverlaysParent2,
|
||||
OverlaysSettings);
|
||||
|
||||
#endif // USE_OVERLAY
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
uniform Tile HeightMaps[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile HeightMapsParent1[NUMLAYERS_HEIGHTMAP];
|
||||
uniform Tile HeightMapsParent2[NUMLAYERS_HEIGHTMAP];
|
||||
uniform PerLayerSettings HeightMapsSettings[NUMLAYERS_HEIGHTMAP];
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
uniform int xSegments;
|
||||
@@ -52,7 +53,7 @@ float getUntransformedTileVertexHeight(vec2 uv, LevelWeights levelWeights){
|
||||
height = calculateUntransformedHeight(
|
||||
uv,
|
||||
levelWeights, // Variable to determine which texture to sample from
|
||||
HeightMaps, HeightMapsParent1, HeightMapsParent2); // Three textures to sample from
|
||||
HeightMaps, HeightMapsParent1, HeightMapsParent2, HeightMapsSettings); // Three textures to sample from
|
||||
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
@@ -69,13 +70,51 @@ float getTileVertexHeight(vec2 uv, LevelWeights levelWeights){
|
||||
height = calculateHeight(
|
||||
uv,
|
||||
levelWeights, // Variable to determine which texture to sample from
|
||||
HeightMaps, HeightMapsParent1, HeightMapsParent2); // Three textures to sample from
|
||||
HeightMaps, HeightMapsParent1, HeightMapsParent2, HeightMapsSettings); // Three textures to sample from
|
||||
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
// This function is currently not correct
|
||||
vec3 getTileVertexNormal(
|
||||
vec2 uv,
|
||||
LevelWeights levelWeights,
|
||||
vec3 ellipsoidNormal) {
|
||||
vec3 normal = ellipsoidNormal;
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
float sampleDelta = 1.0 / xSegments;
|
||||
|
||||
float heightCenter = calculateHeight(
|
||||
uv,
|
||||
levelWeights,
|
||||
HeightMaps, HeightMapsParent1, HeightMapsParent2, HeightMapsSettings);
|
||||
float heightOffsetX = calculateHeight(
|
||||
uv + vec2(sampleDelta, 0.0),
|
||||
levelWeights,
|
||||
HeightMaps, HeightMapsParent1, HeightMapsParent2, HeightMapsSettings);
|
||||
float heightOffsetY = calculateHeight(
|
||||
uv + vec2(0.0, sampleDelta),
|
||||
levelWeights,
|
||||
HeightMaps, HeightMapsParent1, HeightMapsParent2, HeightMapsSettings);
|
||||
|
||||
vec3 e0 = normalize(cross(vec3(0,0,1), ellipsoidNormal));
|
||||
vec3 e1 = cross(ellipsoidNormal, e0);
|
||||
vec3 e2 = ellipsoidNormal;
|
||||
|
||||
vec3 v0 = e0 * sampleDelta * 3000000 + e2 * heightOffsetX;
|
||||
vec3 v1 = e1 * sampleDelta * 3000000 + e2 * heightOffsetY;
|
||||
|
||||
vec3 n = cross(v0, v1);
|
||||
|
||||
normal = normalize(n);
|
||||
|
||||
#endif // USE_HEIGHTMAP
|
||||
return normal;
|
||||
}
|
||||
|
||||
bool tileVertexIsSkirtVertex(){
|
||||
int vertexIDx = gl_VertexID % (xSegments + 3);
|
||||
int vertexIDy = gl_VertexID / (xSegments + 3);
|
||||
|
||||
Reference in New Issue
Block a user