Some fixes on heightmap displacement for RenderablePlanet

Some fixes on heightmap displacement for RenderablePlanetProjection
Enable optional normal map on RenderablePlanetProjection
This commit is contained in:
Alexander Bock
2016-05-18 19:03:03 +02:00
parent caeb8618a8
commit 0ab3f0c026
8 changed files with 139 additions and 21 deletions
+1 -1
View File
@@ -60,7 +60,7 @@ RenderablePlanet::RenderablePlanet(const ghoul::Dictionary& dictionary)
, _colorTexturePath("colorTexture", "Color Texture")
, _nightTexturePath("nightTexture", "Night Texture")
, _heightMapTexturePath("heightMap", "Heightmap Texture")
, _heightExaggeration("heightExaggeration", "Height Exaggeration", 1.f, 0.f, 100.f)
, _heightExaggeration("heightExaggeration", "Height Exaggeration", 1.f, 0.f, 10.f)
, _programObject(nullptr)
, _texture(nullptr)
, _nightTexture(nullptr)
+2 -2
View File
@@ -34,12 +34,12 @@ uniform int shadows;
uniform float time;
uniform sampler2D texture1;
uniform sampler2D nightTex;
uniform sampler2D heightTex;
in vec2 vs_st;
in vec2 vs_nightTex;
in vec4 vs_normal;
in vec4 vs_position;
in vec4 test;
#include "PowerScaling/powerScaling_fs.hglsl"
#include "fragment.glsl"
@@ -69,7 +69,7 @@ Fragment getFragment() {
vec4 ambient = vec4(0.0,0.0,0.0,transparency);
vec4 daytex = max(intensity * diffuse, ambient);
vec4 mixtex = mix(diffuse, diffuse2, (1+dot(n,-l_dir))/2);
vec4 mixtex = mix(diffuse, diffuse2, (1+dot(n,-l_dir))/2);
diffuse = (daytex*2 + mixtex)/3;
}
+6 -7
View File
@@ -35,7 +35,6 @@ layout(location = 2) in vec3 in_normal;
out vec2 vs_st;
out vec4 vs_normal;
out vec4 vs_position;
out float s;
uniform mat4 ViewProjection;
uniform mat4 ModelTransform;
@@ -54,19 +53,19 @@ void main()
// this is wrong for the normal. The normal transform is the transposed inverse of the model transform
vs_normal = normalize(ModelTransform * vec4(in_normal,0));
// vs_normal = vec4(in_normal, 0.0);
vec4 position = pscTransform(tmp, ModelTransform);
vs_position = tmp;
position = ViewProjection * position;
if (_hasHeightMap) {
// Get the height of the height value
float height = texture(heightTex, in_st).r;
// Displace the position along the position vector (being the normal) by that height * the
// exaggeration factor
position.xyz = position.xyz + height * normalize(position.xyz) * _heightExaggeration;
vec3 displacementDirection = abs(normalize(in_normal.xyz));
float displacementFactor = height * _heightExaggeration;
position.xyz = position.xyz + displacementDirection * displacementFactor;
}
//
position = ViewProjection * position;
gl_Position = z_normalization(position);
}