Browse Source

bool for ssao, reintegration of text layer

Kajetan Johannes Hammerle 4 years ago
parent
commit
0d2076f913

+ 33 - 29
client/GameClient.cpp

@@ -50,6 +50,7 @@ static float farClip = 1000.0f;
 static InternGameClient client;
 static Keys keys;
 static MouseButtons mButtons;
+static bool useSSAO = false;
 
 struct Shaders
 {
@@ -124,27 +125,27 @@ struct Shaders
 
 struct Framebuffers
 {
-    Framebuffers(u32 w, u32 h) : worldBuffer(w, h, Framebuffer::POSITION | 
+    Framebuffers(u32 w, u32 h) : world(w, h, Framebuffer::POSITION | 
         Framebuffer::NORMAL | Framebuffer::COLOR | Framebuffer::DEPTH24_STENCIL8),
-        ssaoBuffer(w, h, Framebuffer::RED), ssaoBlurBuffer(w, h, Framebuffer::RED)
+        ssao(w, h, Framebuffer::RED), ssaoBlur(w, h, Framebuffer::RED)
     {
     }
     
     void resize(u32 w, u32 h) const
     {
-        worldBuffer.resize(w, h);
-        ssaoBuffer.resize(w, h);
-        ssaoBlurBuffer.resize(w, h);
+        world.resize(w, h);
+        ssao.resize(w, h);
+        ssaoBlur.resize(w, h);
     }
     
     bool isValid() const
     {
-        return worldBuffer.isValid() && ssaoBuffer.isValid() && ssaoBlurBuffer.isValid();
+        return world.isValid() && ssao.isValid() && ssaoBlur.isValid();
     }
     
-    Framebuffer worldBuffer;
-    Framebuffer ssaoBuffer;
-    Framebuffer ssaoBlurBuffer;
+    Framebuffer world;
+    Framebuffer ssao;
+    Framebuffer ssaoBlur;
 };
 
 struct InternGame
@@ -267,12 +268,16 @@ static void tick(InternGame& game)
     keys.tick();
     mButtons.tick();
     game.game.tick(keys, mButtons, game.cam);
+    if(keys.test.getDownTime() == 1)
+    {
+        useSSAO = !useSSAO;
+    }
     mButtons.postTick();
 }
 
 static void renderWorld(float lag, Shaders& shaders, InternGame& game, Framebuffers& fb)
 {
-    fb.worldBuffer.bind();
+    fb.world.bind();
     glEnable(GL_DEPTH_TEST);
     shaders.world.use();
     shaders.world.setMatrix("proj", shaders.worldProj);
@@ -290,18 +295,18 @@ static void renderSSAO(Shaders& shaders, InternGame& game, Framebuffers& fb)
     shaders.ssao.setMatrix("proj", shaders.worldProj);
     shaders.ssao.setInt("width", width);
     shaders.ssao.setInt("height", height);
-    fb.worldBuffer.bindPositionTexture(0);
-    fb.worldBuffer.bindNormalTexture(1);
-    fb.worldBuffer.bindColorTexture(2);
-    fb.worldBuffer.bindDepthTexture(3);
+    fb.world.bindPositionTexture(0);
+    fb.world.bindNormalTexture(1);
+    fb.world.bindColorTexture(2);
+    fb.world.bindDepthTexture(3);
     game.ssaoNoise.bind(4);
-    fb.ssaoBuffer.bind();
+    fb.ssao.bind();
     game.rectangle.draw();
     // ssao blur
     shaders.ssaoBlur.use();
-    fb.ssaoBuffer.bindRedTexture(0);
-    fb.worldBuffer.bindColorTexture(1);
-    fb.ssaoBlurBuffer.bind();
+    fb.ssao.bindRedTexture(0);
+    fb.world.bindColorTexture(1);
+    fb.ssaoBlur.bind();
     game.rectangle.draw();
 }
 
@@ -309,19 +314,14 @@ static void renderPostWorld(Shaders& shaders, InternGame& game, Framebuffers& fb
 {
     glBindFramebuffer(GL_FRAMEBUFFER, 0);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
-    fb.worldBuffer.bindColorTexture(0);
-    fb.ssaoBlurBuffer.bindRedTexture(1);
     shaders.postWorld.use();
-    //glDisable(GL_CULL_FACE);
-    glDisable(GL_DEPTH_TEST);
-    glEnable(GL_BLEND);
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-    glBlendEquation(GL_FUNC_ADD);
+    fb.world.bindColorTexture(0);
+    fb.ssaoBlur.bindRedTexture(1);
+    shaders.postWorld.setInt("useSSAO", useSSAO);
     game.rectangle.draw();
-    glDisable(GL_BLEND);
 }
 
-/*static void renderTextOverlay(float lag, Shaders& shaders, InternGame& game)
+static void renderTextOverlay(float lag, Shaders& shaders, InternGame& game)
 {
     glDisable(GL_DEPTH_TEST);
     shaders.text.use();
@@ -340,7 +340,7 @@ static void renderPostWorld(Shaders& shaders, InternGame& game, Framebuffers& fb
     glBlendEquation(GL_FUNC_ADD);
     game.game.renderTextOverlay(lag, game.model, shaders.text, game.fontRenderer);
     glDisable(GL_BLEND);
-}*/
+}
 
 static void renderTick(float lag, Shaders& shaders, InternGame& game, Framebuffers& fb)
 {
@@ -353,8 +353,12 @@ static void renderTick(float lag, Shaders& shaders, InternGame& game, Framebuffe
     shaders.updateWorldView(lag, game.cam);
     
     renderWorld(lag, shaders, game, fb);
-    renderSSAO(shaders, game, fb);
+    if(useSSAO)
+    {
+        renderSSAO(shaders, game, fb);
+    }
     renderPostWorld(shaders, game, fb);
+    renderTextOverlay(lag, shaders, game);
 }
 
 static void loop()

+ 3 - 1
client/input/Keys.cpp

@@ -26,7 +26,8 @@ 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])
+        camLeft(keys[6]), camRight(keys[7]), camUp(keys[8]), camDown(keys[9]), 
+        test(keys[10])
 {
     keys[0].glfwKey = GLFW_KEY_A;
     keys[1].glfwKey = GLFW_KEY_D;
@@ -38,6 +39,7 @@ Keys::Keys() : left(keys[0]), right(keys[1]), up(keys[2]), down(keys[3]),
     keys[7].glfwKey = GLFW_KEY_RIGHT;
     keys[8].glfwKey = GLFW_KEY_UP;
     keys[9].glfwKey = GLFW_KEY_DOWN;
+    keys[10].glfwKey = GLFW_KEY_T;
 }
 
 void Keys::release(int key)

