Use a passthrough shader for some fullscreen effect.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@15043 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
645d4504ab
commit
7d1df19342
@ -1,9 +1,9 @@
|
|||||||
#version 130
|
#version 130
|
||||||
uniform sampler2D texture;
|
uniform sampler2D texture;
|
||||||
|
|
||||||
in vec2 tc;
|
in vec2 uv;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_FragColor = texture2D(texture, tc);
|
gl_FragColor = texture2D(texture, uv);
|
||||||
}
|
}
|
@ -6,7 +6,7 @@ uniform vec2 texsize;
|
|||||||
|
|
||||||
in vec2 position;
|
in vec2 position;
|
||||||
in vec2 texcoord;
|
in vec2 texcoord;
|
||||||
out vec2 tc;
|
out vec2 uv;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
@ -484,6 +484,34 @@ namespace Gaussian6VBlurShader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace PassThroughShader
|
||||||
|
{
|
||||||
|
GLuint Program = 0;
|
||||||
|
GLuint attrib_position, attrib_texcoord;
|
||||||
|
GLuint uniform_texture;
|
||||||
|
|
||||||
|
GLuint vao = 0;
|
||||||
|
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
initGL();
|
||||||
|
Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/texturedquad.frag").c_str());
|
||||||
|
attrib_position = glGetAttribLocation(Program, "Position");
|
||||||
|
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
|
||||||
|
uniform_texture = glGetUniformLocation(Program, "texture");
|
||||||
|
if (!quad_vbo)
|
||||||
|
initQuadVBO();
|
||||||
|
glGenVertexArrays(1, &vao);
|
||||||
|
glBindVertexArray(vao);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, quad_vbo);
|
||||||
|
glEnableVertexAttribArray(attrib_position);
|
||||||
|
glEnableVertexAttribArray(attrib_texcoord);
|
||||||
|
glVertexAttribPointer(attrib_position, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0);
|
||||||
|
glVertexAttribPointer(attrib_texcoord, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid*)(2 * sizeof(float)));
|
||||||
|
glBindVertexArray(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static
|
static
|
||||||
void renderBloom(ITexture *in)
|
void renderBloom(ITexture *in)
|
||||||
@ -703,6 +731,28 @@ void PostProcessing::renderGaussian6Blur(video::ITexture *in, video::ITexture *t
|
|||||||
glEnable(GL_DEPTH_TEST);
|
glEnable(GL_DEPTH_TEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
void renderPassThrough(ITexture *tex)
|
||||||
|
{
|
||||||
|
if (!PassThroughShader::Program)
|
||||||
|
PassThroughShader::init();
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
|
||||||
|
glUseProgram(PassThroughShader::Program);
|
||||||
|
glBindVertexArray(PassThroughShader::vao);
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(tex)->getOpenGLTextureName());
|
||||||
|
glUniform1i(PassThroughShader::uniform_texture, 0);
|
||||||
|
|
||||||
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
||||||
|
glEnable(GL_DEPTH_TEST);
|
||||||
|
glDisable(GL_BLEND);
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
/** Render the post-processed scene */
|
/** Render the post-processed scene */
|
||||||
void PostProcessing::render()
|
void PostProcessing::render()
|
||||||
@ -853,25 +903,17 @@ void PostProcessing::render()
|
|||||||
} // end forced bloom
|
} // end forced bloom
|
||||||
|
|
||||||
// To half
|
// To half
|
||||||
m_material.MaterialType = EMT_SOLID;
|
|
||||||
m_material.setTexture(0, irr_driver->getRTT(RTT_TMP3));
|
|
||||||
drv->setRenderTarget(irr_driver->getRTT(RTT_HALF1), true, false);
|
drv->setRenderTarget(irr_driver->getRTT(RTT_HALF1), true, false);
|
||||||
|
renderPassThrough(irr_driver->getRTT(RTT_TMP3));
|
||||||
|
|
||||||
drawQuad(cam, m_material);
|
|
||||||
|
|
||||||
// To quarter
|
// To quarter
|
||||||
m_material.MaterialType = EMT_SOLID;
|
drv->setRenderTarget(irr_driver->getRTT(RTT_QUARTER1), true, false);
|
||||||
m_material.setTexture(0, irr_driver->getRTT(RTT_HALF1));
|
renderPassThrough(irr_driver->getRTT(RTT_HALF1));
|
||||||
drv->setRenderTarget(irr_driver->getRTT(RTT_QUARTER1), true, false);
|
|
||||||
|
|
||||||
drawQuad(cam, m_material);
|
|
||||||
|
|
||||||
// To eighth
|
// To eighth
|
||||||
m_material.MaterialType = EMT_SOLID;
|
drv->setRenderTarget(irr_driver->getRTT(RTT_EIGHTH1), true, false);
|
||||||
m_material.setTexture(0, irr_driver->getRTT(RTT_QUARTER1));
|
renderPassThrough(irr_driver->getRTT(RTT_QUARTER1));
|
||||||
drv->setRenderTarget(irr_driver->getRTT(RTT_EIGHTH1), true, false);
|
|
||||||
|
|
||||||
drawQuad(cam, m_material);
|
|
||||||
|
|
||||||
// Blur it for distribution.
|
// Blur it for distribution.
|
||||||
renderGaussian6Blur(irr_driver->getRTT(RTT_EIGHTH1), irr_driver->getRTT(RTT_EIGHTH2), 8.f / UserConfigParams::m_width, 8.f / UserConfigParams::m_height);
|
renderGaussian6Blur(irr_driver->getRTT(RTT_EIGHTH1), irr_driver->getRTT(RTT_EIGHTH2), 8.f / UserConfigParams::m_width, 8.f / UserConfigParams::m_height);
|
||||||
@ -1075,26 +1117,16 @@ void PostProcessing::render()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Final blit
|
// Final blit
|
||||||
|
// TODO : Use glBlitFramebuffer
|
||||||
drv->setRenderTarget(ERT_FRAME_BUFFER, false, false);
|
drv->setRenderTarget(ERT_FRAME_BUFFER, false, false);
|
||||||
if (irr_driver->getNormals())
|
if (irr_driver->getNormals())
|
||||||
{
|
renderPassThrough(irr_driver->getRTT(RTT_NORMAL_AND_DEPTH));
|
||||||
m_material.MaterialType = irr_driver->getShader(ES_FLIP);
|
else if (irr_driver->getSSAOViz())
|
||||||
m_material.setTexture(0, irr_driver->getRTT(RTT_NORMAL_AND_DEPTH));
|
renderPassThrough(irr_driver->getRTT(RTT_SSAO));
|
||||||
drawQuad(cam, m_material);
|
else if (irr_driver->getShadowViz())
|
||||||
} else if (irr_driver->getSSAOViz())
|
renderPassThrough(irr_driver->getRTT(RTT_SHADOW));
|
||||||
{
|
else
|
||||||
m_material.MaterialType = irr_driver->getShader(ES_FLIP);
|
|
||||||
m_material.setTexture(0, irr_driver->getRTT(RTT_SSAO));
|
|
||||||
drawQuad(cam, m_material);
|
|
||||||
} else if (irr_driver->getShadowViz())
|
|
||||||
{
|
|
||||||
m_material.MaterialType = irr_driver->getShader(ES_FLIP);
|
|
||||||
m_material.setTexture(0, irr_driver->getRTT(RTT_DISPLACE));
|
|
||||||
drawQuad(cam, m_material);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
renderColorLevel(in);
|
renderColorLevel(in);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} // render
|
} // render
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user