Add some code to average log luminance.

This commit is contained in:
vlj 2014-03-30 22:56:50 +02:00 committed by Vincent Lejeune
parent a2ab6fc80c
commit 6e8b45a6d8
6 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,14 @@
uniform sampler2D tex;
in vec2 uv;
out vec4 FragColor;
float delta = 0.0001;
void main()
{
vec3 weight = vec3(0.2125f, 0.7154f, 0.0721f);
vec3 col = texture(tex, uv).xyz;
float luma = dot(col, weight);
FragColor = vec4(log(luma + delta));
}

View File

@ -618,6 +618,28 @@ static void renderGodRay(GLuint tex, const core::vector2df &sunpos)
glEnable(GL_DEPTH_TEST);
}
static void averageTexture(GLuint tex)
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glGenerateMipmap(GL_TEXTURE_2D);
}
static void computeLogLuminance(GLuint tex)
{
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
IVideoDriver *const drv = irr_driver->getVideoDriver();
drv->setRenderTarget(irr_driver->getRTT(RTT_LOG_LUMINANCE), false, false);
glUseProgram(FullScreenShader::LogLuminanceShader::Program);
glBindVertexArray(FullScreenShader::LogLuminanceShader::vao);
setTexture(0, tex, GL_LINEAR, GL_LINEAR);
FullScreenShader::LogLuminanceShader::setUniforms(0);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
averageTexture(getTextureGLuint(irr_driver->getRTT(RTT_LOG_LUMINANCE)));
}
// ----------------------------------------------------------------------------
/** Render the post-processed scene */
void PostProcessing::render()

View File

@ -59,6 +59,7 @@ RTT::RTT()
rtts[RTT_TMP4] = drv->addRenderTargetTexture(res, "rtt.tmp4", ECF_R16F, stencil);
rtts[RTT_NORMAL_AND_DEPTH] = drv->addRenderTargetTexture(res, "rtt.normal_and_depth", ECF_G16R16F, stencil);
rtts[RTT_COLOR] = drv->addRenderTargetTexture(res, "rtt.color", ECF_A16B16G16R16F, stencil);
rtts[RTT_LOG_LUMINANCE] = drv->addRenderTargetTexture(shadowsize0, "rtt.logluminance", ECF_R16F, stencil);
rtts[RTT_HALF1] = drv->addRenderTargetTexture(half, "rtt.half1", ECF_A16B16G16R16F, stencil);
rtts[RTT_HALF2] = drv->addRenderTargetTexture(half, "rtt.half2", ECF_A16B16G16R16F, stencil);

View File

@ -33,6 +33,7 @@ enum TypeRTT
RTT_TMP4,
RTT_NORMAL_AND_DEPTH,
RTT_COLOR,
RTT_LOG_LUMINANCE,
RTT_HALF1,
RTT_HALF2,

View File

@ -314,6 +314,7 @@ void Shaders::loadShaders()
FullScreenShader::MotionBlurShader::init();
FullScreenShader::GodFadeShader::init();
FullScreenShader::GodRayShader::init();
FullScreenShader::LogLuminanceShader::init();
MeshShader::ColorizeShader::init();
MeshShader::NormalMapShader::init();
MeshShader::ObjectPass1Shader::init();
@ -2319,6 +2320,24 @@ namespace FullScreenShader
glUniform2f(uniform_sunpos, sunpos.X, sunpos.Y);
glUniform1i(uniform_tex, TU_tex);
}
GLuint LogLuminanceShader::Program;
GLuint LogLuminanceShader::uniform_tex;
GLuint LogLuminanceShader::vao;
void LogLuminanceShader::init()
{
Program = LoadProgram(
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/logluminance.frag").c_str());
uniform_tex = glGetUniformLocation(Program, "tex");
vao = createVAO(Program);
}
void LogLuminanceShader::setUniforms(unsigned TU_tex)
{
glUniform1i(uniform_tex, TU_tex);
}
}
namespace UIShader

View File

@ -665,6 +665,17 @@ public:
static void setUniforms(const core::vector2df &sunpos, unsigned TU_tex);
};
class LogLuminanceShader
{
public:
static GLuint Program;
static GLuint uniform_tex;
static GLuint vao;
static void init();
static void setUniforms(unsigned TU_tex);
};
}
namespace UIShader