aboutsummaryrefslogtreecommitdiff
path: root/apps/openmb/renderer/SSAORenderer.hpp
blob: 3075252c4c0dd5c234bf7e7a444aaa51ce97ae33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#pragma once

#include "Shader.hpp"
#include <glm/glm.hpp>
#include <vector>

#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#ifdef __APPLE__
#include <OpenGL/gl3.h>
#endif

namespace renderer {
class SSAORenderer {
  public:
    SSAORenderer();
    ~SSAORenderer();

    bool init( int width, int height, bool halfRes = true );
    void resize( int width, int height );

    void bindGBuffer();
    void unbind();

    void computeSSAO( const glm::mat4& proj, const glm::mat4& invProj, float radius, float bias, float power );
    void blurSSAO();

    unsigned int getSSAOTextureID() const;
    void         bindSSAOTextureToUnit( int unit, renderer::Shader& shader, const std::string& uniformName = "ssao" ) const;

    renderer::Shader& getGBufferShader () { return mGBufferShader; }

  private:
    void initBuffers();
    void initKernelAndNoise();

    int  mWidth;
    int  mHeight;
    bool mHalfRes;

    GLuint mGBufferFBO;
    GLuint mGNormal;
    GLuint mGDepth;

    GLuint mSSAOFBO;
    GLuint mSSAOTexture;

    GLuint mSSAOBlurFBO;
    GLuint mSSAOBlurTexture;

    GLuint mNoiseTexture;

    GLuint mQuadVAO;
    GLuint mQuadVBO;

    std::vector<glm::vec3> mKernel;
    int                    mKernelSize;

    renderer::Shader mGBufferShader;
    renderer::Shader mSSAOShader;
    renderer::Shader mBlurShader;
};

}   // namespace renderer