From d569b8235ed7ca98ef80238f13b93c423faafe80 Mon Sep 17 00:00:00 2001 From: Emil Axelsson Date: Tue, 16 Jan 2018 17:05:46 +0100 Subject: [PATCH] Fix height mapping bugs in renderable planet --- modules/space/rendering/renderableplanet.cpp | 6 +----- modules/space/shaders/renderableplanet_vs.glsl | 10 ++++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/space/rendering/renderableplanet.cpp b/modules/space/rendering/renderableplanet.cpp index 82d25b074d..8f4855569a 100644 --- a/modules/space/rendering/renderableplanet.cpp +++ b/modules/space/rendering/renderableplanet.cpp @@ -236,6 +236,7 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary) if (dictionary.hasKey(PerformShadingInfo.identifier)) { _performShading = dictionary.value(PerformShadingInfo.identifier); } + addProperty(_performShading); addPropertySubOwner(_geometry.get()); @@ -256,11 +257,6 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary) } addProperty(_heightExaggeration); - if (dictionary.hasKey(HeightExaggerationInfo.identifier)) { - _performShading = dictionary.value(HeightExaggerationInfo.identifier); - } - addProperty(_performShading); - //================================================================ //======== Reads Shadow (Eclipses) Entries in mod file =========== //================================================================ diff --git a/modules/space/shaders/renderableplanet_vs.glsl b/modules/space/shaders/renderableplanet_vs.glsl index 2b0d4c31e1..b10e225e22 100644 --- a/modules/space/shaders/renderableplanet_vs.glsl +++ b/modules/space/shaders/renderableplanet_vs.glsl @@ -40,6 +40,9 @@ uniform mat4 ModelTransform; uniform dmat4 modelViewTransform; uniform mat4 modelViewProjectionTransform; +uniform sampler2D heightTex; +uniform bool _hasHeightMap; +uniform float _heightExaggeration; void main() { vs_st = in_st; @@ -53,6 +56,13 @@ void main() { vec4 position = vec4(in_position.xyz * pow(10, in_position.w), 1.0); + if (_hasHeightMap) { + float height = texture(heightTex, in_st).r; + vec3 displacementDirection = abs(normalize(in_normal.xyz)); + float displacementFactor = height * _heightExaggeration; + position.xyz = position.xyz + displacementDirection * displacementFactor; + } + // G-Buffer vs_gPosition = vec4(modelViewTransform * position); // Must be in SGCT eye space;