diff --git a/src/graphics/post_processing.cpp b/src/graphics/post_processing.cpp index 24e3968fd..401f22c96 100644 --- a/src/graphics/post_processing.cpp +++ b/src/graphics/post_processing.cpp @@ -645,11 +645,10 @@ static void renderGodRay(GLuint tex, const core::vector2df &sunpos) static void toneMap(FrameBuffer &fbo, GLuint rtt) { fbo.Bind(); - glUseProgram(FullScreenShader::ToneMapShader::Program); - glBindVertexArray(FullScreenShader::ToneMapShader::vao); - setTexture(0, rtt, GL_NEAREST, GL_NEAREST); - setTexture(1, irr_driver->getRenderTargetTexture(RTT_LOG_LUMINANCE), GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST); - FullScreenShader::ToneMapShader::setUniforms(irr_driver->getExposure(), irr_driver->getLwhite(), 0, 1); + glUseProgram(FullScreenShader::ToneMapShader::getInstance()->Program); + glBindVertexArray(FullScreenShader::ToneMapShader::getInstance()->vao); + setTexture(FullScreenShader::ToneMapShader::getInstance()->TU_tex, rtt, GL_NEAREST, GL_NEAREST); + FullScreenShader::ToneMapShader::getInstance()->setUniforms(); glDrawArrays(GL_TRIANGLES, 0, 3); } diff --git a/src/graphics/shaders.cpp b/src/graphics/shaders.cpp index 25759ff0a..243c55ce3 100644 --- a/src/graphics/shaders.cpp +++ b/src/graphics/shaders.cpp @@ -400,7 +400,6 @@ void Shaders::loadShaders() FullScreenShader::MotionBlurShader::init(); FullScreenShader::GodFadeShader::init(); FullScreenShader::GodRayShader::init(); - FullScreenShader::ToneMapShader::init(); FullScreenShader::MLAAColorEdgeDetectionSHader::init(); FullScreenShader::MLAABlendWeightSHader::init(); FullScreenShader::MLAAGatherSHader::init(); @@ -1588,35 +1587,19 @@ namespace FullScreenShader glUniform1i(uniform_tex_512, TU_tex_512); } - GLuint ToneMapShader::Program; - GLuint ToneMapShader::uniform_tex; - GLuint ToneMapShader::uniform_logluminancetex; - GLuint ToneMapShader::uniform_exposure; - GLuint ToneMapShader::uniform_lwhite; - GLuint ToneMapShader::vao; - - void ToneMapShader::init() + ToneMapShader::ToneMapShader() { Program = LoadProgram( GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getRGBfromCIEXxy.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/utils/getCIEXYZ.frag").c_str(), GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/tonemap.frag").c_str()); - uniform_tex = glGetUniformLocation(Program, "tex"); - uniform_logluminancetex = glGetUniformLocation(Program, "logluminancetex"); - uniform_exposure = glGetUniformLocation(Program, "exposure"); - uniform_lwhite = glGetUniformLocation(Program, "Lwhite"); + AssignUniforms(); + TU_tex = 0; + AssignTextureUnit(Program, TexUnit(TU_tex, "text")); vao = createFullScreenVAO(Program); } - void ToneMapShader::setUniforms(float exposure, float Lwhite, unsigned TU_tex, unsigned TU_loglum) - { - glUniform1i(uniform_tex, TU_tex); - glUniform1i(uniform_logluminancetex, TU_loglum); - glUniform1f(uniform_exposure, exposure); - glUniform1f(uniform_lwhite, Lwhite); - } - GLuint DepthOfFieldShader::Program; GLuint DepthOfFieldShader::uniform_tex; GLuint DepthOfFieldShader::uniform_depth; diff --git a/src/graphics/shaders.hpp b/src/graphics/shaders.hpp index 127de8d65..dac9ea44c 100644 --- a/src/graphics/shaders.hpp +++ b/src/graphics/shaders.hpp @@ -523,15 +523,13 @@ public: static void setUniforms(unsigned TU_tex_128, unsigned TU_tex_256, unsigned TU_tex_512); }; -class ToneMapShader +class ToneMapShader : public ShaderHelperSingleton { public: - static GLuint Program; - static GLuint uniform_tex, uniform_logluminancetex, uniform_exposure, uniform_lwhite; - static GLuint vao; + GLuint TU_tex; + GLuint vao; - static void init(); - static void setUniforms(float exposure, float Lwhite, unsigned TU_tex, unsigned TU_logluminance); + ToneMapShader(); }; class DepthOfFieldShader