mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-08 04:20:14 -05:00
Update rendering of shadow texture and water mask in RenderableGlobe.
This commit is contained in:
@@ -381,11 +381,17 @@ namespace openspace {
|
||||
programObject->setUniform("lonLatScalingFactor", vec2(patchSize.toLonLatVec2()));
|
||||
programObject->setUniform("radiiSquared", vec3(ellipsoid.radiiSquared()));
|
||||
|
||||
if (_tileProviderManager->getTileProviderGroup(LayeredTextures::NightTextures).getActiveTileProviders().size() > 0) {
|
||||
if (_tileProviderManager->getTileProviderGroup(
|
||||
LayeredTextures::NightTextures).getActiveTileProviders().size() > 0) {
|
||||
glm::vec3 directionToSunWorldSpace =
|
||||
glm::normalize(-data.modelTransform.translation);
|
||||
glm::vec3 directionToSunCameraSpace =
|
||||
(viewTransform * glm::dvec4(directionToSunWorldSpace, 0)).xyz();
|
||||
data.modelTransform.translation;
|
||||
programObject->setUniform("modelViewTransform", modelViewTransform);
|
||||
programObject->setUniform("lightDirectionCameraSpace", -directionToSunCameraSpace);
|
||||
}
|
||||
|
||||
|
||||
// OpenGL rendering settings
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
@@ -430,8 +436,6 @@ namespace openspace {
|
||||
}
|
||||
|
||||
// Calculate other uniform variables needed for rendering
|
||||
|
||||
// TODO : Model transform should be fetched as a matrix directly.
|
||||
dmat4 modelTransform = chunk.owner()->modelTransform();
|
||||
dmat4 viewTransform = data.camera.combinedViewMatrix();
|
||||
dmat4 modelViewTransform = viewTransform * modelTransform;
|
||||
@@ -454,6 +458,16 @@ namespace openspace {
|
||||
programObject->setUniform("patchNormalCameraSpace", patchNormalCameraSpace);
|
||||
programObject->setUniform("projectionTransform", data.camera.projectionMatrix());
|
||||
|
||||
if (_tileProviderManager->getTileProviderGroup(
|
||||
LayeredTextures::NightTextures).getActiveTileProviders().size() > 0) {
|
||||
glm::vec3 directionToSunWorldSpace =
|
||||
glm::normalize(-data.modelTransform.translation);
|
||||
glm::vec3 directionToSunCameraSpace =
|
||||
(viewTransform * glm::dvec4(directionToSunWorldSpace, 0)).xyz();
|
||||
data.modelTransform.translation;
|
||||
programObject->setUniform("lightDirectionCameraSpace", -directionToSunCameraSpace);
|
||||
}
|
||||
|
||||
|
||||
// OpenGL rendering settings
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
@@ -44,6 +44,7 @@ out vec2 fs_uv;
|
||||
out vec4 fs_position;
|
||||
out vec3 ellipsoidNormalCameraSpace;
|
||||
out LevelWeights levelWeights;
|
||||
out vec3 positionCameraSpace;
|
||||
|
||||
PositionNormalPair globalInterpolation() {
|
||||
vec2 lonLatInput;
|
||||
@@ -77,4 +78,5 @@ void main() {
|
||||
fs_position = z_normalization(positionClippingSpace);
|
||||
gl_Position = fs_position;
|
||||
ellipsoidNormalCameraSpace = mat3(modelViewTransform) * pair.normal;
|
||||
positionCameraSpace = vec3(modelViewTransform * vec4(pair.position, 1));
|
||||
}
|
||||
@@ -46,7 +46,7 @@ out vec2 fs_uv;
|
||||
out vec4 fs_position;
|
||||
out vec3 ellipsoidNormalCameraSpace;
|
||||
out LevelWeights levelWeights;
|
||||
|
||||
out vec3 positionCameraSpace;
|
||||
|
||||
vec3 bilinearInterpolation(vec2 uv) {
|
||||
vec3 p0 = (1 - uv.x) * p00 + uv.x * p10;
|
||||
@@ -84,4 +84,5 @@ void main() {
|
||||
fs_position = z_normalization(positionClippingSpace);
|
||||
gl_Position = fs_position;
|
||||
ellipsoidNormalCameraSpace = patchNormalCameraSpace;
|
||||
positionCameraSpace = p;
|
||||
}
|
||||
@@ -259,10 +259,8 @@ vec4 calculateNight(
|
||||
const Tile nightTiles[NUMLAYERS_NIGHTTEXTURE],
|
||||
const Tile nightTilesParent1[NUMLAYERS_NIGHTTEXTURE],
|
||||
const Tile nightTilesParent2[NUMLAYERS_NIGHTTEXTURE],
|
||||
const vec3 ellipsoidNormalCameraSpace) {
|
||||
|
||||
vec3 lightDirection = normalize(vec3(-1,-1,-1));
|
||||
float cosineFactor = clamp(dot(-lightDirection, ellipsoidNormalCameraSpace), 0, 1);
|
||||
const vec3 ellipsoidNormalCameraSpace,
|
||||
const vec3 lightDirectionCameraSpace) {
|
||||
|
||||
vec4 nightColor = vec4(0,0,0,0);
|
||||
|
||||
@@ -283,8 +281,10 @@ vec4 calculateNight(
|
||||
}
|
||||
#endfor
|
||||
|
||||
float cosineFactor = clamp(dot(-lightDirectionCameraSpace, ellipsoidNormalCameraSpace) * 3, 0, 1);
|
||||
|
||||
// Blend night color with base color
|
||||
vec4 color = vec4(cosineFactor * vec3(currentColor) + (1 - cosineFactor) * vec3(nightColor), currentColor.a);
|
||||
vec4 color = vec4(cosineFactor * currentColor.xyz + (1 - cosineFactor) * vec3(nightColor * nightColor * 0.7), currentColor.a);
|
||||
|
||||
return color;
|
||||
}
|
||||
@@ -371,7 +371,10 @@ vec4 calculateWater(
|
||||
LevelWeights levelWeights,
|
||||
const Tile waterTiles[NUMLAYERS_WATERMASK],
|
||||
const Tile waterTilesParent1[NUMLAYERS_WATERMASK],
|
||||
const Tile waterTilesParent2[NUMLAYERS_WATERMASK]) {
|
||||
const Tile waterTilesParent2[NUMLAYERS_WATERMASK],
|
||||
const vec3 ellipsoidNormalCameraSpace,
|
||||
const vec3 lightDirectionCameraSpace,
|
||||
const vec3 positionCameraSpace) {
|
||||
|
||||
vec4 waterColor = vec4(0,0,0,0);
|
||||
|
||||
@@ -392,7 +395,18 @@ vec4 calculateWater(
|
||||
}
|
||||
#endfor
|
||||
|
||||
return blendOver(currentColor, waterColor);
|
||||
vec3 directionToFragmentCameraSpace = normalize(positionCameraSpace - vec3(0, 0, 0));
|
||||
vec3 reflectionDirectionCameraSpace = reflect(lightDirectionCameraSpace, ellipsoidNormalCameraSpace);
|
||||
float cosineFactor = clamp(dot(-reflectionDirectionCameraSpace, directionToFragmentCameraSpace), 0, 1);
|
||||
cosineFactor = pow(cosineFactor, 30);
|
||||
|
||||
vec3 specularColor = vec3(1, 1, 1);
|
||||
float specularIntensity = 0.4;
|
||||
|
||||
vec3 specularTotal = specularColor * cosineFactor * specularIntensity * waterColor.a;
|
||||
|
||||
//return blendOver(currentColor, waterColor);
|
||||
return currentColor + vec4(specularTotal, 1);
|
||||
}
|
||||
|
||||
#endif // TEXTURETILEMAPPING_HGLSL
|
||||
@@ -43,6 +43,7 @@ uniform Tile ColorTexturesParent2[NUMLAYERS_COLORTEXTURE];
|
||||
uniform Tile NightTextures[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform Tile NightTexturesParent1[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform Tile NightTexturesParent2[NUMLAYERS_NIGHTTEXTURE];
|
||||
uniform vec3 lightDirectionCameraSpace;
|
||||
#endif // USE_NIGHTTEXTURE
|
||||
|
||||
#if USE_OVERLAY
|
||||
@@ -75,6 +76,8 @@ uniform vec2 vertexResolution;
|
||||
in vec4 fs_position;
|
||||
in vec2 fs_uv;
|
||||
in vec3 ellipsoidNormalCameraSpace;
|
||||
in vec3 positionCameraSpace;
|
||||
|
||||
|
||||
// levelInterpolationParameter is used to interpolate between a tile and its parent tiles
|
||||
// The value increases with the distance from the vertex (or fragment) to the camera
|
||||
@@ -170,7 +173,10 @@ vec4 getTileFragColor(){
|
||||
levelWeights,
|
||||
WaterMasks,
|
||||
WaterMasksParent1,
|
||||
WaterMasksParent2);
|
||||
WaterMasksParent2,
|
||||
ellipsoidNormalCameraSpace,
|
||||
lightDirectionCameraSpace,
|
||||
positionCameraSpace);
|
||||
|
||||
#endif // USE_WATERMASK
|
||||
|
||||
@@ -184,7 +190,8 @@ vec4 getTileFragColor(){
|
||||
NightTextures,
|
||||
NightTexturesParent1,
|
||||
NightTexturesParent2,
|
||||
ellipsoidNormalCameraSpace);
|
||||
ellipsoidNormalCameraSpace,
|
||||
lightDirectionCameraSpace);
|
||||
|
||||
#endif // USE_NIGHTTEXTURE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user