Gather bloom effect to avoid extra texture read.
I have a .5ms win here...
This commit is contained in:
@@ -1,19 +1,24 @@
|
||||
uniform sampler2D tex;
|
||||
uniform sampler2D tex_128;
|
||||
uniform sampler2D tex_256;
|
||||
uniform sampler2D tex_512;
|
||||
|
||||
layout (std140) uniform MatrixesData
|
||||
{
|
||||
mat4 ViewMatrix;
|
||||
mat4 ProjectionMatrix;
|
||||
mat4 InverseViewMatrix;
|
||||
mat4 InverseProjectionMatrix;
|
||||
mat4 ShadowViewProjMatrixes[4];
|
||||
vec2 screen;
|
||||
};
|
||||
|
||||
#if __VERSION__ >= 130
|
||||
in vec2 uv;
|
||||
out vec4 FragColor;
|
||||
#else
|
||||
varying vec2 uv;
|
||||
#define FragColor gl_FragColor
|
||||
#endif
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec4 col = texture(tex, uv);
|
||||
|
||||
col.xyz *= 10.0 * col.a;
|
||||
|
||||
FragColor = vec4(col.xyz, 1.);
|
||||
vec2 uv = gl_FragCoord.xy / screen;
|
||||
vec4 col = .125 * texture(tex_128, uv);
|
||||
col += .25 * texture(tex_256, uv);
|
||||
col += .5 * texture(tex_512, uv);
|
||||
FragColor = vec4(col.xyz, 1.);
|
||||
}
|
||||
|
||||
@@ -783,14 +783,16 @@ FrameBuffer *PostProcessing::render(scene::ICameraSceneNode * const camnode)
|
||||
// Additively blend on top of tmp1
|
||||
in_fbo->Bind();
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
glBlendColor(.125, .125, .125, .125);
|
||||
renderPassThrough(irr_driver->getRenderTargetTexture(RTT_BLOOM_128));
|
||||
glBlendColor(.25, .25, .25, .25);
|
||||
renderPassThrough(irr_driver->getRenderTargetTexture(RTT_BLOOM_256));
|
||||
glBlendColor(.5, .5, .5, .5);
|
||||
renderPassThrough(irr_driver->getRenderTargetTexture(RTT_BLOOM_512));
|
||||
setTexture(0, irr_driver->getRenderTargetTexture(RTT_BLOOM_128), GL_LINEAR, GL_LINEAR);
|
||||
setTexture(1, irr_driver->getRenderTargetTexture(RTT_BLOOM_256), GL_LINEAR, GL_LINEAR);
|
||||
setTexture(2, irr_driver->getRenderTargetTexture(RTT_BLOOM_512), GL_LINEAR, GL_LINEAR);
|
||||
glUseProgram(FullScreenShader::BloomBlendShader::Program);
|
||||
FullScreenShader::BloomBlendShader::setUniforms(0, 1, 2);
|
||||
glBindVertexArray(FullScreenShader::BloomBlendShader::vao);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 3);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
} // end if bloom
|
||||
PROFILER_POP_CPU_MARKER();
|
||||
|
||||
@@ -2089,20 +2089,27 @@ namespace FullScreenShader
|
||||
}
|
||||
|
||||
GLuint BloomBlendShader::Program;
|
||||
GLuint BloomBlendShader::uniform_texture;
|
||||
GLuint BloomBlendShader::uniform_tex_128;
|
||||
GLuint BloomBlendShader::uniform_tex_256;
|
||||
GLuint BloomBlendShader::uniform_tex_512;
|
||||
GLuint BloomBlendShader::vao;
|
||||
|
||||
void BloomBlendShader::init()
|
||||
{
|
||||
Program = LoadProgram(
|
||||
GL_VERTEX_SHADER, file_manager->getAsset("shaders/screenquad.vert").c_str(),
|
||||
GL_FRAGMENT_SHADER, file_manager->getAsset("shaders/bloomblend.frag").c_str());
|
||||
uniform_texture = glGetUniformLocation(Program, "tex");
|
||||
vao = createVAO(Program);
|
||||
uniform_tex_128 = glGetUniformLocation(Program, "tex_128");
|
||||
uniform_tex_256 = glGetUniformLocation(Program, "tex_256");
|
||||
uniform_tex_512 = glGetUniformLocation(Program, "tex_512");
|
||||
vao = createFullScreenVAO(Program);
|
||||
}
|
||||
|
||||
void BloomBlendShader::setUniforms(unsigned TU_tex)
|
||||
void BloomBlendShader::setUniforms(unsigned TU_tex_128, unsigned TU_tex_256, unsigned TU_tex_512)
|
||||
{
|
||||
glUniform1i(FullScreenShader::BloomShader::uniform_texture, TU_tex);
|
||||
glUniform1i(uniform_tex_128, TU_tex_128);
|
||||
glUniform1i(uniform_tex_256, TU_tex_256);
|
||||
glUniform1i(uniform_tex_512, TU_tex_512);
|
||||
}
|
||||
|
||||
GLuint ToneMapShader::Program;
|
||||
|
||||
@@ -526,11 +526,11 @@ class BloomBlendShader
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint uniform_texture;
|
||||
static GLuint uniform_tex_128, uniform_tex_256, uniform_tex_512;
|
||||
static GLuint vao;
|
||||
|
||||
static void init();
|
||||
static void setUniforms(unsigned TU_tex);
|
||||
static void setUniforms(unsigned TU_tex_128, unsigned TU_tex_256, unsigned TU_tex_512);
|
||||
};
|
||||
|
||||
class ToneMapShader
|
||||
|
||||
Reference in New Issue
Block a user