Recalculate chunk bounding boxes when the settings of a heightlayer change (closes #2096)

* Correctly calculate Offset when negative numbers are involved
* Adds tile index layer for the Moon
* Remove empty spaces
This commit is contained in:
Alexander Bock
2022-11-07 15:45:54 +01:00
committed by GitHub
parent 6d379a537e
commit 12bb47c71e
16 changed files with 76 additions and 31 deletions

View File

@@ -0,0 +1,29 @@
local globeIdentifier = asset.require("../../moon").Moon.Identifier
local layer = {
Identifier = "Tile_Indices",
Name = "Tile Indices",
Enabled = asset.enabled,
Type = "TileIndexTileLayer"
}
asset.onInitialize(function()
openspace.globebrowsing.addLayer(globeIdentifier, "Overlays", layer)
end)
asset.onDeinitialize(function()
openspace.globebrowsing.deleteLayer(globeIdentifier, "Overlays", layer)
end)
asset.export("layer", layer)
asset.meta = {
Name = "Moon Tile Indices",
Version = "1.0",
Description = "Tile index layer for Moon globe",
Author = "OpenSpace Team",
URL = "http://openspaceproject.com",
License = "MIT license"
}

View File

@@ -91,7 +91,7 @@ Fragment getFragment() {
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}));
@@ -116,7 +116,7 @@ Fragment getFragment() {
// 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 =
diffuse.xyz =
vec3(1.0, 0.97075, 0.952) * texture(ringTextureUnlit, texCoord).xyz * nightFactor;
}

View File

