mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-23 20:50:59 -05:00
Feature/cleanup (#1608)
* Revert screenlog back to showing Info and above messages * Various code cleanup
This commit is contained in:
@@ -94,7 +94,7 @@ source_group("Source Files" FILES ${SOURCE_FILES})
|
||||
set(SHADER_FILES
|
||||
shaders/advanced_rings_vs.glsl
|
||||
shaders/advanced_rings_fs.glsl
|
||||
shaders/blending.hglsl
|
||||
shaders/blending.glsl
|
||||
shaders/globalrenderer_vs.glsl
|
||||
shaders/localrenderer_vs.glsl
|
||||
shaders/renderer_fs.glsl
|
||||
@@ -102,10 +102,10 @@ set(SHADER_FILES
|
||||
shaders/rings_fs.glsl
|
||||
shaders/rings_geom_vs.glsl
|
||||
shaders/rings_geom_fs.glsl
|
||||
shaders/texturetilemapping.hglsl
|
||||
shaders/tile.hglsl
|
||||
shaders/tileheight.hglsl
|
||||
shaders/tilevertexskirt.hglsl
|
||||
shaders/texturetilemapping.glsl
|
||||
shaders/tile.glsl
|
||||
shaders/tileheight.glsl
|
||||
shaders/tilevertexskirt.glsl
|
||||
)
|
||||
|
||||
source_group("Shader Files" FILES ${SHADER_FILES})
|
||||
|
||||
@@ -45,99 +45,88 @@ uniform float colorFilterValue;
|
||||
uniform vec3 sunPosition;
|
||||
uniform vec3 sunPositionObj;
|
||||
uniform vec3 camPositionObj;
|
||||
uniform float _nightFactor;
|
||||
uniform float nightFactor;
|
||||
uniform float zFightingPercentage;
|
||||
|
||||
// temp
|
||||
in vec4 fragPosInLightSpace;
|
||||
|
||||
|
||||
Fragment getFragment() {
|
||||
// Moving the origin to the center
|
||||
vec2 st = (vs_st - vec2(0.5)) * 2.0;
|
||||
// Moving the origin to the center
|
||||
vec2 st = (vs_st - vec2(0.5)) * 2.0;
|
||||
|
||||
// The length of the texture coordinates vector is our distance from the center
|
||||
float radius = length(st);
|
||||
// The length of the texture coordinates vector is our distance from the center
|
||||
float radius = length(st);
|
||||
|
||||
// We only want to consider ring-like objects so we need to discard everything else
|
||||
if (radius > 1.0) {
|
||||
discard;
|
||||
}
|
||||
// We only want to consider ring-like objects so we need to discard everything else
|
||||
if (radius > 1.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
// Remapping the texture coordinates
|
||||
// Radius \in [0,1], texCoord \in [textureOffset.x, textureOffset.y]
|
||||
// textureOffset.x -> 0
|
||||
// textureOffset.y -> 1
|
||||
float texCoord = (radius - textureOffset.x) / (textureOffset.y - textureOffset.x);
|
||||
if (texCoord < 0.f || texCoord > 1.f) {
|
||||
discard;
|
||||
}
|
||||
// Remapping the texture coordinates
|
||||
// Radius \in [0,1], texCoord \in [textureOffset.x, textureOffset.y]
|
||||
// textureOffset.x -> 0
|
||||
// textureOffset.y -> 1
|
||||
float texCoord = (radius - textureOffset.x) / (textureOffset.y - textureOffset.x);
|
||||
if (texCoord < 0.0 || texCoord > 1.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
vec4 colorBckwrd = texture(ringTextureBckwrd, texCoord);
|
||||
vec4 colorFwrd = texture(ringTextureFwrd, texCoord);
|
||||
vec4 colorMult = texture(ringTextureColor, texCoord);
|
||||
vec4 transparency = texture(ringTextureTransparency, texCoord);
|
||||
vec4 colorBckwrd = texture(ringTextureBckwrd, texCoord);
|
||||
vec4 colorFwrd = texture(ringTextureFwrd, texCoord);
|
||||
vec4 colorMult = texture(ringTextureColor, texCoord);
|
||||
vec4 transparency = texture(ringTextureTransparency, texCoord);
|
||||
|
||||
float lerpFactor = dot(camPositionObj, sunPositionObj);
|
||||
float lerpFactor = dot(camPositionObj, sunPositionObj);
|
||||
|
||||
// Jon Colors:
|
||||
//vec4 diffuse = mix(colorFwrd * vec4(1, 0.88, 0.82, 1.0), colorBckwrd * vec4(1, 0.88, 0.82, 1.0), lerpFactor);
|
||||
vec4 diffuse = mix(colorFwrd * colorMult, colorBckwrd * colorMult, lerpFactor);
|
||||
diffuse.a = colorFilterValue * transparency.a;
|
||||
float colorValue = length(diffuse.rgb) / 0.57735026919;
|
||||
if (colorValue < 0.1) {
|
||||
discard;
|
||||
}
|
||||
// Jon Colors:
|
||||
//vec4 diffuse = mix(colorFwrd * vec4(1, 0.88, 0.82, 1.0), colorBckwrd * vec4(1, 0.88, 0.82, 1.0), lerpFactor);
|
||||
vec4 diffuse = mix(colorFwrd * colorMult, colorBckwrd * colorMult, lerpFactor);
|
||||
diffuse.a = colorFilterValue * transparency.a;
|
||||
float colorValue = length(diffuse.rgb) / 0.57735026919;
|
||||
if (colorValue < 0.1) {
|
||||
discard;
|
||||
}
|
||||
|
||||
// shadow == 1.0 means it is not in shadow
|
||||
float shadow = 1.0;
|
||||
if (shadowCoords.z >= 0) {
|
||||
vec4 normalizedShadowCoords = shadowCoords;
|
||||
normalizedShadowCoords.z = normalizeFloat(zFightingPercentage * normalizedShadowCoords.w);
|
||||
normalizedShadowCoords.xy = normalizedShadowCoords.xy / normalizedShadowCoords.w;
|
||||
normalizedShadowCoords.w = 1.0;
|
||||
|
||||
float sum = 0;
|
||||
#for i in 0..#{nShadowSamples}
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, 0));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, NSSamples - #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , NSSamples - #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, 0));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, NSSamples - #{i}));
|
||||
#endfor
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(0, 0));
|
||||
shadow = clamp(sum / (8.0 * NSSamples + 1.f), 0.35, 1.0);
|
||||
}
|
||||
// shadow == 1.0 means it is not in shadow
|
||||
float shadow = 1.0;
|
||||
if (shadowCoords.z >= 0) {
|
||||
vec4 normalizedShadowCoords = shadowCoords;
|
||||
normalizedShadowCoords.z = normalizeFloat(zFightingPercentage * normalizedShadowCoords.w);
|
||||
normalizedShadowCoords.xy = normalizedShadowCoords.xy / normalizedShadowCoords.w;
|
||||
normalizedShadowCoords.w = 1.0;
|
||||
|
||||
float sum = 0;
|
||||
#for i in 0..#{nShadowSamples}
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, 0));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, NSSamples - #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , NSSamples - #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, 0));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, NSSamples - #{i}));
|
||||
#endfor
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(0, 0));
|
||||
shadow = clamp(sum / (8.0 * NSSamples + 1.f), 0.35, 1.0);
|
||||
}
|
||||
|
||||
// The normal for the one plane depends on whether we are dealing
|
||||
// with a front facing or back facing fragment
|
||||
vec3 normal;
|
||||
// The plane is oriented on the xz plane
|
||||
// WARNING: This might not be the case for Uranus
|
||||
if (gl_FrontFacing) {
|
||||
normal = vec3(-1.0, 0.0, 0.0);
|
||||
}
|
||||
else {
|
||||
normal = vec3(1.0, 0.0, 0.0);
|
||||
}
|
||||
// The normal for the one plane depends on whether we are dealing
|
||||
// with a front facing or back facing fragment
|
||||
// The plane is oriented on the xz plane
|
||||
// WARNING: This might not be the case for Uranus
|
||||
vec3 normal = gl_FrontFacing ? vec3(-1.0, 0.0, 0.0) : vec3(1.0, 0.0, 0.0);
|
||||
|
||||
// Reduce the color of the fragment by the user factor
|
||||
// if we are facing away from the Sun
|
||||
if (dot(sunPosition, normal) < 0) {
|
||||
diffuse.xyz = vec3(1.0, 0.97075, 0.952) *
|
||||
texture(ringTextureUnlit, texCoord).xyz *
|
||||
_nightFactor;
|
||||
}
|
||||
// Reduce the color of the fragment by the user factor
|
||||
// if we are facing away from the Sun
|
||||
if (dot(sunPosition, normal) < 0.0) {
|
||||
diffuse.xyz =
|
||||
vec3(1.0, 0.97075, 0.952) * texture(ringTextureUnlit, texCoord).xyz * nightFactor;
|
||||
}
|
||||
|
||||
Fragment frag;
|
||||
Fragment frag;
|
||||
|
||||
frag.color = diffuse * shadow;
|
||||
frag.depth = vs_screenSpaceDepth;
|
||||
frag.gPosition = vec4(1e30, 1e30, 1e30, 1.0);
|
||||
frag.gNormal = vec4(normal, 1.0);
|
||||
frag.color = diffuse * shadow;
|
||||
frag.depth = vs_screenSpaceDepth;
|
||||
frag.gPosition = vec4(1e30, 1e30, 1e30, 1.0);
|
||||
frag.gNormal = vec4(normal, 1.0);
|
||||
|
||||
return frag;
|
||||
return frag;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ layout(location = 1) in vec2 in_st;
|
||||
|
||||
out vec2 vs_st;
|
||||
out float vs_screenSpaceDepth;
|
||||
out vec4 vs_positionViewSpace;
|
||||
out vec4 shadowCoords;
|
||||
|
||||
uniform dmat4 modelViewProjectionMatrix;
|
||||
@@ -42,12 +41,12 @@ uniform dmat4 modelViewProjectionMatrix;
|
||||
uniform dmat4 shadowMatrix;
|
||||
|
||||
void main() {
|
||||
vs_st = in_st;
|
||||
vs_st = in_st;
|
||||
|
||||
dvec4 positionClipSpace = modelViewProjectionMatrix * dvec4(in_position, 0.0, 1.0);
|
||||
vec4 positionClipSpaceZNorm = z_normalization(vec4(positionClipSpace));
|
||||
|
||||
shadowCoords = vec4(shadowMatrix * dvec4(in_position, 0.0, 1.0));
|
||||
vs_screenSpaceDepth = positionClipSpaceZNorm.w;
|
||||
gl_Position = positionClipSpaceZNorm;
|
||||
dvec4 positionClipSpace = modelViewProjectionMatrix * dvec4(in_position, 0.0, 1.0);
|
||||
vec4 positionClipSpaceZNorm = z_normalization(vec4(positionClipSpace));
|
||||
|
||||
shadowCoords = vec4(shadowMatrix * dvec4(in_position, 0.0, 1.0));
|
||||
vs_screenSpaceDepth = positionClipSpaceZNorm.w;
|
||||
gl_Position = positionClipSpaceZNorm;
|
||||
}
|
||||
|
||||
+53
-54
@@ -26,92 +26,91 @@
|
||||
#define BLENDING_HGLSL
|
||||
|
||||
vec4 blendNormal(vec4 oldColor, vec4 newColor) {
|
||||
vec4 toReturn;
|
||||
toReturn.a = mix(oldColor.a, 1.0, newColor.a);
|
||||
toReturn.rgb =
|
||||
(newColor.rgb * newColor.a + oldColor.rgb * oldColor.a * (1 - newColor.a)) /
|
||||
toReturn.a;
|
||||
return toReturn;
|
||||
vec4 toReturn;
|
||||
toReturn.a = mix(oldColor.a, 1.0, newColor.a);
|
||||
toReturn.rgb =
|
||||
(newColor.rgb * newColor.a + oldColor.rgb * oldColor.a * (1 - newColor.a)) / toReturn.a;
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
vec4 blendMultiply(vec4 oldColor, vec4 newColor) {
|
||||
return oldColor * newColor;
|
||||
return oldColor * newColor;
|
||||
}
|
||||
|
||||
vec4 blendAdd(vec4 oldColor, vec4 newColor) {
|
||||
return oldColor + newColor;
|
||||
return oldColor + newColor;
|
||||
}
|
||||
|
||||
vec4 blendSubtract(vec4 oldColor, vec4 newColor) {
|
||||
return oldColor - newColor;
|
||||
return oldColor - newColor;
|
||||
}
|
||||
|
||||
vec3 hsl2rgb(in vec3 c) {
|
||||
vec3 rgb = clamp(abs(mod(c.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0);
|
||||
vec3 rgb = clamp(abs(mod(c.x * 6.0 + vec3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0);
|
||||
|
||||
return c.z + c.y * (rgb - 0.5) * (1.0 - abs(2.0 * c.z - 1.0));
|
||||
return c.z + c.y * (rgb - 0.5) * (1.0 - abs(2.0 * c.z - 1.0));
|
||||
}
|
||||
|
||||
vec3 HueShift(in vec3 color, in float shift) {
|
||||
vec3 P = vec3(0.55735) * dot(vec3(0.55735), color);
|
||||
vec3 U = color - P;
|
||||
vec3 V = cross(vec3(0.55735), U);
|
||||
vec3 c = U * cos(shift*6.2832) + V * sin(shift*6.2832) + P;
|
||||
return c;
|
||||
vec3 P = vec3(0.55735) * dot(vec3(0.55735), color);
|
||||
vec3 U = color - P;
|
||||
vec3 V = cross(vec3(0.55735), U);
|
||||
vec3 c = U * cos(shift*6.2832) + V * sin(shift*6.2832) + P;
|
||||
return c;
|
||||
}
|
||||
|
||||
vec3 rgb2hsl(in vec3 c) {
|
||||
float r = c.r;
|
||||
float g = c.g;
|
||||
float b = c.b;
|
||||
float cMin = min(r, min(g, b));
|
||||
float cMax = max(r, max(g, b));
|
||||
float r = c.r;
|
||||
float g = c.g;
|
||||
float b = c.b;
|
||||
float cMin = min(r, min(g, b));
|
||||
float cMax = max(r, max(g, b));
|
||||
|
||||
if (cMax > cMin) {
|
||||
float l = (cMax + cMin) / 2.0;
|
||||
if (cMax > cMin) {
|
||||
float l = (cMax + cMin) / 2.0;
|
||||
|
||||
float cDelta = cMax - cMin;
|
||||
float cDelta = cMax - cMin;
|
||||
|
||||
//s = l < .05 ? cDelta / ( cMax + cMin ) : cDelta / ( 2.0 - ( cMax + cMin ) ); Original
|
||||
float s = (l < 0.0) ? cDelta / (cMax + cMin) : cDelta / (2.0 - (cMax + cMin));
|
||||
//s = l < .05 ? cDelta / ( cMax + cMin ) : cDelta / ( 2.0 - ( cMax + cMin ) ); Original
|
||||
float s = (l < 0.0) ? cDelta / (cMax + cMin) : cDelta / (2.0 - (cMax + cMin));
|
||||
|
||||
float h = 0.0;
|
||||
if (r == cMax) {
|
||||
h = (g - b) / cDelta;
|
||||
}
|
||||
else if (g == cMax) {
|
||||
h = 2.0 + (b - r) / cDelta;
|
||||
}
|
||||
else {
|
||||
h = 4.0 + (r - g) / cDelta;
|
||||
}
|
||||
|
||||
if (h < 0.0) {
|
||||
h += 6.0;
|
||||
}
|
||||
h = h / 6.0;
|
||||
|
||||
return vec3(h, s, l);
|
||||
float h = 0.0;
|
||||
if (r == cMax) {
|
||||
h = (g - b) / cDelta;
|
||||
}
|
||||
else if (g == cMax) {
|
||||
h = 2.0 + (b - r) / cDelta;
|
||||
}
|
||||
else {
|
||||
return vec3(0.0);
|
||||
h = 4.0 + (r - g) / cDelta;
|
||||
}
|
||||
|
||||
if (h < 0.0) {
|
||||
h += 6.0;
|
||||
}
|
||||
h = h / 6.0;
|
||||
|
||||
return vec3(h, s, l);
|
||||
}
|
||||
else {
|
||||
return vec3(0.0);
|
||||
}
|
||||
}
|
||||
|
||||
vec3 rgb2hsv(vec3 c) {
|
||||
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
vec4 p = (c.g < c.b) ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
|
||||
vec4 q = (c.r < p.x) ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
|
||||
vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
|
||||
vec4 p = (c.g < c.b) ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy);
|
||||
vec4 q = (c.r < p.x) ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx);
|
||||
|
||||
float d = q.x - min(q.w, q.y);
|
||||
float e = 1.0e-10;
|
||||
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
||||
float d = q.x - min(q.w, q.y);
|
||||
float e = 1.0e-10;
|
||||
return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
|
||||
}
|
||||
|
||||
vec3 hsv2rgb(vec3 c) {
|
||||
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
|
||||
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
||||
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif // BLENDING_HGLSL
|
||||
@@ -25,10 +25,10 @@
|
||||
#version __CONTEXT__
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetilemapping.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tileheight.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tilevertexskirt.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.glsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetilemapping.glsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tileheight.glsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tilevertexskirt.glsl>
|
||||
|
||||
layout(location = 1) in vec2 in_uv;
|
||||
|
||||
@@ -39,22 +39,22 @@ out vec3 levelWeights;
|
||||
out vec3 positionCameraSpace;
|
||||
|
||||
#if USE_ACCURATE_NORMALS
|
||||
out vec3 ellipsoidTangentThetaCameraSpace;
|
||||
out vec3 ellipsoidTangentPhiCameraSpace;
|
||||
out vec3 ellipsoidTangentThetaCameraSpace;
|
||||
out vec3 ellipsoidTangentPhiCameraSpace;
|
||||
#endif // USE_ACCURATE_NORMALS
|
||||
|
||||
#if USE_ECLIPSE_SHADOWS
|
||||
out vec3 positionWorldSpace;
|
||||
uniform dmat4 modelTransform;
|
||||
#endif
|
||||
out vec3 positionWorldSpace;
|
||||
uniform dmat4 modelTransform;
|
||||
#endif // USE_ECLIPSE_SHADOWS
|
||||
|
||||
#if SHADOW_MAPPING_ENABLED
|
||||
// ShadowMatrix is the matrix defined by:
|
||||
// textureCoordsMatrix * projectionMatrix * combinedViewMatrix * modelMatrix
|
||||
// where textureCoordsMatrix is just a scale and bias computation: [-1,1] to [0,1]
|
||||
uniform dmat4 shadowMatrix;
|
||||
out vec4 shadowCoords;
|
||||
#endif
|
||||
// ShadowMatrix is the matrix defined by:
|
||||
// textureCoordsMatrix * projectionMatrix * combinedViewMatrix * modelMatrix
|
||||
// where textureCoordsMatrix is just a scale and bias computation: [-1,1] to [0,1]
|
||||
uniform dmat4 shadowMatrix;
|
||||
out vec4 shadowCoords;
|
||||
#endif // SHADOW_MAPPING_ENABLED
|
||||
|
||||
uniform mat4 modelViewProjectionTransform;
|
||||
uniform mat4 modelViewTransform;
|
||||
@@ -68,78 +68,77 @@ uniform float chunkMinHeight;
|
||||
uniform float distanceScaleFactor;
|
||||
uniform int chunkLevel;
|
||||
|
||||
|
||||
struct PositionNormalPair {
|
||||
vec3 position;
|
||||
vec3 normal;
|
||||
vec3 position;
|
||||
vec3 normal;
|
||||
};
|
||||
|
||||
PositionNormalPair globalInterpolation(vec2 uv) {
|
||||
vec2 lonlat = lonLatScalingFactor * uv + minLatLon;
|
||||
vec2 lonlat = lonLatScalingFactor * uv + minLatLon;
|
||||
|
||||
// geodetic surface normal
|
||||
float cosLat = cos(lonlat.y);
|
||||
vec3 normal = vec3(cosLat * cos(lonlat.x), cosLat * sin(lonlat.x), sin(lonlat.y));
|
||||
vec3 k = radiiSquared * normal;
|
||||
float gamma = sqrt(dot(k, normal));
|
||||
// geodetic surface normal
|
||||
float cosLat = cos(lonlat.y);
|
||||
vec3 normal = vec3(cosLat * cos(lonlat.x), cosLat * sin(lonlat.x), sin(lonlat.y));
|
||||
vec3 k = radiiSquared * normal;
|
||||
float gamma = sqrt(dot(k, normal));
|
||||
|
||||
PositionNormalPair result;
|
||||
result.position = k / gamma;
|
||||
result.normal = normal;
|
||||
return result;
|
||||
PositionNormalPair result;
|
||||
result.position = k / gamma;
|
||||
result.normal = normal;
|
||||
return result;
|
||||
}
|
||||
|
||||
vec3 getLevelWeights(float distToVertexOnEllipsoid) {
|
||||
float projectedScaleFactor = distanceScaleFactor / distToVertexOnEllipsoid;
|
||||
float desiredLevel = log2(projectedScaleFactor);
|
||||
float levelInterp = chunkLevel - desiredLevel;
|
||||
float projectedScaleFactor = distanceScaleFactor / distToVertexOnEllipsoid;
|
||||
float desiredLevel = log2(projectedScaleFactor);
|
||||
float levelInterp = chunkLevel - desiredLevel;
|
||||
|
||||
return vec3(
|
||||
clamp(1.0 - levelInterp, 0.0, 1.0),
|
||||
clamp(levelInterp, 0.0, 1.0) - clamp(levelInterp - 1.0, 0.0, 1.0),
|
||||
clamp(levelInterp - 1.0, 0.0, 1.0)
|
||||
);
|
||||
return vec3(
|
||||
clamp(1.0 - levelInterp, 0.0, 1.0),
|
||||
clamp(levelInterp, 0.0, 1.0) - clamp(levelInterp - 1.0, 0.0, 1.0),
|
||||
clamp(levelInterp - 1.0, 0.0, 1.0)
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
PositionNormalPair pair = globalInterpolation(in_uv);
|
||||
float distToVertexOnEllipsoid = length((pair.normal * chunkMinHeight + pair.position) - cameraPosition);
|
||||
PositionNormalPair pair = globalInterpolation(in_uv);
|
||||
float distToVertexOnEllipsoid = length((pair.normal * chunkMinHeight + pair.position) - cameraPosition);
|
||||
|
||||
// use level weight for height sampling, and output to fragment shader
|
||||
levelWeights = getLevelWeights(distToVertexOnEllipsoid);
|
||||
// use level weight for height sampling, and output to fragment shader
|
||||
levelWeights = getLevelWeights(distToVertexOnEllipsoid);
|
||||
|
||||
// Get the height value and apply skirts
|
||||
float height = getTileHeight(in_uv, levelWeights) - getTileVertexSkirtLength();
|
||||
// Get the height value and apply skirts
|
||||
float height = getTileHeight(in_uv, levelWeights) - getTileVertexSkirtLength();
|
||||
|
||||
#if USE_ACCURATE_NORMALS
|
||||
// Calculate tangents
|
||||
// tileDelta is a step length (epsilon). Should be small enough for accuracy but not
|
||||
// Too small for precision. 1 / 512 is good.
|
||||
const float tileDelta = 1.0 / 512.0;
|
||||
PositionNormalPair pair10 = globalInterpolation(vec2(1.0, 0.0) * tileDelta + in_uv);
|
||||
PositionNormalPair pair01 = globalInterpolation(vec2(0.0, 1.0) * tileDelta + in_uv);
|
||||
vec3 ellipsoidTangentTheta = normalize(pair10.position - pair.position);
|
||||
vec3 ellipsoidTangentPhi = normalize(pair01.position - pair.position);
|
||||
ellipsoidTangentThetaCameraSpace = mat3(modelViewTransform) * ellipsoidTangentTheta;
|
||||
ellipsoidTangentPhiCameraSpace = mat3(modelViewTransform) * ellipsoidTangentPhi;
|
||||
// Calculate tangents
|
||||
// tileDelta is a step length (epsilon). Should be small enough for accuracy but not
|
||||
// Too small for precision. 1 / 512 is good.
|
||||
const float tileDelta = 1.0 / 512.0;
|
||||
PositionNormalPair pair10 = globalInterpolation(vec2(1.0, 0.0) * tileDelta + in_uv);
|
||||
PositionNormalPair pair01 = globalInterpolation(vec2(0.0, 1.0) * tileDelta + in_uv);
|
||||
vec3 ellipsoidTangentTheta = normalize(pair10.position - pair.position);
|
||||
vec3 ellipsoidTangentPhi = normalize(pair01.position - pair.position);
|
||||
ellipsoidTangentThetaCameraSpace = mat3(modelViewTransform) * ellipsoidTangentTheta;
|
||||
ellipsoidTangentPhiCameraSpace = mat3(modelViewTransform) * ellipsoidTangentPhi;
|
||||
#endif // USE_ACCURATE_NORMALS
|
||||
|
||||
// Add the height in the direction of the normal
|
||||
pair.position = pair.normal * height + pair.position;
|
||||
vec4 positionClippingSpace = modelViewProjectionTransform * vec4(pair.position, 1.0);
|
||||
// Add the height in the direction of the normal
|
||||
pair.position = pair.normal * height + pair.position;
|
||||
vec4 positionClippingSpace = modelViewProjectionTransform * vec4(pair.position, 1.0);
|
||||
|
||||
// Write output
|
||||
fs_uv = in_uv;
|
||||
fs_position = z_normalization(positionClippingSpace);
|
||||
gl_Position = fs_position;
|
||||
ellipsoidNormalCameraSpace = mat3(modelViewTransform) * pair.normal;
|
||||
positionCameraSpace = vec3(modelViewTransform * vec4(pair.position, 1.0));
|
||||
// Write output
|
||||
fs_uv = in_uv;
|
||||
fs_position = z_normalization(positionClippingSpace);
|
||||
gl_Position = fs_position;
|
||||
ellipsoidNormalCameraSpace = mat3(modelViewTransform) * pair.normal;
|
||||
positionCameraSpace = vec3(modelViewTransform * vec4(pair.position, 1.0));
|
||||
|
||||
#if USE_ECLIPSE_SHADOWS
|
||||
positionWorldSpace = vec3(modelTransform * dvec4(pair.position, 1.0));
|
||||
#endif
|
||||
positionWorldSpace = vec3(modelTransform * dvec4(pair.position, 1.0));
|
||||
#endif // USE_ECLIPSE_SHADOWS
|
||||
|
||||
#if SHADOW_MAPPING_ENABLED
|
||||
shadowCoords = vec4(shadowMatrix * dvec4(pair.position, 1.0));
|
||||
#endif
|
||||
shadowCoords = vec4(shadowMatrix * dvec4(pair.position, 1.0));
|
||||
#endif // SHADOW_MAPPING_ENABLED
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@
|
||||
#version __CONTEXT__
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetilemapping.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tileheight.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tilevertexskirt.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.glsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetilemapping.glsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tileheight.glsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tilevertexskirt.glsl>
|
||||
|
||||
layout(location = 1) in vec2 in_uv;
|
||||
|
||||
@@ -39,22 +39,22 @@ out vec3 levelWeights;
|
||||
out vec3 positionCameraSpace;
|
||||
|
||||
#if USE_ACCURATE_NORMALS
|
||||
out vec3 ellipsoidTangentThetaCameraSpace;
|
||||
out vec3 ellipsoidTangentPhiCameraSpace;
|
||||
out vec3 ellipsoidTangentThetaCameraSpace;
|
||||
out vec3 ellipsoidTangentPhiCameraSpace;
|
||||
#endif // USE_ACCURATE_NORMALS
|
||||
|
||||
#if USE_ECLIPSE_SHADOWS
|
||||
out vec3 positionWorldSpace;
|
||||
uniform dmat4 inverseViewTransform;
|
||||
#endif
|
||||
#endif // USE_ECLIPSE_SHADOWS
|
||||
|
||||
#if SHADOW_MAPPING_ENABLED
|
||||
// ShadowMatrix is the matrix defined by:
|
||||
// textureCoordsMatrix * projectionMatrix * combinedViewMatrix * modelMatrix
|
||||
// where textureCoordsMatrix is just a scale and bias computation: [-1,1] to [0,1]
|
||||
uniform dmat4 shadowMatrix;
|
||||
out vec4 shadowCoords;
|
||||
#endif
|
||||
// ShadowMatrix is the matrix defined by:
|
||||
// textureCoordsMatrix * projectionMatrix * combinedViewMatrix * modelMatrix
|
||||
// where textureCoordsMatrix is just a scale and bias computation: [-1,1] to [0,1]
|
||||
uniform dmat4 shadowMatrix;
|
||||
out vec4 shadowCoords;
|
||||
#endif // SHADOW_MAPPING_ENABLED
|
||||
|
||||
uniform mat4 projectionTransform;
|
||||
// Input points in camera space
|
||||
@@ -69,60 +69,60 @@ uniform float distanceScaleFactor;
|
||||
uniform int chunkLevel;
|
||||
|
||||
vec3 bilinearInterpolation(vec2 uv) {
|
||||
vec3 p0 = mix(p00, p10, uv.x);
|
||||
vec3 p1 = mix(p01, p11, uv.x);
|
||||
return mix(p0, p1, uv.y);
|
||||
vec3 p0 = mix(p00, p10, uv.x);
|
||||
vec3 p1 = mix(p01, p11, uv.x);
|
||||
return mix(p0, p1, uv.y);
|
||||
}
|
||||
|
||||
vec3 getLevelWeights(float distToVertexOnEllipsoid) {
|
||||
float projectedScaleFactor = distanceScaleFactor / distToVertexOnEllipsoid;
|
||||
float desiredLevel = log2(projectedScaleFactor);
|
||||
float levelInterp = chunkLevel - desiredLevel;
|
||||
float projectedScaleFactor = distanceScaleFactor / distToVertexOnEllipsoid;
|
||||
float desiredLevel = log2(projectedScaleFactor);
|
||||
float levelInterp = chunkLevel - desiredLevel;
|
||||
|
||||
return vec3(
|
||||
clamp(1.0 - levelInterp, 0.0, 1.0),
|
||||
clamp(levelInterp, 0.0, 1.0) - clamp(levelInterp - 1.0, 0.0, 1.0),
|
||||
clamp(levelInterp - 1.0, 0.0, 1.0)
|
||||
);
|
||||
return vec3(
|
||||
clamp(1.0 - levelInterp, 0.0, 1.0),
|
||||
clamp(levelInterp, 0.0, 1.0) - clamp(levelInterp - 1.0, 0.0, 1.0),
|
||||
clamp(levelInterp - 1.0, 0.0, 1.0)
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
// Position in cameraspace
|
||||
vec3 p = bilinearInterpolation(in_uv);
|
||||
|
||||
// Calculate desired level based on distance to the vertex on the ellipsoid
|
||||
// Before any heightmapping is done
|
||||
float distToVertexOnEllipsoid = length(p + patchNormalCameraSpace * chunkMinHeight);
|
||||
// Position in cameraspace
|
||||
vec3 p = bilinearInterpolation(in_uv);
|
||||
|
||||
// Calculate desired level based on distance to the vertex on the ellipsoid
|
||||
// Before any heightmapping is done
|
||||
float distToVertexOnEllipsoid = length(p + patchNormalCameraSpace * chunkMinHeight);
|
||||
|
||||
// use level weight for height sampling, and output to fragment shader
|
||||
levelWeights = getLevelWeights(distToVertexOnEllipsoid);
|
||||
// use level weight for height sampling, and output to fragment shader
|
||||
levelWeights = getLevelWeights(distToVertexOnEllipsoid);
|
||||
|
||||
// Get the height value and apply skirts
|
||||
float height = getTileHeightScaled(in_uv, levelWeights) - getTileVertexSkirtLength();
|
||||
|
||||
// Translate the point along normal
|
||||
p += patchNormalCameraSpace * height;
|
||||
// Get the height value and apply skirts
|
||||
float height = getTileHeightScaled(in_uv, levelWeights) - getTileVertexSkirtLength();
|
||||
|
||||
// Translate the point along normal
|
||||
p += patchNormalCameraSpace * height;
|
||||
|
||||
vec4 positionClippingSpace = projectionTransform * vec4(p, 1);
|
||||
vec4 positionClippingSpace = projectionTransform * vec4(p, 1);
|
||||
|
||||
#if USE_ACCURATE_NORMALS
|
||||
// Calculate tangents
|
||||
ellipsoidTangentThetaCameraSpace = normalize(p10 - p00);
|
||||
ellipsoidTangentPhiCameraSpace = normalize(p01 - p00);
|
||||
// Calculate tangents
|
||||
ellipsoidTangentThetaCameraSpace = normalize(p10 - p00);
|
||||
ellipsoidTangentPhiCameraSpace = normalize(p01 - p00);
|
||||
#endif // USE_ACCURATE_NORMALS
|
||||
|
||||
// Write output
|
||||
fs_uv = in_uv;
|
||||
fs_position = z_normalization(positionClippingSpace);
|
||||
gl_Position = fs_position;
|
||||
ellipsoidNormalCameraSpace = patchNormalCameraSpace;
|
||||
positionCameraSpace = p;
|
||||
// Write output
|
||||
fs_uv = in_uv;
|
||||
fs_position = z_normalization(positionClippingSpace);
|
||||
gl_Position = fs_position;
|
||||
ellipsoidNormalCameraSpace = patchNormalCameraSpace;
|
||||
positionCameraSpace = p;
|
||||
|
||||
#if USE_ECLIPSE_SHADOWS
|
||||
positionWorldSpace = vec3(inverseViewTransform * dvec4(p, 1.0));
|
||||
#endif
|
||||
positionWorldSpace = vec3(inverseViewTransform * dvec4(p, 1.0));
|
||||
#endif // USE_ECLIPSE_SHADOWS
|
||||
|
||||
#if SHADOW_MAPPING_ENABLED
|
||||
shadowCoords = vec4(shadowMatrix * dvec4(p, 1.0));
|
||||
#endif
|
||||
shadowCoords = vec4(shadowMatrix * dvec4(p, 1.0));
|
||||
#endif // SHADOW_MAPPING_ENABLED
|
||||
}
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
|
||||
#include "fragment.glsl"
|
||||
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetilemapping.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tileheight.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.glsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/texturetilemapping.glsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tileheight.glsl>
|
||||
#include "PowerScaling/powerScaling_fs.hglsl"
|
||||
|
||||
// Below are all the tiles that are used for contributing the actual fragment color
|
||||
@@ -49,15 +49,13 @@ uniform Layer WaterMasks[NUMLAYERS_WATERMASK];
|
||||
|
||||
#if SHOW_HEIGHT_RESOLUTION
|
||||
uniform vec2 vertexResolution;
|
||||
#endif
|
||||
#endif // SHOW_HEIGHT_RESOLUTION
|
||||
|
||||
//#if USE_NIGHTTEXTURE || USE_WATERMASK || PERFORM_SHADING
|
||||
uniform vec3 lightDirectionCameraSpace;
|
||||
//#endif
|
||||
|
||||
#if PERFORM_SHADING
|
||||
uniform float orenNayarRoughness;
|
||||
#endif
|
||||
#endif // PERFORM_SHADING
|
||||
|
||||
#if SHADOW_MAPPING_ENABLED
|
||||
|
||||
@@ -67,23 +65,22 @@ uniform float orenNayarRoughness;
|
||||
in vec4 shadowCoords;
|
||||
uniform sampler2DShadow shadowMapTexture;
|
||||
uniform float zFightingPercentage;
|
||||
#endif
|
||||
#endif // SHADOW_MAPPING_ENABLED
|
||||
|
||||
#if USE_ECLIPSE_SHADOWS
|
||||
|
||||
|
||||
#define NSEclipseShadowsMinusOne #{nEclipseShadows}
|
||||
#define NSEclipseShadows (NSEclipseShadowsMinusOne + 1)
|
||||
|
||||
/*******************************************************************************
|
||||
***** ALL CALCULATIONS FOR ECLIPSE ARE IN METERS AND IN WORLD SPACE SYSTEM ****
|
||||
*******************************************************************************/
|
||||
***** ALL CALCULATIONS FOR ECLIPSE ARE IN METERS AND IN WORLD SPACE SYSTEM ****
|
||||
*******************************************************************************/
|
||||
struct ShadowRenderingStruct {
|
||||
double xu, xp;
|
||||
double rs, rc;
|
||||
dvec3 sourceCasterVec;
|
||||
dvec3 casterPositionVec;
|
||||
bool isShadowing;
|
||||
double xu, xp;
|
||||
double rs, rc;
|
||||
dvec3 sourceCasterVec;
|
||||
dvec3 casterPositionVec;
|
||||
bool isShadowing;
|
||||
};
|
||||
|
||||
// Eclipse shadow data
|
||||
@@ -96,48 +93,46 @@ uniform bool hardShadows;
|
||||
vec4 calcShadow(const ShadowRenderingStruct shadowInfoArray[NSEclipseShadows],
|
||||
const dvec3 position, const bool ground)
|
||||
{
|
||||
#for i in 0..#{nEclipseShadows}
|
||||
if (shadowInfoArray[#{i}].isShadowing) {
|
||||
dvec3 pc = shadowInfoArray[#{i}].casterPositionVec - position;
|
||||
dvec3 sc_norm = shadowInfoArray[#{i}].sourceCasterVec;
|
||||
dvec3 pc_proj = dot(pc, sc_norm) * sc_norm;
|
||||
dvec3 d = pc - pc_proj;
|
||||
#for i in 0..#{nEclipseShadows}
|
||||
if (shadowInfoArray[#{i}].isShadowing) {
|
||||
dvec3 pc = shadowInfoArray[#{i}].casterPositionVec - position;
|
||||
dvec3 sc_norm = shadowInfoArray[#{i}].sourceCasterVec;
|
||||
dvec3 pc_proj = dot(pc, sc_norm) * sc_norm;
|
||||
dvec3 d = pc - pc_proj;
|
||||
|
||||
float length_d = float(length(d));
|
||||
double length_pc_proj = length(pc_proj);
|
||||
|
||||
float length_d = float(length(d));
|
||||
double length_pc_proj = length(pc_proj);
|
||||
float r_p_pi = float(shadowInfoArray[#{i}].rc * (length_pc_proj + shadowInfoArray[#{i}].xp) / shadowInfoArray[#{i}].xp);
|
||||
float r_u_pi = float(shadowInfoArray[#{i}].rc * (shadowInfoArray[#{i}].xu - length_pc_proj) / shadowInfoArray[#{i}].xu);
|
||||
|
||||
float r_p_pi = float(shadowInfoArray[#{i}].rc * (length_pc_proj + shadowInfoArray[#{i}].xp) / shadowInfoArray[#{i}].xp);
|
||||
float r_u_pi = float(shadowInfoArray[#{i}].rc * (shadowInfoArray[#{i}].xu - length_pc_proj) / shadowInfoArray[#{i}].xu);
|
||||
|
||||
if (length_d < r_u_pi) { // umbra
|
||||
if (ground) {
|
||||
#if USE_ECLIPSE_HARD_SHADOWS
|
||||
return vec4(0.2, 0.2, 0.2, 1.0);
|
||||
#else
|
||||
// butterworthFunc
|
||||
return vec4(vec3(sqrt(r_u_pi / (r_u_pi + pow(length_d, 2.0)))), 1.0);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
#if USE_ECLIPSE_HARD_SHADOWS
|
||||
return vec4(0.5, 0.5, 0.5, 1.0);
|
||||
#else
|
||||
return vec4(vec3(length_d / r_p_pi), 1.0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (length_d < r_p_pi) {// penumbra
|
||||
#if USE_ECLIPSE_HARD_SHADOWS
|
||||
return vec4(0.5, 0.5, 0.5, 1.0);
|
||||
#else
|
||||
return vec4(vec3(length_d / r_p_pi), 1.0);
|
||||
#endif
|
||||
}
|
||||
if (length_d < r_u_pi) { // umbra
|
||||
if (ground) {
|
||||
#if USE_ECLIPSE_HARD_SHADOWS
|
||||
return vec4(0.2, 0.2, 0.2, 1.0);
|
||||
#else
|
||||
// butterworthFunc
|
||||
return vec4(vec3(sqrt(r_u_pi / (r_u_pi + pow(length_d, 2.0)))), 1.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endfor
|
||||
return vec4(1.0);
|
||||
else {
|
||||
#if USE_ECLIPSE_HARD_SHADOWS
|
||||
return vec4(0.5, 0.5, 0.5, 1.0);
|
||||
#else
|
||||
return vec4(vec3(length_d / r_p_pi), 1.0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if (length_d < r_p_pi) {// penumbra
|
||||
#if USE_ECLIPSE_HARD_SHADOWS
|
||||
return vec4(0.5, 0.5, 0.5, 1.0);
|
||||
#else
|
||||
return vec4(vec3(length_d / r_p_pi), 1.0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endfor
|
||||
return vec4(1.0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -148,8 +143,8 @@ in vec3 levelWeights;
|
||||
in vec3 positionCameraSpace;
|
||||
|
||||
#if USE_ACCURATE_NORMALS
|
||||
in vec3 ellipsoidTangentThetaCameraSpace;
|
||||
in vec3 ellipsoidTangentPhiCameraSpace;
|
||||
in vec3 ellipsoidTangentThetaCameraSpace;
|
||||
in vec3 ellipsoidTangentPhiCameraSpace;
|
||||
#endif // USE_ACCURATE_NORMALS
|
||||
|
||||
#if USE_ECLIPSE_SHADOWS
|
||||
@@ -158,146 +153,142 @@ in vec3 positionWorldSpace;
|
||||
|
||||
uniform float opacity;
|
||||
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
frag.color = vec4(0.3, 0.3, 0.3, 1.0);
|
||||
Fragment frag;
|
||||
frag.color = vec4(0.3, 0.3, 0.3, 1.0);
|
||||
|
||||
vec3 normal = normalize(ellipsoidNormalCameraSpace);
|
||||
vec3 normal = normalize(ellipsoidNormalCameraSpace);
|
||||
|
||||
#if USE_ACCURATE_NORMALS
|
||||
normal = getTileNormal(
|
||||
fs_uv,
|
||||
levelWeights,
|
||||
normalize(ellipsoidNormalCameraSpace),
|
||||
normalize(ellipsoidTangentThetaCameraSpace),
|
||||
normalize(ellipsoidTangentPhiCameraSpace)
|
||||
);
|
||||
normal = getTileNormal(
|
||||
fs_uv,
|
||||
levelWeights,
|
||||
normalize(ellipsoidNormalCameraSpace),
|
||||
normalize(ellipsoidTangentThetaCameraSpace),
|
||||
normalize(ellipsoidTangentPhiCameraSpace)
|
||||
);
|
||||
#endif /// USE_ACCURATE_NORMALS
|
||||
|
||||
#if USE_COLORTEXTURE
|
||||
frag.color = calculateColor(frag.color, fs_uv, levelWeights, ColorLayers);
|
||||
frag.color = calculateColor(frag.color, fs_uv, levelWeights, ColorLayers);
|
||||
#endif // USE_COLORTEXTURE
|
||||
|
||||
#if USE_WATERMASK
|
||||
float waterReflectance = 0.0;
|
||||
frag.color = calculateWater(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
levelWeights,
|
||||
WaterMasks,
|
||||
normal,
|
||||
lightDirectionCameraSpace, // Should already be normalized
|
||||
positionCameraSpace,
|
||||
waterReflectance
|
||||
);
|
||||
|
||||
float waterReflectance = 0.0;
|
||||
frag.color = calculateWater(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
levelWeights,
|
||||
WaterMasks,
|
||||
normal,
|
||||
lightDirectionCameraSpace, // Should already be normalized
|
||||
positionCameraSpace,
|
||||
waterReflectance
|
||||
);
|
||||
#endif // USE_WATERMASK
|
||||
|
||||
#if USE_NIGHTTEXTURE
|
||||
frag.color = calculateNight(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
levelWeights,
|
||||
NightLayers,
|
||||
normalize(ellipsoidNormalCameraSpace),
|
||||
lightDirectionCameraSpace // Should already be normalized
|
||||
);
|
||||
|
||||
frag.color = calculateNight(
|
||||
frag.color,
|
||||
fs_uv,
|
||||
levelWeights,
|
||||
NightLayers,
|
||||
normalize(ellipsoidNormalCameraSpace),
|
||||
lightDirectionCameraSpace // Should already be normalized
|
||||
);
|
||||
#endif // USE_NIGHTTEXTURE
|
||||
|
||||
#if PERFORM_SHADING
|
||||
frag.color = calculateShadedColor(
|
||||
frag.color,
|
||||
normal,
|
||||
lightDirectionCameraSpace,
|
||||
normalize(positionCameraSpace),
|
||||
orenNayarRoughness
|
||||
);
|
||||
frag.color = calculateShadedColor(
|
||||
frag.color,
|
||||
normal,
|
||||
lightDirectionCameraSpace,
|
||||
normalize(positionCameraSpace),
|
||||
orenNayarRoughness
|
||||
);
|
||||
#endif // PERFORM_SHADING
|
||||
|
||||
#if USE_ECLIPSE_SHADOWS
|
||||
frag.color *= calcShadow(shadowDataArray, dvec3(positionWorldSpace), true);
|
||||
#endif
|
||||
frag.color *= calcShadow(shadowDataArray, dvec3(positionWorldSpace), true);
|
||||
#endif // USE_ECLIPSE_SHADOWS
|
||||
|
||||
#if USE_OVERLAY
|
||||
frag.color = calculateOverlay(frag.color, fs_uv, levelWeights, Overlays);
|
||||
frag.color = calculateOverlay(frag.color, fs_uv, levelWeights, Overlays);
|
||||
#endif // USE_OVERLAY
|
||||
|
||||
#if SHOW_HEIGHT_INTENSITIES
|
||||
frag.color.rgb *= vec3(0.1);
|
||||
frag.color.rgb *= vec3(0.1);
|
||||
|
||||
float untransformedHeight = getUntransformedTileVertexHeight(fs_uv, levelWeights);
|
||||
float contourLine = fract(10.0 * untransformedHeight) > 0.98 ? 1.0 : 0.0;
|
||||
frag.color.r += untransformedHeight;
|
||||
frag.color.b = contourLine;
|
||||
#endif
|
||||
float untransformedHeight = getUntransformedTileVertexHeight(fs_uv, levelWeights);
|
||||
float contourLine = fract(10.0 * untransformedHeight) > 0.98 ? 1.0 : 0.0;
|
||||
frag.color.r += untransformedHeight;
|
||||
frag.color.b = contourLine;
|
||||
#endif // SHOW_HEIGHT_INTENSITIES
|
||||
|
||||
#if SHOW_HEIGHT_RESOLUTION
|
||||
frag.color += 0.0001 * calculateDebugColor(fs_uv, fs_position, vertexResolution);
|
||||
#if USE_HEIGHTMAP
|
||||
frag.color.r = min(frag.color.r, 0.8);
|
||||
frag.color.r += tileResolution(fs_uv, HeightLayers[0].pile.chunkTile0) > 0.9 ? 1 : 0;
|
||||
#endif
|
||||
#endif
|
||||
frag.color += 0.0001 * calculateDebugColor(fs_uv, fs_position, vertexResolution);
|
||||
#if USE_HEIGHTMAP
|
||||
frag.color.r = min(frag.color.r, 0.8);
|
||||
frag.color.r += tileResolution(fs_uv, HeightLayers[0].pile.chunkTile0) > 0.9 ? 1 : 0;
|
||||
#endif // USE_HEIGHTMAP
|
||||
#endif // SHOW_HEIGHT_RESOLUTION
|
||||
|
||||
// Other data
|
||||
// Other data
|
||||
#if USE_WATERMASK
|
||||
// Water reflectance is added to the G-Buffer.
|
||||
frag.gNormal.w = waterReflectance;
|
||||
// Water reflectance is added to the G-Buffer.
|
||||
frag.gNormal.w = waterReflectance;
|
||||
#else
|
||||
frag.gNormal.w = 0.0;
|
||||
frag.gNormal.w = 0.0;
|
||||
#endif
|
||||
// Normal is written View Space (Including SGCT View Matrix).
|
||||
frag.gNormal.xyz = normal;
|
||||
// Normal is written View Space (Including SGCT View Matrix).
|
||||
frag.gNormal.xyz = normal;
|
||||
|
||||
if (dot(positionCameraSpace, vec3(1.0)) != 0.0) {
|
||||
frag.gPosition = vec4(positionCameraSpace, 1.0); // in Camera Rig Space
|
||||
}
|
||||
else {
|
||||
frag.gPosition = vec4(1.0); // in Camera Rig Space
|
||||
}
|
||||
if (dot(positionCameraSpace, vec3(1.0)) != 0.0) {
|
||||
frag.gPosition = vec4(positionCameraSpace, 1.0); // in Camera Rig Space
|
||||
}
|
||||
else {
|
||||
frag.gPosition = vec4(1.0); // in Camera Rig Space
|
||||
}
|
||||
|
||||
frag.depth = fs_position.w;
|
||||
frag.depth = fs_position.w;
|
||||
|
||||
#if SHOW_CHUNK_EDGES
|
||||
const float BorderSize = 0.005;
|
||||
const vec3 BorderColor = vec3(1.0, 0.0, 0.0);
|
||||
const float BorderSize = 0.005;
|
||||
const vec3 BorderColor = vec3(1.0, 0.0, 0.0);
|
||||
|
||||
vec2 uvOffset = fs_uv - vec2(0.5);
|
||||
float thres = 0.5 - BorderSize * 0.5;
|
||||
bool isBorder = abs(uvOffset.x) > thres || abs(uvOffset.y) > thres;
|
||||
if (isBorder) {
|
||||
frag.color.rgb += BorderColor;
|
||||
}
|
||||
vec2 uvOffset = fs_uv - vec2(0.5);
|
||||
float thres = 0.5 - BorderSize * 0.5;
|
||||
bool isBorder = abs(uvOffset.x) > thres || abs(uvOffset.y) > thres;
|
||||
if (isBorder) {
|
||||
frag.color.rgb += BorderColor;
|
||||
}
|
||||
#endif // SHOW_CHUNK_EDGES
|
||||
|
||||
#if SHADOW_MAPPING_ENABLED
|
||||
float shadow = 1.0;
|
||||
if (shadowCoords.w > 1) {
|
||||
vec4 normalizedShadowCoords = shadowCoords;
|
||||
normalizedShadowCoords.z = normalizeFloat(zFightingPercentage * normalizedShadowCoords.w);
|
||||
normalizedShadowCoords.xy = normalizedShadowCoords.xy / normalizedShadowCoords.w;
|
||||
normalizedShadowCoords.w = 1.0;
|
||||
float shadow = 1.0;
|
||||
if (shadowCoords.w > 1) {
|
||||
vec4 normalizedShadowCoords = shadowCoords;
|
||||
normalizedShadowCoords.z = normalizeFloat(zFightingPercentage * normalizedShadowCoords.w);
|
||||
normalizedShadowCoords.xy = normalizedShadowCoords.xy / normalizedShadowCoords.w;
|
||||
normalizedShadowCoords.w = 1.0;
|
||||
|
||||
float sum = 0;
|
||||
#for i in 0..#{nShadowSamples}
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, 0));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, NSSamples - #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , NSSamples - #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, 0));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, NSSamples - #{i}));
|
||||
#endfor
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(0, 0));
|
||||
shadow = sum / (8.0 * NSSamples + 1.f);
|
||||
}
|
||||
frag.color.xyz *= shadow < 0.99 ? clamp(shadow + 0.3, 0.0, 1.0) : shadow;
|
||||
float sum = 0;
|
||||
#for i in 0..#{nShadowSamples}
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, 0));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, NSSamples - #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , NSSamples - #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, 0));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, NSSamples - #{i}));
|
||||
#endfor
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(0, 0));
|
||||
shadow = sum / (8.0 * NSSamples + 1.f);
|
||||
}
|
||||
frag.color.xyz *= shadow < 0.99 ? clamp(shadow + 0.3, 0.0, 1.0) : shadow;
|
||||
#endif
|
||||
|
||||
frag.color.a *= opacity;
|
||||
|
||||
return frag;
|
||||
frag.color.a *= opacity;
|
||||
return frag;
|
||||
}
|
||||
|
||||
@@ -38,91 +38,82 @@ uniform vec2 textureOffset;
|
||||
uniform float colorFilterValue;
|
||||
|
||||
uniform vec3 sunPosition;
|
||||
uniform float _nightFactor;
|
||||
uniform float nightFactor;
|
||||
uniform float zFightingPercentage;
|
||||
|
||||
// temp
|
||||
in vec4 fragPosInLightSpace;
|
||||
|
||||
|
||||
Fragment getFragment() {
|
||||
// Moving the origin to the center
|
||||
vec2 st = (vs_st - vec2(0.5)) * 2.0;
|
||||
// Moving the origin to the center
|
||||
vec2 st = (vs_st - vec2(0.5)) * 2.0;
|
||||
|
||||
// The length of the texture coordinates vector is our distance from the center
|
||||
float radius = length(st);
|
||||
// The length of the texture coordinates vector is our distance from the center
|
||||
float radius = length(st);
|
||||
|
||||
// We only want to consider ring-like objects so we need to discard everything else
|
||||
if (radius > 1.0) {
|
||||
discard;
|
||||
// We only want to consider ring-like objects so we need to discard everything else
|
||||
if (radius > 1.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
// Remapping the texture coordinates
|
||||
// Radius \in [0,1], texCoord \in [textureOffset.x, textureOffset.y]
|
||||
// textureOffset.x -> 0
|
||||
// textureOffset.y -> 1
|
||||
float texCoord = (radius - textureOffset.x) / (textureOffset.y - textureOffset.x);
|
||||
if (texCoord < 0.0 || texCoord > 1.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
vec4 diffuse = texture(ringTexture, texCoord);
|
||||
// divided by 3 as length of vec3(1.0, 1.0, 1.0) will return 3 and we want
|
||||
// to normalize the alpha value to [0,1]
|
||||
float colorValue = length(diffuse.rgb) / 3.0;
|
||||
if (colorValue < colorFilterValue) {
|
||||
diffuse.a = colorValue * colorFilterValue;
|
||||
if (diffuse.a < 0.65) {
|
||||
discard;
|
||||
}
|
||||
|
||||
// Remapping the texture coordinates
|
||||
// Radius \in [0,1], texCoord \in [textureOffset.x, textureOffset.y]
|
||||
// textureOffset.x -> 0
|
||||
// textureOffset.y -> 1
|
||||
float texCoord = (radius - textureOffset.x) / (textureOffset.y - textureOffset.x);
|
||||
if (texCoord < 0.f || texCoord > 1.f) {
|
||||
discard;
|
||||
}
|
||||
|
||||
vec4 diffuse = texture(ringTexture, texCoord);
|
||||
// divided by 3 as length of vec3(1.0, 1.0, 1.0) will return 3 and we want
|
||||
// to normalize the alpha value to [0,1]
|
||||
float colorValue = length(diffuse.rgb) / 3.0;
|
||||
if (colorValue < colorFilterValue) {
|
||||
diffuse.a = colorValue * colorFilterValue;
|
||||
if (diffuse.a < 0.65)
|
||||
discard;
|
||||
}
|
||||
|
||||
// shadow == 1.0 means it is not in shadow
|
||||
float shadow = 1.0;
|
||||
if (shadowCoords.z >= 0) {
|
||||
vec4 normalizedShadowCoords = shadowCoords;
|
||||
normalizedShadowCoords.z = normalizeFloat(zFightingPercentage * normalizedShadowCoords.w);
|
||||
normalizedShadowCoords.xy = normalizedShadowCoords.xy / normalizedShadowCoords.w;
|
||||
normalizedShadowCoords.w = 1.0;
|
||||
|
||||
float sum = 0;
|
||||
#for i in 0..#{nShadowSamples}
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, 0));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, NSSamples - #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , NSSamples - #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, 0));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, NSSamples - #{i}));
|
||||
#endfor
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(0, 0));
|
||||
shadow = clamp(sum / (8.0 * NSSamples + 1.f), 0.35, 1.0);
|
||||
}
|
||||
|
||||
// The normal for the one plane depends on whether we are dealing
|
||||
// with a front facing or back facing fragment
|
||||
vec3 normal;
|
||||
// The plane is oriented on the xz plane
|
||||
// WARNING: This might not be the case for Uranus
|
||||
if (gl_FrontFacing) {
|
||||
normal = vec3(-1.0, 0.0, 0.0);
|
||||
}
|
||||
else {
|
||||
normal = vec3(1.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
// Reduce the color of the fragment by the user factor
|
||||
// if we are facing away from the Sun
|
||||
if (dot(sunPosition, normal) < 0) {
|
||||
diffuse.xyz *= _nightFactor;
|
||||
}
|
||||
|
||||
Fragment frag;
|
||||
|
||||
frag.color = diffuse * shadow;
|
||||
frag.depth = vs_screenSpaceDepth;
|
||||
frag.gPosition = vec4(1e30, 1e30, 1e30, 1.0);
|
||||
frag.gNormal = vec4(normal, 1.0);
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
// shadow == 1.0 means it is not in shadow
|
||||
float shadow = 1.0;
|
||||
if (shadowCoords.z >= 0) {
|
||||
vec4 normalizedShadowCoords = shadowCoords;
|
||||
normalizedShadowCoords.z = normalizeFloat(zFightingPercentage * normalizedShadowCoords.w);
|
||||
normalizedShadowCoords.xy = normalizedShadowCoords.xy / normalizedShadowCoords.w;
|
||||
normalizedShadowCoords.w = 1.0;
|
||||
|
||||
float sum = 0;
|
||||
#for i in 0..#{nShadowSamples}
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, 0));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(-NSSamples + #{i}, NSSamples - #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( 0 , NSSamples - #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, -NSSamples + #{i}));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, 0));
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2( NSSamples - #{i}, NSSamples - #{i}));
|
||||
#endfor
|
||||
sum += textureProjOffset(shadowMapTexture, normalizedShadowCoords, ivec2(0, 0));
|
||||
shadow = clamp(sum / (8.0 * NSSamples + 1.0), 0.35, 1.0);
|
||||
}
|
||||
|
||||
// The normal for the one plane depends on whether we are dealing
|
||||
// with a front facing or back facing fragment
|
||||
// The plane is oriented on the xz plane
|
||||
// WARNING: This might not be the case for Uranus
|
||||
vec3 normal = gl_FrontFacing ? vec3(-1.0, 0.0, 0.0) : vec3(1.0, 0.0, 0.0);
|
||||
|
||||
// Reduce the color of the fragment by the user factor
|
||||
// if we are facing away from the Sun
|
||||
if (dot(sunPosition, normal) < 0.0) {
|
||||
diffuse.xyz *= _nightFactor;
|
||||
}
|
||||
|
||||
Fragment frag;
|
||||
|
||||
frag.color = diffuse * shadow;
|
||||
frag.depth = vs_screenSpaceDepth;
|
||||
frag.gPosition = vec4(1e30, 1e30, 1e30, 1.0);
|
||||
frag.gNormal = vec4(normal, 1.0);
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
@@ -32,43 +32,43 @@ uniform sampler1D ringTexture;
|
||||
uniform vec2 textureOffset;
|
||||
|
||||
Fragment getFragment() {
|
||||
// Moving the origin to the center
|
||||
vec2 st = (vs_st - vec2(0.5)) * 2.0;
|
||||
// Moving the origin to the center
|
||||
vec2 st = (vs_st - vec2(0.5)) * 2.0;
|
||||
|
||||
// The length of the texture coordinates vector is our distance from the center
|
||||
float radius = length(st);
|
||||
// The length of the texture coordinates vector is our distance from the center
|
||||
float radius = length(st);
|
||||
|
||||
// We only want to consider ring-like objects so we need to discard everything else
|
||||
if (radius > 1.0) {
|
||||
discard;
|
||||
}
|
||||
// We only want to consider ring-like objects so we need to discard everything else
|
||||
if (radius > 1.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
// Remapping the texture coordinates
|
||||
// Radius \in [0,1], texCoord \in [textureOffset.x, textureOffset.y]
|
||||
// textureOffset.x -> 0
|
||||
// textureOffset.y -> 1
|
||||
float texCoord = (radius - textureOffset.x) / (textureOffset.y - textureOffset.x);
|
||||
if (texCoord < 0.f || texCoord > 1.f) {
|
||||
discard;
|
||||
}
|
||||
// Remapping the texture coordinates
|
||||
// Radius \in [0,1], texCoord \in [textureOffset.x, textureOffset.y]
|
||||
// textureOffset.x -> 0
|
||||
// textureOffset.y -> 1
|
||||
float texCoord = (radius - textureOffset.x) / (textureOffset.y - textureOffset.x);
|
||||
if (texCoord < 0.0 || texCoord > 1.0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
float diffuse = length(texture(ringTexture, texCoord).rgb);
|
||||
|
||||
// The normal for the one plane depends on whether we are dealing
|
||||
// with a front facing or back facing fragment
|
||||
//vec3 normal;
|
||||
// The plane is oriented on the xz plane
|
||||
// WARNING: This might not be the case for Uranus
|
||||
// if (gl_FrontFacing) {
|
||||
// normal = vec3(-1.0, 0.0, 0.0);
|
||||
// }
|
||||
// else {
|
||||
// normal = vec3(1.0, 0.0, 0.0);
|
||||
// }
|
||||
float diffuse = length(texture(ringTexture, texCoord).rgb);
|
||||
|
||||
// The normal for the one plane depends on whether we are dealing
|
||||
// with a front facing or back facing fragment
|
||||
//vec3 normal;
|
||||
// The plane is oriented on the xz plane
|
||||
// WARNING: This might not be the case for Uranus
|
||||
// if (gl_FrontFacing) {
|
||||
// normal = vec3(-1.0, 0.0, 0.0);
|
||||
// }
|
||||
// else {
|
||||
// normal = vec3(1.0, 0.0, 0.0);
|
||||
// }
|
||||
|
||||
Fragment frag;
|
||||
frag.color = vec4(vec3(vs_screenSpaceDepth), 1.0);
|
||||
frag.depth = (diffuse < 0.5) ? 1E30 : vs_screenSpaceDepth;
|
||||
|
||||
return frag;
|
||||
Fragment frag;
|
||||
frag.color = vec4(vec3(vs_screenSpaceDepth), 1.0);
|
||||
frag.depth = (diffuse < 0.5) ? 1E30 : vs_screenSpaceDepth;
|
||||
|
||||
return frag;
|
||||
}
|
||||
|
||||
@@ -35,13 +35,10 @@ out float vs_screenSpaceDepth;
|
||||
uniform dmat4 modelViewProjectionMatrix;
|
||||
|
||||
void main() {
|
||||
vs_st = in_st;
|
||||
vs_st = in_st;
|
||||
|
||||
dvec4 positionClipSpace = modelViewProjectionMatrix *
|
||||
dvec4(in_position, 0.0, 1.0);
|
||||
vec4 positionClipSpaceZNorm = z_normalization(vec4(positionClipSpace));
|
||||
|
||||
vs_screenSpaceDepth = positionClipSpaceZNorm.w;
|
||||
|
||||
gl_Position = positionClipSpaceZNorm;
|
||||
dvec4 positionClipSpace = modelViewProjectionMatrix * dvec4(in_position, 0.0, 1.0);
|
||||
vec4 positionClipSpaceZNorm = z_normalization(vec4(positionClipSpace));
|
||||
vs_screenSpaceDepth = positionClipSpaceZNorm.w;
|
||||
gl_Position = positionClipSpaceZNorm;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ layout(location = 1) in vec2 in_st;
|
||||
|
||||
out vec2 vs_st;
|
||||
out float vs_screenSpaceDepth;
|
||||
out vec4 vs_positionViewSpace;
|
||||
out vec4 shadowCoords;
|
||||
|
||||
uniform dmat4 modelViewProjectionMatrix;
|
||||
@@ -42,12 +41,12 @@ uniform dmat4 modelViewProjectionMatrix;
|
||||
uniform dmat4 shadowMatrix;
|
||||
|
||||
void main() {
|
||||
vs_st = in_st;
|
||||
vs_st = in_st;
|
||||
|
||||
dvec4 positionClipSpace = modelViewProjectionMatrix * dvec4(in_position, 0.0, 1.0);
|
||||
vec4 positionClipSpaceZNorm = z_normalization(vec4(positionClipSpace));
|
||||
|
||||
shadowCoords = vec4(shadowMatrix * dvec4(in_position, 0.0, 1.0));
|
||||
vs_screenSpaceDepth = positionClipSpaceZNorm.w;
|
||||
gl_Position = positionClipSpaceZNorm;
|
||||
dvec4 positionClipSpace = modelViewProjectionMatrix * dvec4(in_position, 0.0, 1.0);
|
||||
vec4 positionClipSpaceZNorm = z_normalization(vec4(positionClipSpace));
|
||||
|
||||
shadowCoords = vec4(shadowMatrix * dvec4(in_position, 0.0, 1.0));
|
||||
vs_screenSpaceDepth = positionClipSpaceZNorm.w;
|
||||
gl_Position = positionClipSpaceZNorm;
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2021 *
|
||||
* *
|
||||
* 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_fs.hglsl"
|
||||
#include "fragment.glsl"
|
||||
|
||||
precision highp float;
|
||||
|
||||
in vec2 texCoord;
|
||||
|
||||
uniform highp sampler2D shadowMapTexture;
|
||||
|
||||
Fragment getFragment() {
|
||||
Fragment frag;
|
||||
frag.color = vec4(vec3(1.f) - texture(shadowMapTexture, texCoord).rrr, 1.f);
|
||||
frag.depth = 0.f;
|
||||
|
||||
return frag;
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2021 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#version __CONTEXT__
|
||||
|
||||
out vec2 texCoord;
|
||||
|
||||
const vec3 posData[6] = vec3[] (
|
||||
vec3(1.0, -0.5, 0.0),
|
||||
vec3(0.5, -0.5, 0.0),
|
||||
vec3(0.5, -1.0, 0.0),
|
||||
vec3(1.0, -1.0, 0.0),
|
||||
vec3(1.0, -0.5, 0.0),
|
||||
vec3(0.5, -1.0, 0.0)
|
||||
);
|
||||
|
||||
const vec2 texData[6] = vec2[] (
|
||||
vec2(1.0, 1.0),
|
||||
vec2(0.0, 1.0),
|
||||
vec2(0.0, 0.0),
|
||||
vec2(1.0, 0.0),
|
||||
vec2(1.0, 1.0),
|
||||
vec2(0.0, 0.0)
|
||||
|
||||
);
|
||||
|
||||
void main() {
|
||||
texCoord = texData[gl_VertexID];
|
||||
gl_Position = vec4(posData[gl_VertexID], 1.0);
|
||||
}
|
||||
@@ -0,0 +1,457 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2021 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef TEXTURETILEMAPPING_HGLSL
|
||||
#define TEXTURETILEMAPPING_HGLSL
|
||||
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.glsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/blending.glsl>
|
||||
|
||||
// First layer type from LayerShaderManager is height map
|
||||
#define NUMLAYERS_HEIGHTMAP #{lastLayerIndexHeightLayers} + 1
|
||||
#define USE_HEIGHTMAP #{useHeightLayers}
|
||||
#define HEIGHTMAP_BLENDING_ENABLED #{blendHeightLayers}
|
||||
|
||||
// Second layer type from LayerShaderManager is color texture
|
||||
#define NUMLAYERS_COLORTEXTURE #{lastLayerIndexColorLayers} + 1
|
||||
#define USE_COLORTEXTURE #{useColorLayers}
|
||||
#define COLORTEXTURE_BLENDING_ENABLED #{blendColorLayers}
|
||||
|
||||
// Third layer type from LayerShaderManager is water mask
|
||||
#define NUMLAYERS_WATERMASK #{lastLayerIndexWaterMasks} + 1
|
||||
#define USE_WATERMASK #{useWaterMasks}
|
||||
#define WATERMASK_BLENDING_ENABLED #{blendWaterMasks}
|
||||
|
||||
// Fourth layer type from LayerShaderManager is night texture
|
||||
#define NUMLAYERS_NIGHTTEXTURE #{lastLayerIndexNightLayers} + 1
|
||||
#define USE_NIGHTTEXTURE #{useNightLayers}
|
||||
#define NIGHTTEXTURE_BLENDING_ENABLED #{blendNightLayers}
|
||||
|
||||
// Fifth layer type from LayerShaderManager is overlay
|
||||
#define NUMLAYERS_OVERLAY #{lastLayerIndexOverlays} + 1
|
||||
#define USE_OVERLAY #{useOverlays}
|
||||
#define OVERLAY_BLENDING_ENABLED #{blendOverlays}
|
||||
|
||||
// Global constants
|
||||
#define CHUNK_DEFAULT_HEIGHT #{defaultHeight}
|
||||
|
||||
// Other key value pairs used for settings
|
||||
#define USE_ACCURATE_NORMALS #{useAccurateNormals}
|
||||
#define PERFORM_SHADING #{performShading}
|
||||
#define USE_ECLIPSE_SHADOWS #{useEclipseShadows}
|
||||
#define USE_ECLIPSE_HARD_SHADOWS #{useEclipseHardShadows}
|
||||
#define SHOW_CHUNK_EDGES #{showChunkEdges}
|
||||
#define SHOW_HEIGHT_RESOLUTION #{showHeightResolution}
|
||||
#define SHOW_HEIGHT_INTENSITIES #{showHeightIntensities}
|
||||
#define SHADOW_MAPPING_ENABLED #{enableShadowMapping}
|
||||
|
||||
const vec3 DefaultLevelWeights = vec3(1.0, 0.0, 0.0);
|
||||
|
||||
float orenNayarDiffuse(vec3 lightDirection, vec3 viewDirection, vec3 surfaceNormal,
|
||||
float roughness)
|
||||
{
|
||||
// calculate intermediary values
|
||||
float NdotL = dot(surfaceNormal, lightDirection);
|
||||
float NdotV = dot(surfaceNormal, viewDirection);
|
||||
|
||||
float angleVN = acos(NdotV);
|
||||
float angleLN = acos(NdotL);
|
||||
|
||||
float alpha = max(angleVN, angleLN);
|
||||
float beta = min(angleVN, angleLN);
|
||||
float gamma = dot(
|
||||
viewDirection - surfaceNormal * dot(viewDirection, surfaceNormal),
|
||||
lightDirection - surfaceNormal * dot(lightDirection, surfaceNormal)
|
||||
);
|
||||
|
||||
float roughnessSquared = roughness * roughness;
|
||||
|
||||
// calculate A and B
|
||||
float A = 1.0 - 0.5 * (roughnessSquared / (roughnessSquared + 0.57));
|
||||
float B = 0.45 * (roughnessSquared / (roughnessSquared + 0.09));
|
||||
float C = sin(alpha) * tan(beta);
|
||||
|
||||
// put it all together
|
||||
return max(0.0, NdotL) * (A + B * max(0.0, gamma) * C);
|
||||
}
|
||||
|
||||
float performLayerSettings(float value, LayerSettings settings) {
|
||||
float v = pow(abs(value), settings.gamma) * settings.multiplier + settings.offset;
|
||||
return sign(value) * v * settings.opacity;
|
||||
}
|
||||
|
||||
vec4 performLayerSettings(vec4 currentValue, LayerSettings settings) {
|
||||
vec3 newValue = sign(currentValue.rgb) * pow(abs(currentValue.rgb), vec3(settings.gamma)) *
|
||||
settings.multiplier + settings.offset;
|
||||
return vec4(newValue, currentValue.a * settings.opacity);
|
||||
}
|
||||
|
||||
vec2 tileUVToTextureSamplePosition(ChunkTile chunkTile, vec2 tileUV, PixelPadding padding)
|
||||
{
|
||||
vec2 uv = chunkTile.uvTransform.uvOffset + chunkTile.uvTransform.uvScale * tileUV;
|
||||
|
||||
// compensateSourceTextureSampling
|
||||
ivec2 resolution = textureSize(chunkTile.textureSampler, 0);
|
||||
vec2 sourceSize = vec2(resolution) + padding.sizeDifference;
|
||||
vec2 currentSize = vec2(resolution);
|
||||
vec2 sourceToCurrentSize = currentSize / sourceSize;
|
||||
return sourceToCurrentSize * (uv - padding.startOffset / sourceSize);
|
||||
}
|
||||
|
||||
vec4 getTexVal(ChunkTilePile chunkTilePile, vec3 w, vec2 uv, PixelPadding padding) {
|
||||
vec4 v1 = texture(
|
||||
chunkTilePile.chunkTile0.textureSampler,
|
||||
tileUVToTextureSamplePosition(chunkTilePile.chunkTile0, uv, padding)
|
||||
);
|
||||
vec4 v2 = texture(
|
||||
chunkTilePile.chunkTile1.textureSampler,
|
||||
tileUVToTextureSamplePosition(chunkTilePile.chunkTile1, uv, padding)
|
||||
);
|
||||
vec4 v3 = texture(
|
||||
chunkTilePile.chunkTile2.textureSampler,
|
||||
tileUVToTextureSamplePosition(chunkTilePile.chunkTile2, uv, padding)
|
||||
);
|
||||
|
||||
return w.x * v1 + w.y * v2 + w.z * v3;
|
||||
}
|
||||
|
||||
#for id, layerGroup in layerGroups
|
||||
#for i in 0..#{lastLayerIndex#{layerGroup}}
|
||||
|
||||
vec4 getSample#{layerGroup}#{i}(vec2 uv, vec3 levelWeights,
|
||||
Layer #{layerGroup}[#{lastLayerIndex#{layerGroup}} + 1])
|
||||
{
|
||||
vec4 c = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
// All tile layers are the same. Sample from texture
|
||||
#if (#{#{layerGroup}#{i}LayerType} == 0) // DefaultTileLayer
|
||||
c = getTexVal(#{layerGroup}[#{i}].pile, levelWeights, uv, #{layerGroup}[#{i}].padding);
|
||||
#elif (#{#{layerGroup}#{i}LayerType} == 1) // SingleImageTileLayer
|
||||
c = getTexVal(#{layerGroup}[#{i}].pile, levelWeights, uv, #{layerGroup}[#{i}].padding);
|
||||
#elif (#{#{layerGroup}#{i}LayerType} == 2) // SizeReferenceTileLayer
|
||||
c = getTexVal(#{layerGroup}[#{i}].pile, levelWeights, uv, #{layerGroup}[#{i}].padding);
|
||||
#elif (#{#{layerGroup}#{i}LayerType} == 3) // TemporalTileLayer
|
||||
c = getTexVal(#{layerGroup}[#{i}].pile, levelWeights, uv, #{layerGroup}[#{i}].padding);
|
||||
#elif (#{#{layerGroup}#{i}LayerType} == 4) // TileIndexTileLayer
|
||||
c = getTexVal(#{layerGroup}[#{i}].pile, levelWeights, uv, #{layerGroup}[#{i}].padding);
|
||||
#elif (#{#{layerGroup}#{i}LayerType} == 5) // ByIndexTileLayer
|
||||
c = getTexVal(#{layerGroup}[#{i}].pile, levelWeights, uv, #{layerGroup}[#{i}].padding);
|
||||
#elif (#{#{layerGroup}#{i}LayerType} == 6) // ByLevelTileLayer
|
||||
c = getTexVal(#{layerGroup}[#{i}].pile, levelWeights, uv, #{layerGroup}[#{i}].padding);
|
||||
#elif (#{#{layerGroup}#{i}LayerType} == 7) // SolidColor
|
||||
c.rgb = #{layerGroup}[#{i}].color;
|
||||
#endif
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
#endfor
|
||||
#endfor
|
||||
|
||||
#define BlendModeDefault 0
|
||||
#define BlendModeMultiply 1
|
||||
#define BlendModeAdd 2
|
||||
#define BlendModeSubtract 3
|
||||
#define BlendModeColor 4
|
||||
|
||||
#for id, layerGroup in layerGroups
|
||||
#for i in 0..#{lastLayerIndex#{layerGroup}}
|
||||
|
||||
vec4 blend#{layerGroup}#{i}(vec4 currentColor, vec4 newColor, float blendFactor) {
|
||||
#if (#{#{layerGroup}#{i}BlendMode} == BlendModeDefault)
|
||||
return blendNormal(currentColor, vec4(newColor.rgb, newColor.a * blendFactor));
|
||||
#elif (#{#{layerGroup}#{i}BlendMode} == BlendModeMultiply)
|
||||
return blendMultiply(currentColor, newColor * blendFactor);
|
||||
#elif (#{#{layerGroup}#{i}BlendMode} == BlendModeAdd)
|
||||
return blendAdd(currentColor, newColor * blendFactor);
|
||||
#elif (#{#{layerGroup}#{i}BlendMode} == BlendModeSubtract)
|
||||
return blendSubtract(currentColor, newColor * blendFactor);
|
||||
#elif (#{#{layerGroup}#{i}BlendMode} == BlendModeColor)
|
||||
// Convert color to grayscale
|
||||
float gray = (newColor.r + newColor.g + newColor.b) / 3.0;
|
||||
|
||||
vec3 hsvCurrent = rgb2hsv(currentColor.rgb);
|
||||
// Use gray from new color as value in hsv
|
||||
vec3 hsvNew = vec3(hsvCurrent.x, hsvCurrent.y, gray);
|
||||
vec3 rgbNew = hsv2rgb(hsvNew);
|
||||
|
||||
vec4 color = blendNormal(currentColor, vec4(rgbNew, newColor.a * blendFactor));
|
||||
return color;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endfor
|
||||
#endfor
|
||||
|
||||
#define LayerAdjustmentTypeDefault 0
|
||||
#define LayerAdjustmentTypeChroma 1
|
||||
#define LayerAdjustmentTypeTransferFunction 1
|
||||
|
||||
#for id, layerGroup in layerGroups
|
||||
#for i in 0..#{lastLayerIndex#{layerGroup}}
|
||||
|
||||
vec4 performAdjustment#{layerGroup}#{i}(vec4 currentColor, LayerAdjustment adjustment) {
|
||||
#if (#{#{layerGroup}#{i}LayerAdjustmentType} == LayerAdjustmentTypeDefault)
|
||||
return currentColor;
|
||||
#elif (#{#{layerGroup}#{i}LayerAdjustmentType} == LayerAdjustmentTypeChroma)
|
||||
if (distance(currentColor.rgb, adjustment.chromaKeyColor) <=
|
||||
adjustment.chromaKeyTolerance)
|
||||
{
|
||||
return vec4(0.0);
|
||||
}
|
||||
else {
|
||||
return currentColor;
|
||||
}
|
||||
#elif (#{#{layerGroup}#{i}LayerAdjustmentType} == LayerAdjustmentTypeTransferFunction)
|
||||
return currentColor;
|
||||
#else
|
||||
return currentColor;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endfor
|
||||
#endfor
|
||||
|
||||
float calculateUntransformedHeight(vec2 uv, vec3 levelWeights,
|
||||
Layer HeightLayers[NUMLAYERS_HEIGHTMAP])
|
||||
{
|
||||
|
||||
float height = 0;
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if !HEIGHTMAP_BLENDING_ENABLED
|
||||
levelWeights = DefaultLevelWeights;
|
||||
#endif // HEIGHTMAP_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexHeightLayers}
|
||||
{
|
||||
vec4 colorSample = getSampleHeightLayers#{i}(uv, levelWeights, HeightLayers);
|
||||
colorSample = performAdjustmentHeightLayers#{i}(colorSample, HeightLayers[#{i}].adjustment);
|
||||
height = colorSample.r;
|
||||
|
||||
height = performLayerSettings(height, HeightLayers[#{i}].settings);
|
||||
}
|
||||
#endfor
|
||||
return height;
|
||||
}
|
||||
|
||||
float calculateHeight(vec2 uv, vec3 levelWeights, Layer HeightLayers[NUMLAYERS_HEIGHTMAP])
|
||||
{
|
||||
float height = 0;
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if !HEIGHTMAP_BLENDING_ENABLED
|
||||
levelWeights = DefaultLevelWeights;
|
||||
#endif // HEIGHTMAP_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexHeightLayers}
|
||||
{
|
||||
vec4 colorSample = getSampleHeightLayers#{i}(uv, levelWeights, HeightLayers);
|
||||
colorSample = performAdjustmentHeightLayers#{i}(colorSample, HeightLayers[#{i}].adjustment);
|
||||
float untransformedHeight = colorSample.r;
|
||||
|
||||
TileDepthTransform transform = HeightLayers[#{i}].depthTransform;
|
||||
float heightSample = transform.depthScale * untransformedHeight + transform.depthOffset;
|
||||
if (heightSample > -100000) {
|
||||
heightSample = performLayerSettings(heightSample, HeightLayers[#{i}].settings);
|
||||
height = heightSample;
|
||||
}
|
||||
}
|
||||
#endfor
|
||||
return height;
|
||||
}
|
||||
|
||||
vec4 calculateColor(vec4 currentColor, vec2 uv, vec3 levelWeights,
|
||||
Layer ColorLayers[NUMLAYERS_COLORTEXTURE])
|
||||
{
|
||||
vec4 color = currentColor;
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if !COLORTEXTURE_BLENDING_ENABLED
|
||||
levelWeights = DefaultLevelWeights;
|
||||
#endif // COLORTEXTURE_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexColorLayers}
|
||||
{
|
||||
vec4 colorSample = getSampleColorLayers#{i}(uv, levelWeights, ColorLayers);
|
||||
colorSample = performAdjustmentColorLayers#{i}(colorSample, ColorLayers[#{i}].adjustment);
|
||||
colorSample = performLayerSettings(colorSample, ColorLayers[#{i}].settings);
|
||||
|
||||
color = blendColorLayers#{i}(color, colorSample, 1.0);
|
||||
}
|
||||
#endfor
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
float gridDots(vec2 uv, vec2 gridResolution) {
|
||||
vec2 uvVertexSpace = fract((gridResolution) * uv) + 0.5;
|
||||
|
||||
vec2 uvDotSpace = abs(2.0 * (uvVertexSpace - 0.5));
|
||||
return 1.0 - length(1.0 - uvDotSpace);
|
||||
}
|
||||
|
||||
vec4 calculateDebugColor(vec2 uv, vec4 fragPos, vec2 vertexResolution) {
|
||||
vec2 uvVertexSpace = fract(vertexResolution * uv);
|
||||
vec3 colorUv = vec3(0.3 * uv.x, 0.3 * uv.y, 0);
|
||||
vec3 colorDistance = vec3(0.0, 0.0, min(0.4 * log(fragPos.w) - 3.9, 1));
|
||||
vec3 colorVertex = (1.0 - length(uvVertexSpace)) * vec3(0.5);
|
||||
vec3 colorSum = colorUv + colorDistance + colorVertex;
|
||||
return vec4(0.5 * colorSum, 1);
|
||||
}
|
||||
|
||||
float tileResolution(vec2 tileUV, ChunkTile chunkTile) {
|
||||
PixelPadding padding;
|
||||
padding.startOffset = ivec2(0);
|
||||
padding.sizeDifference = ivec2(0);
|
||||
|
||||
vec2 heightResolution = textureSize(chunkTile.textureSampler, 0);
|
||||
vec2 uv = tileUVToTextureSamplePosition(chunkTile, tileUV, padding);
|
||||
return gridDots(uv, heightResolution);
|
||||
}
|
||||
|
||||
vec4 calculateNight(vec4 currentColor, vec2 uv, vec3 levelWeights,
|
||||
Layer NightLayers[NUMLAYERS_NIGHTTEXTURE],
|
||||
vec3 ellipsoidNormalCameraSpace, vec3 lightDirectionCameraSpace)
|
||||
{
|
||||
vec4 nightColor = vec4(0.0);
|
||||
vec4 color = currentColor;
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if !NIGHTTEXTURE_BLENDING_ENABLED
|
||||
levelWeights = DefaultLevelWeights;
|
||||
#endif // NIGHTTEXTURE_BLENDING_ENABLED
|
||||
|
||||
vec3 n = normalize(ellipsoidNormalCameraSpace);
|
||||
vec3 l = lightDirectionCameraSpace;
|
||||
float cosineFactor = clamp(dot(l, normalize(n + 0.20 * l)) * 3 , 0, 1);
|
||||
|
||||
#for i in 0..#{lastLayerIndexNightLayers}
|
||||
{
|
||||
vec4 colorSample = getSampleNightLayers#{i}(uv, levelWeights, NightLayers);
|
||||
colorSample = performAdjustmentNightLayers#{i}(colorSample, NightLayers[#{i}].adjustment);
|
||||
colorSample = performLayerSettings(colorSample, NightLayers[#{i}].settings);
|
||||
|
||||
float adjustedAlpha = cosineFactor * colorSample.a;
|
||||
// Filter to night side
|
||||
vec4 newColor = vec4(cosineFactor * colorSample.xyz, adjustedAlpha);
|
||||
|
||||
color = blendNightLayers#{i}(color, newColor, adjustedAlpha);
|
||||
}
|
||||
#endfor
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4 calculateShadedColor(vec4 currentColor, vec3 ellipsoidNormalCameraSpace,
|
||||
vec3 lightDirectionCameraSpace, vec3 viewDirectionCameraSpace,
|
||||
float roughness)
|
||||
{
|
||||
vec3 shadedColor = currentColor.rgb * 0.05;
|
||||
|
||||
vec3 n = normalize(ellipsoidNormalCameraSpace);
|
||||
|
||||
float power = orenNayarDiffuse(
|
||||
-lightDirectionCameraSpace,
|
||||
viewDirectionCameraSpace,
|
||||
ellipsoidNormalCameraSpace,
|
||||
roughness
|
||||
);
|
||||
|
||||
vec3 l = lightDirectionCameraSpace;
|
||||
power = max(smoothstep(0.0, 0.1, max(dot(-l, n), 0.0)) * power, 0.0);
|
||||
|
||||
vec4 color = vec4(shadedColor + currentColor.rgb * power, currentColor.a);
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4 calculateOverlay(vec4 currentColor, vec2 uv, vec3 levelWeights,
|
||||
Layer Overlays[NUMLAYERS_OVERLAY])
|
||||
{
|
||||
vec4 color = currentColor;
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if !OVERLAY_BLENDING_ENABLED
|
||||
levelWeights = DefaultLevelWeights;
|
||||
#endif // OVERLAY_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexOverlays}
|
||||
{
|
||||
vec4 colorSample = getSampleOverlays#{i}(uv, levelWeights, Overlays);
|
||||
colorSample = performAdjustmentOverlays#{i}(colorSample, Overlays[#{i}].adjustment);
|
||||
|
||||
colorSample = performLayerSettings(colorSample, Overlays[#{i}].settings);
|
||||
|
||||
color = blendNormal(color, colorSample);
|
||||
color = blendOverlays#{i}(color, colorSample, 1.0);
|
||||
}
|
||||
#endfor
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4 calculateWater(vec4 currentColor, vec2 uv, vec3 levelWeights,
|
||||
Layer WaterMasks[NUMLAYERS_WATERMASK],
|
||||
vec3 ellipsoidNormalCameraSpace, vec3 lightDirectionCameraSpace,
|
||||
vec3 positionCameraSpace, out float reflectance)
|
||||
{
|
||||
vec4 waterColor = vec4(0.0);
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if !WATERMASK_BLENDING_ENABLED
|
||||
levelWeights = DefaultLevelWeights;
|
||||
#endif // WATERMASK_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexWaterMasks}
|
||||
{
|
||||
vec4 colorSample = getSampleWaterMasks#{i}(uv, levelWeights, WaterMasks);
|
||||
colorSample = performAdjustmentWaterMasks#{i}(colorSample, WaterMasks[#{i}].adjustment);
|
||||
|
||||
colorSample.a = performLayerSettings(colorSample.a, WaterMasks[#{i}].settings);
|
||||
|
||||
waterColor = blendWaterMasks#{i}(waterColor, colorSample, 1.0);
|
||||
}
|
||||
#endfor
|
||||
|
||||
vec3 directionToFragmentCameraSpace = normalize(positionCameraSpace - vec3(0, 0, 0));
|
||||
vec3 reflectionDirectionCameraSpace = reflect(lightDirectionCameraSpace, ellipsoidNormalCameraSpace);
|
||||
// float cosineFactor = clamp(dot(-reflectionDirectionCameraSpace, directionToFragmentCameraSpace), 0, 1);
|
||||
// cosineFactor = pow(cosineFactor, 100);
|
||||
|
||||
// const float specularIntensity = 0.4;
|
||||
// vec3 specularTotal = cosineFactor * specularIntensity * waterColor.a;
|
||||
|
||||
reflectance = waterColor.a;
|
||||
//return blendNormal(currentColor, waterColor);
|
||||
//return currentColor + vec4(specularTotal, 1);
|
||||
return currentColor;
|
||||
}
|
||||
|
||||
#endif // TEXTURETILEMAPPING_HGLSL
|
||||
@@ -1,461 +0,0 @@
|
||||
/*****************************************************************************************
|
||||
* *
|
||||
* OpenSpace *
|
||||
* *
|
||||
* Copyright (c) 2014-2021 *
|
||||
* *
|
||||
* 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. *
|
||||
****************************************************************************************/
|
||||
|
||||
#ifndef TEXTURETILEMAPPING_HGLSL
|
||||
#define TEXTURETILEMAPPING_HGLSL
|
||||
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/blending.hglsl>
|
||||
|
||||
// First layer type from LayerShaderManager is height map
|
||||
#define NUMLAYERS_HEIGHTMAP #{lastLayerIndexHeightLayers} + 1
|
||||
#define USE_HEIGHTMAP #{useHeightLayers}
|
||||
#define HEIGHTMAP_BLENDING_ENABLED #{blendHeightLayers}
|
||||
|
||||
// Second layer type from LayerShaderManager is color texture
|
||||
#define NUMLAYERS_COLORTEXTURE #{lastLayerIndexColorLayers} + 1
|
||||
#define USE_COLORTEXTURE #{useColorLayers}
|
||||
#define COLORTEXTURE_BLENDING_ENABLED #{blendColorLayers}
|
||||
|
||||
// Third layer type from LayerShaderManager is water mask
|
||||
#define NUMLAYERS_WATERMASK #{lastLayerIndexWaterMasks} + 1
|
||||
#define USE_WATERMASK #{useWaterMasks}
|
||||
#define WATERMASK_BLENDING_ENABLED #{blendWaterMasks}
|
||||
|
||||
// Fourth layer type from LayerShaderManager is night texture
|
||||
#define NUMLAYERS_NIGHTTEXTURE #{lastLayerIndexNightLayers} + 1
|
||||
#define USE_NIGHTTEXTURE #{useNightLayers}
|
||||
#define NIGHTTEXTURE_BLENDING_ENABLED #{blendNightLayers}
|
||||
|
||||
// Fifth layer type from LayerShaderManager is overlay
|
||||
#define NUMLAYERS_OVERLAY #{lastLayerIndexOverlays} + 1
|
||||
#define USE_OVERLAY #{useOverlays}
|
||||
#define OVERLAY_BLENDING_ENABLED #{blendOverlays}
|
||||
|
||||
// Global constants
|
||||
#define CHUNK_DEFAULT_HEIGHT #{defaultHeight}
|
||||
|
||||
// Other key value pairs used for settings
|
||||
#define USE_ACCURATE_NORMALS #{useAccurateNormals}
|
||||
#define PERFORM_SHADING #{performShading}
|
||||
#define USE_ECLIPSE_SHADOWS #{useEclipseShadows}
|
||||
#define USE_ECLIPSE_HARD_SHADOWS #{useEclipseHardShadows}
|
||||
#define SHOW_CHUNK_EDGES #{showChunkEdges}
|
||||
#define SHOW_HEIGHT_RESOLUTION #{showHeightResolution}
|
||||
#define SHOW_HEIGHT_INTENSITIES #{showHeightIntensities}
|
||||
#define SHADOW_MAPPING_ENABLED #{enableShadowMapping}
|
||||
|
||||
const vec3 DefaultLevelWeights = vec3(1.0, 0.0, 0.0);
|
||||
|
||||
float orenNayarDiffuse(vec3 lightDirection, vec3 viewDirection, vec3 surfaceNormal,
|
||||
float roughness)
|
||||
{
|
||||
// calculate intermediary values
|
||||
float NdotL = dot(surfaceNormal, lightDirection);
|
||||
float NdotV = dot(surfaceNormal, viewDirection);
|
||||
|
||||
float angleVN = acos(NdotV);
|
||||
float angleLN = acos(NdotL);
|
||||
|
||||
float alpha = max(angleVN, angleLN);
|
||||
float beta = min(angleVN, angleLN);
|
||||
float gamma = dot(
|
||||
viewDirection - surfaceNormal * dot(viewDirection, surfaceNormal),
|
||||
lightDirection - surfaceNormal * dot(lightDirection, surfaceNormal)
|
||||
);
|
||||
|
||||
float roughnessSquared = roughness * roughness;
|
||||
|
||||
// calculate A and B
|
||||
float A = 1.0 - 0.5 * (roughnessSquared / (roughnessSquared + 0.57));
|
||||
float B = 0.45 * (roughnessSquared / (roughnessSquared + 0.09));
|
||||
float C = sin(alpha) * tan(beta);
|
||||
|
||||
// put it all together
|
||||
return max(0.0, NdotL) * (A + B * max(0.0, gamma) * C);
|
||||
}
|
||||
|
||||
float performLayerSettings(float currentValue, LayerSettings settings) {
|
||||
float v = sign(currentValue) * pow(abs(currentValue), settings.gamma) *
|
||||
settings.multiplier + settings.offset;
|
||||
return v * settings.opacity;
|
||||
}
|
||||
|
||||
vec4 performLayerSettings(vec4 currentValue, LayerSettings settings) {
|
||||
vec3 newValue = sign(currentValue.rgb) * pow(abs(currentValue.rgb), vec3(settings.gamma)) *
|
||||
settings.multiplier + settings.offset;
|
||||
return vec4(newValue, currentValue.a * settings.opacity);
|
||||
}
|
||||
|
||||
vec2 tileUVToTextureSamplePosition(ChunkTile chunkTile, vec2 tileUV,
|
||||
PixelPadding padding)
|
||||
{
|
||||
vec2 uv = chunkTile.uvTransform.uvOffset + chunkTile.uvTransform.uvScale * tileUV;
|
||||
|
||||
// compensateSourceTextureSampling
|
||||
ivec2 resolution = textureSize(chunkTile.textureSampler, 0);
|
||||
vec2 sourceSize = vec2(resolution) + padding.sizeDifference;
|
||||
vec2 currentSize = vec2(resolution);
|
||||
vec2 sourceToCurrentSize = currentSize / sourceSize;
|
||||
return sourceToCurrentSize * (uv - padding.startOffset / sourceSize);
|
||||
}
|
||||
|
||||
vec4 getTexVal(ChunkTilePile chunkTilePile, vec3 w, vec2 uv,
|
||||
PixelPadding padding)
|
||||
{
|
||||
vec4 v1 = texture(
|
||||
chunkTilePile.chunkTile0.textureSampler,
|
||||
tileUVToTextureSamplePosition(chunkTilePile.chunkTile0, uv, padding)
|
||||
);
|
||||
vec4 v2 = texture(
|
||||
chunkTilePile.chunkTile1.textureSampler,
|
||||
tileUVToTextureSamplePosition(chunkTilePile.chunkTile1, uv, padding)
|
||||
);
|
||||
vec4 v3 = texture(
|
||||
chunkTilePile.chunkTile2.textureSampler,
|
||||
tileUVToTextureSamplePosition(chunkTilePile.chunkTile2, uv, padding)
|
||||
);
|
||||
|
||||
return w.x * v1 + w.y * v2 + w.z * v3;
|
||||
}
|
||||
|
||||
#for id, layerGroup in layerGroups
|
||||
#for i in 0..#{lastLayerIndex#{layerGroup}}
|
||||
|
||||
vec4 getSample#{layerGroup}#{i}(vec2 uv, vec3 levelWeights,
|
||||
Layer #{layerGroup}[#{lastLayerIndex#{layerGroup}} + 1])
|
||||
{
|
||||
vec4 color = vec4(0.0, 0.0, 0.0, 1.0);
|
||||
|
||||
// All tile layers are the same. Sample from texture
|
||||
#if (#{#{layerGroup}#{i}LayerType} == 0) // DefaultTileLayer
|
||||
color = getTexVal(#{layerGroup}[#{i}].pile, levelWeights, uv, #{layerGroup}[#{i}].padding);
|
||||
#elif (#{#{layerGroup}#{i}LayerType} == 1) // SingleImageTileLayer
|
||||
color = getTexVal(#{layerGroup}[#{i}].pile, levelWeights, uv, #{layerGroup}[#{i}].padding);
|
||||
#elif (#{#{layerGroup}#{i}LayerType} == 2) // SizeReferenceTileLayer
|
||||
color = getTexVal(#{layerGroup}[#{i}].pile, levelWeights, uv, #{layerGroup}[#{i}].padding);
|
||||
#elif (#{#{layerGroup}#{i}LayerType} == 3) // TemporalTileLayer
|
||||
color = getTexVal(#{layerGroup}[#{i}].pile, levelWeights, uv, #{layerGroup}[#{i}].padding);
|
||||
#elif (#{#{layerGroup}#{i}LayerType} == 4) // TileIndexTileLayer
|
||||
color = getTexVal(#{layerGroup}[#{i}].pile, levelWeights, uv, #{layerGroup}[#{i}].padding);
|
||||
#elif (#{#{layerGroup}#{i}LayerType} == 5) // ByIndexTileLayer
|
||||
color = getTexVal(#{layerGroup}[#{i}].pile, levelWeights, uv, #{layerGroup}[#{i}].padding);
|
||||
#elif (#{#{layerGroup}#{i}LayerType} == 6) // ByLevelTileLayer
|
||||
color = getTexVal(#{layerGroup}[#{i}].pile, levelWeights, uv, #{layerGroup}[#{i}].padding);
|
||||
#elif (#{#{layerGroup}#{i}LayerType} == 7) // SolidColor
|
||||
color.rgb = #{layerGroup}[#{i}].color;
|
||||
#endif
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
#endfor
|
||||
#endfor
|
||||
|
||||
#for id, layerGroup in layerGroups
|
||||
#for i in 0..#{lastLayerIndex#{layerGroup}}
|
||||
|
||||
vec4 blend#{layerGroup}#{i}(vec4 currentColor, vec4 newColor, float blendFactor) {
|
||||
#if (#{#{layerGroup}#{i}BlendMode} == 0) // Default, Normal
|
||||
return blendNormal(currentColor, vec4(newColor.rgb, newColor.a * blendFactor));
|
||||
#elif (#{#{layerGroup}#{i}BlendMode} == 1) // Multiply
|
||||
return blendMultiply(currentColor, newColor * blendFactor);
|
||||
#elif (#{#{layerGroup}#{i}BlendMode} == 2) // Add
|
||||
return blendAdd(currentColor, newColor * blendFactor);
|
||||
#elif (#{#{layerGroup}#{i}BlendMode} == 3) // Subtract
|
||||
return blendSubtract(currentColor, newColor * blendFactor);
|
||||
#elif (#{#{layerGroup}#{i}BlendMode} == 4) // Color
|
||||
// Convert color to grayscale
|
||||
float gray = (newColor.r + newColor.g + newColor.b) / 3.0;
|
||||
|
||||
vec3 hsvCurrent = rgb2hsv(currentColor.rgb);
|
||||
// Use gray from new color as value in hsv
|
||||
vec3 hsvNew = vec3(hsvCurrent.x, hsvCurrent.y, gray);
|
||||
vec3 rgbNew = hsv2rgb(hsvNew);
|
||||
|
||||
vec4 color = blendNormal(currentColor, vec4(rgbNew, newColor.a * blendFactor));
|
||||
return color;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endfor
|
||||
#endfor
|
||||
|
||||
|
||||
#for id, layerGroup in layerGroups
|
||||
#for i in 0..#{lastLayerIndex#{layerGroup}}
|
||||
|
||||
vec4 performAdjustment#{layerGroup}#{i}(vec4 currentColor,
|
||||
LayerAdjustment adjustment)
|
||||
{
|
||||
#if (#{#{layerGroup}#{i}LayerAdjustmentType} == 0) // Default, None
|
||||
return currentColor;
|
||||
#elif (#{#{layerGroup}#{i}LayerAdjustmentType} == 1) // ChromaKey
|
||||
if (distance(
|
||||
currentColor.rgb,
|
||||
adjustment.chromaKeyColor
|
||||
) <= adjustment.chromaKeyTolerance)
|
||||
{
|
||||
return vec4(0.0);
|
||||
}
|
||||
else {
|
||||
return currentColor;
|
||||
}
|
||||
#elif (#{#{layerGroup}#{i}LayerAdjustmentType} == 2) // TransferFunction
|
||||
return currentColor;
|
||||
#else
|
||||
return currentColor;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endfor
|
||||
#endfor
|
||||
|
||||
float calculateUntransformedHeight(vec2 uv, vec3 levelWeights,
|
||||
Layer HeightLayers[NUMLAYERS_HEIGHTMAP])
|
||||
{
|
||||
|
||||
float height = 0;
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if !HEIGHTMAP_BLENDING_ENABLED
|
||||
levelWeights = DefaultLevelWeights;
|
||||
#endif // HEIGHTMAP_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexHeightLayers}
|
||||
{
|
||||
vec4 colorSample = getSampleHeightLayers#{i}(uv, levelWeights, HeightLayers);
|
||||
colorSample = performAdjustmentHeightLayers#{i}(colorSample, HeightLayers[#{i}].adjustment);
|
||||
height = colorSample.r;
|
||||
|
||||
height = performLayerSettings(height, HeightLayers[#{i}].settings);
|
||||
}
|
||||
#endfor
|
||||
return height;
|
||||
}
|
||||
|
||||
float calculateHeight(vec2 uv, vec3 levelWeights, Layer HeightLayers[NUMLAYERS_HEIGHTMAP])
|
||||
{
|
||||
float height = 0;
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if !HEIGHTMAP_BLENDING_ENABLED
|
||||
levelWeights = DefaultLevelWeights;
|
||||
#endif // HEIGHTMAP_BLENDING_ENABLED
|
||||
|
||||
|
||||
#for i in 0..#{lastLayerIndexHeightLayers}
|
||||
{
|
||||
vec4 colorSample = getSampleHeightLayers#{i}(uv, levelWeights, HeightLayers);
|
||||
colorSample = performAdjustmentHeightLayers#{i}(colorSample, HeightLayers[#{i}].adjustment);
|
||||
float untransformedHeight = colorSample.r;
|
||||
|
||||
TileDepthTransform transform = HeightLayers[#{i}].depthTransform;
|
||||
float heightSample =
|
||||
transform.depthScale * untransformedHeight + transform.depthOffset;
|
||||
if (heightSample > -100000) {
|
||||
heightSample = performLayerSettings(heightSample, HeightLayers[#{i}].settings);
|
||||
height = heightSample;
|
||||
}
|
||||
}
|
||||
#endfor
|
||||
return height;
|
||||
}
|
||||
|
||||
vec4 calculateColor(vec4 currentColor, vec2 uv, vec3 levelWeights,
|
||||
Layer ColorLayers[NUMLAYERS_COLORTEXTURE])
|
||||
{
|
||||
vec4 color = currentColor;
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if !COLORTEXTURE_BLENDING_ENABLED
|
||||
levelWeights = DefaultLevelWeights;
|
||||
#endif // COLORTEXTURE_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexColorLayers}
|
||||
{
|
||||
vec4 colorSample = getSampleColorLayers#{i}(uv, levelWeights, ColorLayers);
|
||||
colorSample = performAdjustmentColorLayers#{i}(colorSample, ColorLayers[#{i}].adjustment);
|
||||
colorSample = performLayerSettings(colorSample, ColorLayers[#{i}].settings);
|
||||
|
||||
color = blendColorLayers#{i}(color, colorSample, 1.0);
|
||||
}
|
||||
#endfor
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
float gridDots(vec2 uv, vec2 gridResolution) {
|
||||
vec2 uvVertexSpace = fract((gridResolution) * uv) + 0.5;
|
||||
|
||||
vec2 uvDotSpace = abs(2.0 * (uvVertexSpace - 0.5));
|
||||
return 1.0 - length(1.0 - uvDotSpace);
|
||||
}
|
||||
|
||||
vec4 calculateDebugColor(vec2 uv, vec4 fragPos, vec2 vertexResolution) {
|
||||
vec2 uvVertexSpace = fract(vertexResolution * uv);
|
||||
vec3 colorUv = vec3(0.3 * uv.x, 0.3 * uv.y, 0);
|
||||
vec3 colorDistance = vec3(0.0, 0.0, min(0.4 * log(fragPos.w) - 3.9, 1));
|
||||
vec3 colorVertex = (1.0 - length(uvVertexSpace)) * vec3(0.5);
|
||||
vec3 colorSum = colorUv + colorDistance + colorVertex;
|
||||
return vec4(0.5 * colorSum, 1);
|
||||
}
|
||||
|
||||
float tileResolution(vec2 tileUV, ChunkTile chunkTile) {
|
||||
PixelPadding padding;
|
||||
padding.startOffset = ivec2(0);
|
||||
padding.sizeDifference = ivec2(0);
|
||||
|
||||
vec2 heightResolution = textureSize(chunkTile.textureSampler, 0);
|
||||
vec2 uv = tileUVToTextureSamplePosition(chunkTile, tileUV, padding);
|
||||
return gridDots(uv, heightResolution);
|
||||
}
|
||||
|
||||
vec4 calculateNight(vec4 currentColor, vec2 uv, vec3 levelWeights,
|
||||
Layer NightLayers[NUMLAYERS_NIGHTTEXTURE],
|
||||
vec3 ellipsoidNormalCameraSpace,
|
||||
vec3 lightDirectionCameraSpace)
|
||||
{
|
||||
vec4 nightColor = vec4(0.0);
|
||||
vec4 color = currentColor;
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if !NIGHTTEXTURE_BLENDING_ENABLED
|
||||
levelWeights = DefaultLevelWeights;
|
||||
#endif // NIGHTTEXTURE_BLENDING_ENABLED
|
||||
|
||||
vec3 n = normalize(ellipsoidNormalCameraSpace);
|
||||
vec3 l = lightDirectionCameraSpace;
|
||||
float cosineFactor = clamp(dot(l, normalize(n + 0.20 * l)) * 3 , 0, 1);
|
||||
|
||||
#for i in 0..#{lastLayerIndexNightLayers}
|
||||
{
|
||||
vec4 colorSample = getSampleNightLayers#{i}(uv, levelWeights, NightLayers);
|
||||
colorSample = performAdjustmentNightLayers#{i}(colorSample, NightLayers[#{i}].adjustment);
|
||||
colorSample = performLayerSettings(colorSample, NightLayers[#{i}].settings);
|
||||
|
||||
float adjustedAlpha = cosineFactor * colorSample.a;
|
||||
// Filter to night side
|
||||
vec4 newColor = vec4(cosineFactor * colorSample.xyz, adjustedAlpha);
|
||||
|
||||
color = blendNightLayers#{i}(color, newColor, adjustedAlpha);
|
||||
}
|
||||
#endfor
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4 calculateShadedColor(vec4 currentColor, vec3 ellipsoidNormalCameraSpace,
|
||||
vec3 lightDirectionCameraSpace, vec3 viewDirectionCameraSpace,
|
||||
float roughness)
|
||||
{
|
||||
vec3 shadedColor = currentColor.rgb * 0.05;
|
||||
|
||||
vec3 n = normalize(ellipsoidNormalCameraSpace);
|
||||
|
||||
float power = orenNayarDiffuse(
|
||||
-lightDirectionCameraSpace,
|
||||
viewDirectionCameraSpace,
|
||||
ellipsoidNormalCameraSpace,
|
||||
roughness);
|
||||
|
||||
vec3 l = lightDirectionCameraSpace;
|
||||
power = max(smoothstep(0.0f, 0.1f, max(dot(-l, n), 0.0f)) * power, 0.0f);
|
||||
|
||||
vec4 color = vec4(shadedColor + currentColor.rgb * power, currentColor.a);
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4 calculateOverlay(vec4 currentColor, vec2 uv, vec3 levelWeights,
|
||||
Layer Overlays[NUMLAYERS_OVERLAY])
|
||||
{
|
||||
vec4 color = currentColor;
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if !OVERLAY_BLENDING_ENABLED
|
||||
levelWeights = DefaultLevelWeights;
|
||||
#endif // OVERLAY_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexOverlays}
|
||||
{
|
||||
vec4 colorSample = getSampleOverlays#{i}(uv, levelWeights, Overlays);
|
||||
colorSample = performAdjustmentOverlays#{i}(colorSample, Overlays[#{i}].adjustment);
|
||||
|
||||
colorSample = performLayerSettings(colorSample, Overlays[#{i}].settings);
|
||||
|
||||
color = blendNormal(color, colorSample);
|
||||
color = blendOverlays#{i}(color, colorSample, 1.0);
|
||||
}
|
||||
#endfor
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
vec4 calculateWater(vec4 currentColor, vec2 uv, vec3 levelWeights,
|
||||
Layer WaterMasks[NUMLAYERS_WATERMASK],
|
||||
vec3 ellipsoidNormalCameraSpace,
|
||||
vec3 lightDirectionCameraSpace, vec3 positionCameraSpace,
|
||||
out float reflectance)
|
||||
{
|
||||
vec4 waterColor = vec4(0.0);
|
||||
|
||||
// The shader compiler will remove unused code when variables are multiplied by
|
||||
// a constant 0
|
||||
#if !WATERMASK_BLENDING_ENABLED
|
||||
levelWeights = DefaultLevelWeights;
|
||||
#endif // WATERMASK_BLENDING_ENABLED
|
||||
|
||||
#for i in 0..#{lastLayerIndexWaterMasks}
|
||||
{
|
||||
vec4 colorSample = getSampleWaterMasks#{i}(uv, levelWeights, WaterMasks);
|
||||
colorSample = performAdjustmentWaterMasks#{i}(colorSample, WaterMasks[#{i}].adjustment);
|
||||
|
||||
colorSample.a = performLayerSettings(colorSample.a, WaterMasks[#{i}].settings);
|
||||
|
||||
waterColor = blendWaterMasks#{i}(waterColor, colorSample, 1.0);
|
||||
}
|
||||
#endfor
|
||||
|
||||
vec3 directionToFragmentCameraSpace = normalize(positionCameraSpace - vec3(0, 0, 0));
|
||||
vec3 reflectionDirectionCameraSpace = reflect(lightDirectionCameraSpace, ellipsoidNormalCameraSpace);
|
||||
float cosineFactor = clamp(dot(-reflectionDirectionCameraSpace, directionToFragmentCameraSpace), 0, 1);
|
||||
cosineFactor = pow(cosineFactor, 100);
|
||||
|
||||
const vec3 specularColor = vec3(1.0);
|
||||
const float specularIntensity = 0.4;
|
||||
|
||||
vec3 specularTotal = specularColor * cosineFactor * specularIntensity * waterColor.a;
|
||||
|
||||
reflectance = waterColor.a;
|
||||
//return blendNormal(currentColor, waterColor);
|
||||
//return currentColor + vec4(specularTotal, 1);
|
||||
return currentColor;
|
||||
}
|
||||
|
||||
#endif // TEXTURETILEMAPPING_HGLSL
|
||||
+26
-26
@@ -26,53 +26,53 @@
|
||||
#define TEXTURETILE_HGLSL
|
||||
|
||||
struct TileDepthTransform {
|
||||
float depthScale;
|
||||
float depthOffset;
|
||||
float depthScale;
|
||||
float depthOffset;
|
||||
};
|
||||
|
||||
struct TileUvTransform {
|
||||
vec2 uvOffset;
|
||||
vec2 uvScale;
|
||||
vec2 uvOffset;
|
||||
vec2 uvScale;
|
||||
};
|
||||
|
||||
struct ChunkTile {
|
||||
sampler2D textureSampler;
|
||||
TileUvTransform uvTransform;
|
||||
sampler2D textureSampler;
|
||||
TileUvTransform uvTransform;
|
||||
};
|
||||
|
||||
struct PixelPadding {
|
||||
ivec2 startOffset;
|
||||
ivec2 sizeDifference;
|
||||
ivec2 startOffset;
|
||||
ivec2 sizeDifference;
|
||||
};
|
||||
|
||||
struct ChunkTilePile {
|
||||
ChunkTile chunkTile0;
|
||||
ChunkTile chunkTile1;
|
||||
ChunkTile chunkTile2;
|
||||
ChunkTile chunkTile0;
|
||||
ChunkTile chunkTile1;
|
||||
ChunkTile chunkTile2;
|
||||
};
|
||||
|
||||
struct LayerSettings {
|
||||
float opacity;
|
||||
float gamma;
|
||||
float multiplier;
|
||||
float offset;
|
||||
float valueBlending;
|
||||
float opacity;
|
||||
float gamma;
|
||||
float multiplier;
|
||||
float offset;
|
||||
float valueBlending;
|
||||
};
|
||||
|
||||
struct LayerAdjustment {
|
||||
vec3 chromaKeyColor;
|
||||
float chromaKeyTolerance;
|
||||
vec3 chromaKeyColor;
|
||||
float chromaKeyTolerance;
|
||||
};
|
||||
|
||||
struct Layer {
|
||||
ChunkTilePile pile;
|
||||
TileDepthTransform depthTransform;
|
||||
LayerSettings settings;
|
||||
LayerAdjustment adjustment;
|
||||
PixelPadding padding;
|
||||
|
||||
// Other layer type properties stuff
|
||||
vec3 color;
|
||||
ChunkTilePile pile;
|
||||
TileDepthTransform depthTransform;
|
||||
LayerSettings settings;
|
||||
LayerAdjustment adjustment;
|
||||
PixelPadding padding;
|
||||
|
||||
// Other layer type properties stuff
|
||||
vec3 color;
|
||||
};
|
||||
|
||||
#endif // TEXTURETILE_HGLSL
|
||||
+29
-34
@@ -26,16 +26,15 @@
|
||||
#define TILE_HEIGHT_HGLSL
|
||||
|
||||
#include "PowerScaling/powerScaling_vs.hglsl"
|
||||
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.hglsl>
|
||||
#include <${MODULE_GLOBEBROWSING}/shaders/tile.glsl>
|
||||
|
||||
#ifndef USE_HEIGHTMAP
|
||||
#define USE_HEIGHTMAP #{useAccurateNormals}
|
||||
#endif //USE_HEIGHTMAP
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
#ifndef USE_ACCURATE_NORMALS
|
||||
#define USE_ACCURATE_NORMALS #{useAccurateNormals}
|
||||
#endif //USE_ACCURATE_NORMALS
|
||||
#endif // USE_ACCURATE_NORMALS
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
uniform Layer HeightLayers[NUMLAYERS_HEIGHTMAP];
|
||||
@@ -48,42 +47,38 @@ uniform float deltaTheta1;
|
||||
uniform float deltaPhi0;
|
||||
uniform float deltaPhi1;
|
||||
uniform float tileDelta;
|
||||
#endif //USE_ACCURATE_NORMALS && USE_HEIGHTMAP
|
||||
#endif // USE_ACCURATE_NORMALS && USE_HEIGHTMAP
|
||||
|
||||
// levelWeights := Variable to determine which texture to sample from
|
||||
// HeightLayers := Three textures to sample from
|
||||
float getUntransformedTileHeight(vec2 uv, vec3 levelWeights) {
|
||||
float height = CHUNK_DEFAULT_HEIGHT;
|
||||
float height = CHUNK_DEFAULT_HEIGHT;
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
// Calculate desired level based on distance to the vertex on the ellipsoid
|
||||
// Before any heightmapping is done
|
||||
height = calculateUntransformedHeight(
|
||||
uv,
|
||||
levelWeights, // Variable to determine which texture to sample from
|
||||
HeightLayers // Three textures to sample from
|
||||
);
|
||||
// Calculate desired level based on distance to the vertex on the ellipsoid before any
|
||||
// heightmapping is done.
|
||||
height = calculateUntransformedHeight(uv, levelWeights, HeightLayers);
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
// levelWeights := Variable to determine which texture to sample from
|
||||
// HeightLayers := Three textures to sample from
|
||||
float getTileHeight(vec2 uv, vec3 levelWeights) {
|
||||
float height = CHUNK_DEFAULT_HEIGHT;
|
||||
float height = CHUNK_DEFAULT_HEIGHT;
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
// Calculate desired level based on distance to the vertex on the ellipsoid
|
||||
// Before any heightmapping is done
|
||||
height = calculateHeight(
|
||||
uv,
|
||||
levelWeights, // Variable to determine which texture to sample from
|
||||
HeightLayers // Three textures to sample from
|
||||
);
|
||||
// Calculate desired level based on distance to the vertex on the ellipsoid before any
|
||||
// heightmapping is done
|
||||
height = calculateHeight(uv, levelWeights, HeightLayers);
|
||||
#endif // USE_HEIGHTMAP
|
||||
|
||||
return height;
|
||||
}
|
||||
|
||||
float getTileHeightScaled(vec2 uv, vec3 levelWeights) {
|
||||
float height = getTileHeight(uv, levelWeights);
|
||||
float height = getTileHeight(uv, levelWeights);
|
||||
|
||||
#if USE_HEIGHTMAP
|
||||
height *= heightScale;
|
||||
@@ -96,25 +91,25 @@ vec3 getTileNormal(vec2 uv, vec3 levelWeights, vec3 ellipsoidNormalCameraSpace,
|
||||
vec3 ellipsoidTangentThetaCameraSpace,
|
||||
vec3 ellipsoidTangentPhiCameraSpace)
|
||||
{
|
||||
vec3 normal = ellipsoidNormalCameraSpace;
|
||||
vec3 normal = ellipsoidNormalCameraSpace;
|
||||
|
||||
#if USE_ACCURATE_NORMALS
|
||||
float deltaPhi = mix(deltaPhi0, deltaPhi1, uv.x);
|
||||
float deltaTheta = mix(deltaTheta0, deltaTheta1, uv.y);
|
||||
float deltaPhi = mix(deltaPhi0, deltaPhi1, uv.x);
|
||||
float deltaTheta = mix(deltaTheta0, deltaTheta1, uv.y);
|
||||
|
||||
vec3 deltaPhiVec = ellipsoidTangentPhiCameraSpace * deltaPhi;
|
||||
vec3 deltaThetaVec = ellipsoidTangentThetaCameraSpace * deltaTheta;
|
||||
vec3 deltaPhiVec = ellipsoidTangentPhiCameraSpace * deltaPhi;
|
||||
vec3 deltaThetaVec = ellipsoidTangentThetaCameraSpace * deltaTheta;
|
||||
|
||||
float height00 = getTileHeightScaled(uv, levelWeights);
|
||||
float height10 = getTileHeightScaled(uv + vec2(tileDelta, 0.0f), levelWeights);
|
||||
float height01 = getTileHeightScaled(uv + vec2(0.0f, tileDelta), levelWeights);
|
||||
float height00 = getTileHeightScaled(uv, levelWeights);
|
||||
float height10 = getTileHeightScaled(uv + vec2(tileDelta, 0.0), levelWeights);
|
||||
float height01 = getTileHeightScaled(uv + vec2(0.0, tileDelta), levelWeights);
|
||||
|
||||
vec3 diffTheta = deltaThetaVec + ellipsoidNormalCameraSpace * (height10 - height00);
|
||||
vec3 diffPhi = deltaPhiVec + ellipsoidNormalCameraSpace * (height01 - height00);
|
||||
vec3 diffTheta = deltaThetaVec + ellipsoidNormalCameraSpace * (height10 - height00);
|
||||
vec3 diffPhi = deltaPhiVec + ellipsoidNormalCameraSpace * (height01 - height00);
|
||||
|
||||
normal = normalize(cross(diffTheta, diffPhi));
|
||||
normal = normalize(cross(diffTheta, diffPhi));
|
||||
#endif // USE_ACCURATE_NORMALS
|
||||
return normal;
|
||||
return normal;
|
||||
}
|
||||
|
||||
#endif // TILE_HEIGHT_HGLSL
|
||||
+5
-5
@@ -31,14 +31,14 @@ uniform int xSegments;
|
||||
uniform float skirtLength;
|
||||
|
||||
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);
|
||||
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;
|
||||
return tileVertexIsSkirtVertex() ? skirtLength : 0.0;
|
||||
}
|
||||
|
||||
#endif // TILE_VERTEX_SKIRT_HGLSL
|
||||
@@ -732,8 +732,6 @@ void RenderableGlobe::render(const RenderData& data, RendererTasks& rendererTask
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
_shadowComponent.setViewDepthMap(false);
|
||||
|
||||
_shadowComponent.end();
|
||||
|
||||
// Render again from original point of view
|
||||
|
||||
@@ -55,13 +55,13 @@ namespace {
|
||||
constexpr const char* _loggerCat = "RingsComponent";
|
||||
|
||||
constexpr const std::array<const char*, 9> UniformNames = {
|
||||
"modelViewProjectionMatrix", "textureOffset", "colorFilterValue", "_nightFactor",
|
||||
"modelViewProjectionMatrix", "textureOffset", "colorFilterValue", "nightFactor",
|
||||
"sunPosition", "ringTexture", "shadowMatrix", "shadowMapTexture",
|
||||
"zFightingPercentage"
|
||||
};
|
||||
|
||||
constexpr const std::array<const char*, 15> UniformNamesAdvancedRings = {
|
||||
"modelViewProjectionMatrix", "textureOffset", "colorFilterValue", "_nightFactor",
|
||||
"modelViewProjectionMatrix", "textureOffset", "colorFilterValue", "nightFactor",
|
||||
"sunPosition", "sunPositionObj", "camPositionObj", "ringTextureFwrd",
|
||||
"ringTextureBckwrd", "ringTextureUnlit", "ringTextureColor",
|
||||
"ringTextureTransparency", "shadowMatrix", "shadowMapTexture", "zFightingPercentage"
|
||||
|
||||
@@ -356,33 +356,6 @@ void ShadowComponent::end() {
|
||||
if (_blendIsEnabled) {
|
||||
glEnable(GL_BLEND);
|
||||
}
|
||||
|
||||
if (_viewDepthMap) {
|
||||
if (!_renderDMProgram) {
|
||||
_renderDMProgram = global::renderEngine->buildRenderProgram(
|
||||
"ShadowMappingDebuggingProgram",
|
||||
absPath("${MODULE_GLOBEBROWSING}/shaders/smviewer_vs.glsl"),
|
||||
absPath("${MODULE_GLOBEBROWSING}/shaders/smviewer_fs.glsl")
|
||||
);
|
||||
}
|
||||
|
||||
if (!_quadVAO) {
|
||||
glGenVertexArrays(1, &_quadVAO);
|
||||
}
|
||||
|
||||
_renderDMProgram->activate();
|
||||
|
||||
ghoul::opengl::TextureUnit shadowMapUnit;
|
||||
shadowMapUnit.activate();
|
||||
glBindTexture(GL_TEXTURE_2D, _shadowDepthTexture);
|
||||
|
||||
_renderDMProgram->setUniform("shadowMapTexture", shadowMapUnit);
|
||||
|
||||
glBindVertexArray(_quadVAO);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
_renderDMProgram->deactivate();
|
||||
}
|
||||
}
|
||||
|
||||
void ShadowComponent::update(const UpdateData&) {
|
||||
@@ -619,10 +592,6 @@ ShadowComponent::ShadowMapData ShadowComponent::shadowMapData() const {
|
||||
return _shadowData;
|
||||
}
|
||||
|
||||
void ShadowComponent::setViewDepthMap(bool enable) {
|
||||
_viewDepthMap = enable;
|
||||
}
|
||||
|
||||
GLuint ShadowComponent::dDepthTexture() const {
|
||||
return _dDepthTexture;
|
||||
}
|
||||
|
||||
@@ -77,8 +77,6 @@ public:
|
||||
|
||||
ShadowComponent::ShadowMapData shadowMapData() const;
|
||||
|
||||
void setViewDepthMap(bool enable);
|
||||
|
||||
GLuint dDepthTexture() const;
|
||||
|
||||
private:
|
||||
@@ -137,9 +135,6 @@ private:
|
||||
|
||||
// DEBUG
|
||||
bool _executeDepthTextureSave = false;
|
||||
bool _viewDepthMap = false;
|
||||
std::unique_ptr<ghoul::opengl::ProgramObject> _renderDMProgram;
|
||||
GLuint _quadVAO = 0u;
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user