Browse Source

toggleable normal mapping

Kajetan Johannes Hammerle 3 years ago
parent
commit
2fb2e7edce

+ 11 - 5
client/Game.cpp

@@ -116,6 +116,12 @@ void Game::tick() {
     if(control.keys.test5.getDownTime() == 1) {
         renderSettings.ssao = !renderSettings.ssao;
     }
+    if(control.keys.test6.getDownTime() == 1) {
+        renderSettings.bump += 0.05f;
+        if(renderSettings.bump > 1.0f) {
+            renderSettings.bump = 0.0f;
+        }
+    }
 }
 
 void Game::renderWorld(float lag, Renderer& renderer) const {
@@ -174,9 +180,9 @@ Vector3 Game::splineTangent(const Vector3& prev, const Vector3& current, const V
 Vector3 Game::interpolate(const Vector3& a, const Vector3& b, const Vector3& tanA, const Vector3& tanB, float t) const {
     float t2 = t * t;
     float t3 = t2 * t;
-    return a * (2.0f * t3 - 3.0f * t2 + 1.0f) + 
-            b * (-2.0f * t3 + 3.0f * t2) + 
-            tanA * (t3 - 2.0f * t2 + t) + 
+    return a * (2.0f * t3 - 3.0f * t2 + 1.0f) +
+            b * (-2.0f * t3 + 3.0f * t2) +
+            tanA * (t3 - 2.0f * t2 + t) +
             tanB * (t3 - t2);
 }
 
@@ -195,7 +201,7 @@ float Game::distance(uint index, uint splits) const {
         currentPos = currentNext;
         float t = (i + 1.0f) / (splits + 1.0f);
         currentNext = interpolate(a, b, tanA, tanB, t);
-        float l = static_cast<Vector3>(currentPos - currentNext).length();
+        float l = static_cast<Vector3> (currentPos - currentNext).length();
         sum += l;
     }
     return sum;
@@ -217,7 +223,7 @@ Vector3 Game::pointUntilDistance(float leftDistance, uint index, uint splits) co
         currentPos = currentNext;
         float t = (i + 1.0f) / (splits + 1.0f);
         currentNext = interpolate(a, b, tanA, tanB, t);
-        float l = static_cast<Vector3>(currentPos - currentNext).length();
+        float l = static_cast<Vector3> (currentPos - currentNext).length();
         sum += l;
         i++;
     }

+ 2 - 1
client/input/Keys.cpp

@@ -25,7 +25,7 @@ std::ostream& operator<<(std::ostream& os, const Keys::Key& k) {
 
 Keys::Keys() : left(keys[0]), right(keys[1]), up(keys[2]), down(keys[3]), jump(keys[4]), sneak(keys[5]),
 camLeft(keys[6]), camRight(keys[7]), camUp(keys[8]), camDown(keys[9]), test(keys[10]), test2(keys[11]), test3(keys[12]),
-test4(keys[13]), test5(keys[14]) {
+test4(keys[13]), test5(keys[14]), test6(keys[15]) {
     keys[0].glfwKey = GLFW_KEY_A;
     keys[1].glfwKey = GLFW_KEY_D;
     keys[2].glfwKey = GLFW_KEY_W;
@@ -41,6 +41,7 @@ test4(keys[13]), test5(keys[14]) {
     keys[12].glfwKey = GLFW_KEY_Y;
     keys[13].glfwKey = GLFW_KEY_G;
     keys[14].glfwKey = GLFW_KEY_H;
+    keys[15].glfwKey = GLFW_KEY_U;
 }
 
 void Keys::release(int key) {

+ 2 - 1
client/input/Keys.h

@@ -31,7 +31,7 @@ public:
     };
 
 private:
-    Key keys[15];
+    Key keys[16];
 
 public:
     Keys();
@@ -50,6 +50,7 @@ public:
     const Key& test3;
     const Key& test4;
     const Key& test5;
+    const Key& test6;
 
     void release(int key);
     void press(int key);

+ 1 - 0
client/rendering/Engine.cpp

@@ -101,6 +101,7 @@ void Engine::renderPostWorld() {
     framebuffers.world.bindNormalTexture(3);
     shaders.postWorld.setInt("ssao", renderSettings.ssao);
     shaders.postWorld.setInt("shadows", renderSettings.shadows);
+    shaders.postWorld.setFloat("bump", renderSettings.bump);
     rectangle.draw();
 }
 

+ 1 - 1
client/rendering/RenderSettings.cpp

@@ -1,4 +1,4 @@
 #include "client/rendering/RenderSettings.h"
 
-RenderSettings::RenderSettings() : ssao(true), shadows(false), testRadius(0.004f), testBias(0.003f) {
+RenderSettings::RenderSettings() : ssao(true), shadows(false), testRadius(0.004f), testBias(0.003f), bump(0.5f) {
 }

+ 1 - 0
client/rendering/RenderSettings.h

@@ -10,6 +10,7 @@ struct RenderSettings final {
     bool shadows;
     float testRadius;
     float testBias;
+    float bump;
 };
 
 #endif

BIN
resources/normal.png


+ 1 - 1
resources/shader/worldFragment.fs

@@ -53,7 +53,7 @@ void main(void) {
 
     if(shadows) {
         vec3 pos = varShadow.xyz / varShadow.w;
-        float fbias = zbias * (1.0 - max(dot(worldNormal, -light), 0.0)); 
+        float fbias = zbias * (1.0 - max(dot(normal, -light), 0.0)); 
         float shadow = 0.0;
         for(int i = 0; i < sampleAmount; i++) {
             shadow += float(texture(shadowSamp, pos.xy + samples[i] * radius).r + fbias > pos.z);

+ 3 - 3
resources/shader/worldPostFragment.fs

@@ -7,6 +7,7 @@ layout (binding = 3) uniform sampler2D worldNormalSamp;
 
 uniform bool ssao;
 uniform bool shadows;
+uniform float bump;
 
 in vec2 varTex;
 
@@ -21,10 +22,9 @@ void main() {
         color = vec4(texture(colorSamp, varTex).xyz, 1.0);
     }
     if(shadows) {
-        float diffuseLight = float(dot(texture(worldNormalSamp, varTex).xyz, -light) > 0);
-        float f = diffuseLight * texture(shadowSamp, varTex).r;
+        float f = texture(shadowSamp, varTex).r;
         color *= f * 0.5 + 0.5;
     }
-    float diffuseLight = max(dot(texture(worldNormalSamp, varTex).xyz, -light), 0.0) * 0.5 + 0.5;
+    float diffuseLight = max(dot(texture(worldNormalSamp, varTex).xyz, -light), 0.0) * bump + (1.0 - bump);
     color *= diffuseLight;
 }