@@ -46,7 +46,7 @@ void main() {
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;

View File

@@ -38,7 +38,7 @@ Fragment getFragment() {
vec4 mixedTexture = mix(texel0, texel1, blendFactor);
Fragment frag;
Fragment frag;
if (mixedTexture.r > 0.999) {
frag.color = texture(colormapTexture, mixedTexture.r - 0.01);
}

View File

@@ -90,7 +90,7 @@ vec3 getLevelWeights(float distToVertexOnEllipsoid) {
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);
@@ -100,7 +100,7 @@ void main() {
// Get the height value and apply skirts
float height = getTileHeightScaled(in_uv, levelWeights) - getTileVertexSkirtLength() * 100.0;
// Translate the point along normal
p += patchNormalCameraSpace * height;

View File

@@ -126,7 +126,7 @@ vec4 calcShadow(const ShadowRenderingStruct shadowInfoArray[NSEclipseShadows],
}
else if (length_d < r_p_pi) {// penumbra
#if USE_ECLIPSE_HARD_SHADOWS
return vec4(0.5, 0.5, 0.5, 1.0);
return vec4(0.5, 0.5, 0.5, 1.0);
#else
return vec4(vec3(length_d / r_p_pi), 1.0);
#endif

View File

@@ -80,7 +80,7 @@ Fragment getFragment() {
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}));

View File

@@ -54,7 +54,7 @@ Fragment getFragment() {
}
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;
@@ -70,6 +70,6 @@ Fragment getFragment() {
Fragment frag;
frag.color = vec4(vec3(vs_screenSpaceDepth), 1.0);
frag.depth = (diffuse < 0.5) ? 1E30 : vs_screenSpaceDepth;
return frag;
}

View File

@@ -46,7 +46,7 @@ void main() {
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;

View File

@@ -73,38 +73,39 @@ float orenNayarDiffuse(vec3 lightDirection, vec3 viewDirection, vec3 surfaceNorm
{
// calculate intermediary values
float NdotL = dot(surfaceNormal, lightDirection);
float NdotV = dot(surfaceNormal, viewDirection);
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;
float v = sign(value) * pow(abs(value), 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);
vec4 performLayerSettings(vec4 value, LayerSettings settings) {
vec3 v = sign(value.rgb) * pow(abs(value.rgb), vec3(settings.gamma)) *
settings.multiplier + settings.offset;
return vec4(v, value.a * settings.opacity);
}
vec2 tileUVToTextureSamplePosition(ChunkTile chunkTile, vec2 tileUV, PixelPadding padding)
@@ -194,7 +195,7 @@ vec4 blend#{layerGroup}#{i}(vec4 currentColor, vec4 newColor, float 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);
@@ -248,7 +249,7 @@ float calculateUntransformedHeight(vec2 uv, vec3 levelWeights,
#if !HEIGHTMAP_BLENDING_ENABLED
levelWeights = DefaultLevelWeights;
#endif // HEIGHTMAP_BLENDING_ENABLED
#for i in 0..#{lastLayerIndexHeightLayers}
{
vec4 colorSample = getSampleHeightLayers#{i}(uv, levelWeights, HeightLayers);
@@ -354,7 +355,7 @@ vec4 calculateNight(vec4 currentColor, vec2 uv, vec3 levelWeights,
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);
@@ -420,7 +421,7 @@ vec4 calculateOverlay(vec4 currentColor, vec2 uv, vec3 levelWeights,
return color;
}
vec4 calculateWater(vec4 currentColor, vec2 uv, vec3 levelWeights,
vec4 calculateWater(vec4 currentColor, vec2 uv, vec3 levelWeights,
Layer WaterMasks[NUMLAYERS_WATERMASK],
vec3 ellipsoidNormalCameraSpace, vec3 lightDirectionCameraSpace,
vec3 positionCameraSpace, out float reflectance)

View File

@@ -70,7 +70,7 @@ struct Layer {
LayerSettings settings;
LayerAdjustment adjustment;
PixelPadding padding;
// Other layer type properties stuff
vec3 color;
};

View File

@@ -79,7 +79,7 @@ float getTileHeight(vec2 uv, vec3 levelWeights) {
float getTileHeightScaled(vec2 uv, vec3 levelWeights) {
float height = getTileHeight(uv, levelWeights);
#if USE_HEIGHTMAP
height *= heightScale;
#endif // USE_HEIGHTMAP

View File

@@ -296,6 +296,14 @@ Layer::Layer(layers::Group::ID id, const ghoul::Dictionary& layerDict, LayerGrou
}
});
_renderSettings.onChange([&]() {
// Only if we are a height layer will anyone care about these settings changing as
// that will change the overall bounding box of the layer and thus require culling
if (_parent.isHeightLayer() && _onChangeCallback) {
_onChangeCallback(this);
}
});
_typeOption.onChange([&]() {
switch (type()) {
// Intentional fall through. Same for all tile layers

View File

@@ -85,6 +85,14 @@ LayerRenderSettings::LayerRenderSettings()
});
}
void LayerRenderSettings::onChange(std::function<void()> callback) {
opacity.onChange(callback);
gamma.onChange(callback);
multiplier.onChange(callback);
multiplier.onChange(callback);
offset.onChange(callback);
}
float LayerRenderSettings::performLayerSettings(float v) const {
return
((glm::sign(v) * glm::pow(glm::abs(v), gamma) * multiplier) + offset) * opacity;

View File

@@ -41,6 +41,8 @@ struct LayerRenderSettings : public properties::PropertyOwner {
properties::FloatProperty offset;
properties::TriggerProperty setDefault;
void onChange(std::function<void()> callback);
/// This function matches the function with the same name in the
/// shader code
float performLayerSettings(float value) const;

View File

@@ -1858,9 +1858,6 @@ float RenderableGlobe::getHeight(const glm::dvec3& position) const {
const int chunkLevel = node.tileIndex.level;
//TileIndex::TileIndex(const Geodetic2& point, int level_)
// : level(level_)
//{
const int numIndicesAtLevel = 1 << chunkLevel;
const double u = 0.5 + geodeticPosition.lon / glm::two_pi<double>();
const double v = 0.25 - geodeticPosition.lat / glm::two_pi<double>();