+ 2 - 1
client/input/Keys.h

@@ -32,7 +32,7 @@ public:
     };
     
 private:
-   Key keys[10];
+   Key keys[11];
     
 public:
     Keys();
@@ -46,6 +46,7 @@ public:
     const Key& camRight;
     const Key& camUp;
     const Key& camDown;
+    const Key& test;
     
     void release(int key);
     void press(int key);

+ 3 - 3
client/rendering/FontRenderer.cpp

@@ -10,13 +10,13 @@ FontRenderer::FontRenderer() : tex("resources/font8x8.png"), offset(BUFFER_LENGT
     glGenBuffers(1, &vbo);
     glBindBuffer(GL_ARRAY_BUFFER, vbo);
     
-    glVertexAttribPointer(0, 2, GL_FLOAT, false, sizeof(float) * 7, (GLvoid*) (sizeof(float) * 0));
+    glVertexAttribPointer(0, 2, GL_FLOAT, false, sizeof(float) * 7, static_cast<float*>(0));
     glEnableVertexAttribArray(0);
 
-    glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(float) * 7, (GLvoid*) (sizeof(float) * 2));
+    glVertexAttribPointer(1, 2, GL_FLOAT, false, sizeof(float) * 7, static_cast<float*>(0) + 2);
     glEnableVertexAttribArray(1);  
     
-    glVertexAttribPointer(2, 3, GL_FLOAT, false, sizeof(float) * 7, (GLvoid*) (sizeof(float) * 4));
+    glVertexAttribPointer(2, 3, GL_FLOAT, false, sizeof(float) * 7, static_cast<float*>(0) + 4);
     glEnableVertexAttribArray(2);
 }
 

+ 10 - 1
resources/shader/worldPostFragment.fs

@@ -3,11 +3,20 @@
 layout (binding = 0) uniform sampler2D colorSamp;
 layout (binding = 1) uniform sampler2D ssaoSamp;
 
+uniform bool useSSAO;
+
 in vec2 varTex;
 
 out vec4 color;
 
 void main()
 {
-    color = vec4(texture(colorSamp, varTex).xyz * (texture(ssaoSamp, varTex).r + 0.5), 1.0);
+    if(useSSAO)
+    {
+        color = vec4(texture(colorSamp, varTex).xyz * (texture(ssaoSamp, varTex).r + 0.5), 1.0);
+    }
+    else
+    {
+        color = vec4(texture(colorSamp, varTex).xyz, 1.0);
+    }
 }