Lights: Also use direct calls for lightblend.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@15039 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
4f209d38c6
commit
a21f77706a
@ -393,6 +393,39 @@ namespace PointLightShader
|
||||
}
|
||||
}
|
||||
|
||||
namespace LightBlendShader
|
||||
{
|
||||
GLuint Program = 0;
|
||||
GLuint attrib_position, attrib_texcoord;
|
||||
GLuint uniform_diffuse, uniform_specular, uniform_ambient_occlusion, uniform_specular_map, uniform_ambient;
|
||||
|
||||
GLuint vao = 0;
|
||||
|
||||
void init()
|
||||
{
|
||||
initGL();
|
||||
Program = LoadProgram(file_manager->getAsset("shaders/screenquad.vert").c_str(), file_manager->getAsset("shaders/lightblend.frag").c_str());
|
||||
attrib_position = glGetAttribLocation(Program, "Position");
|
||||
attrib_texcoord = glGetAttribLocation(Program, "Texcoord");
|
||||
uniform_diffuse = glGetUniformLocation(Program, "diffuse");
|
||||
uniform_specular = glGetUniformLocation(Program, "specular");
|
||||
uniform_ambient_occlusion = glGetUniformLocation(Program, "ambient_occlusion");
|
||||
uniform_specular_map = glGetUniformLocation(Program, "specular_map");
|
||||
uniform_ambient = glGetUniformLocation(Program, "ambient");
|
||||
|
||||
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
|
||||
void renderBloom(ITexture *in)
|
||||
@ -533,6 +566,45 @@ void PostProcessing::renderPointlight(ITexture *in, const std::vector<float> &po
|
||||
glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
void PostProcessing::renderLightbBlend(ITexture *diffuse, ITexture *specular, ITexture *ao, ITexture *specmap, bool debug)
|
||||
{
|
||||
const SColorf s = irr_driver->getSceneManager()->getAmbientLight();
|
||||
if (!LightBlendShader::Program)
|
||||
LightBlendShader::init();
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
if (debug)
|
||||
glBlendFunc(GL_ONE, GL_ZERO);
|
||||
else
|
||||
glBlendFunc(GL_DST_COLOR, GL_ZERO);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
glUseProgram(LightBlendShader::Program);
|
||||
glBindVertexArray(LightBlendShader::vao);
|
||||
|
||||
glUniform3f(LightBlendShader::uniform_ambient, s.r, s.g, s.b);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(diffuse)->getOpenGLTextureName());
|
||||
glUniform1i(LightBlendShader::uniform_diffuse, 0);
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(specular)->getOpenGLTextureName());
|
||||
glUniform1i(LightBlendShader::uniform_specular, 1);
|
||||
glActiveTexture(GL_TEXTURE2);
|
||||
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(ao)->getOpenGLTextureName());
|
||||
glUniform1i(LightBlendShader::uniform_ambient_occlusion, 2);
|
||||
glActiveTexture(GL_TEXTURE3);
|
||||
glBindTexture(GL_TEXTURE_2D, static_cast<irr::video::COpenGLTexture*>(specmap)->getOpenGLTextureName());
|
||||
glUniform1i(LightBlendShader::uniform_specular_map, 3);
|
||||
|
||||
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 */
|
||||
void PostProcessing::render()
|
||||
|
@ -78,6 +78,9 @@ public:
|
||||
/** Generate diffuse and specular map */
|
||||
void renderPointlight(video::ITexture *in, const std::vector<float> &positions, const std::vector<float> &colors, const std::vector<float> &energy);
|
||||
|
||||
/** Blend all light related map */
|
||||
void renderLightbBlend(video::ITexture *diffuse, video::ITexture *specular, video::ITexture *ao, video::ITexture *specmap, bool debug);
|
||||
|
||||
/** Render the post-processed scene */
|
||||
void render();
|
||||
|
||||
|
@ -808,30 +808,9 @@ void IrrDriver::renderLights(const core::aabbox3df& cambox,
|
||||
m_post_processing->drawQuad(cam, m_material);
|
||||
}
|
||||
|
||||
// Blend lights to the image
|
||||
video::SMaterial lightmat;
|
||||
lightmat.Lighting = false;
|
||||
lightmat.ZWriteEnable = false;
|
||||
lightmat.ZBuffer = video::ECFN_ALWAYS;
|
||||
lightmat.setFlag(video::EMF_BILINEAR_FILTER, false);
|
||||
lightmat.setTexture(0, m_rtts->getRTT(RTT_TMP1));
|
||||
lightmat.setTexture(1, m_rtts->getRTT(RTT_TMP2));
|
||||
lightmat.setTexture(2, m_rtts->getRTT(RTT_SSAO));
|
||||
lightmat.setTexture(3, m_rtts->getRTT(RTT_SPECULARMAP));
|
||||
|
||||
lightmat.MaterialType = m_shaders->getShader(ES_LIGHTBLEND);
|
||||
if (!m_lightviz)
|
||||
lightmat.MaterialTypeParam = video::pack_textureBlendFunc(video::EBF_DST_COLOR, video::EBF_ZERO);
|
||||
else
|
||||
lightmat.MaterialTypeParam = video::pack_textureBlendFunc(video::EBF_ONE, video::EBF_ZERO);
|
||||
lightmat.BlendOperation = video::EBO_ADD;
|
||||
|
||||
lightmat.TextureLayer[0].TextureWrapU =
|
||||
lightmat.TextureLayer[0].TextureWrapV = video::ETC_CLAMP_TO_EDGE;
|
||||
|
||||
m_video_driver->setRenderTarget(m_rtts->getRTT(RTT_COLOR), false, false);
|
||||
if (!m_mipviz)
|
||||
m_post_processing->drawQuad(cam, lightmat);
|
||||
m_post_processing->renderLightbBlend(m_rtts->getRTT(RTT_TMP1), m_rtts->getRTT(RTT_TMP2), m_rtts->getRTT(RTT_SSAO), m_rtts->getRTT(RTT_SPECULARMAP), m_lightviz);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user