The quad scene node doesn't render the final image, and the buffers don't clear the previous render, plus the depth buffer is not rendered.
Here are some code of mine, I only implement solild and ambient shader first.
Code: Select all
createMRT("mrt_color_buffer", irr::video::ECF_A8R8G8B8);
createMRT("mrt_normal_buffer", irr::video::ECF_A8R8G8B8);
createMRT("mrt_depth_buffer", irr::video::ECF_G16R16F);
m_lightRenderer = new LightRenderer(m_renderer, &m_MRTs);
loadMaterials();
m_lightRenderer->setAmbientMaterial(getMaterial(MaterialType::AmbientLight));
m_renderer->getRenderDevice()->getSceneManager()->setLightManager(m_lightRenderer);
m_renderer->getRenderDevice()->getSceneManager()->setAmbientLight(irr::video::SColorf(0.5f,0.5f,0.5f,0.5f))
Code: Select all
LightRenderer::LightRenderer(Renderer* renderer, MRTs* mrt)
: m_renderer(renderer), m_quadLight(renderer), m_MRTs(mrt)
{
auto driver = m_renderer->getRenderDevice()->getVideoDriver();
auto dimension = driver->getCurrentRenderTargetSize();
m_solidFrameBuffer = driver->addRenderTargetTexture(dimension, "solid_buffer");
auto smgr = m_renderer->getRenderDevice()->getSceneManager();
m_ambientCB = new AmbientLightShaderCallback(smgr);
for (irr::u32 i= 0; i < m_MRTs->size(); i++) {
m_quadLight.setMaterialTexture(i, (*m_MRTs)[i].RenderTexture);
}
}
void LightRenderer::OnPreRender(array<ISceneNode*>& lightList) {
m_renderer->getRenderDevice()->getVideoDriver()->setRenderTarget(*m_MRTs, false, true);
}
void LightRenderer::OnPostRender() {
if (m_MRTs->size()) {
auto gbuffRect= irr::core::recti(irr::core::vector2di(0, 0), (*m_MRTs)[0].RenderTexture->getSize());
for(irr::u32 i = 0; i < m_MRTs->size(); i++) {
auto gbuffRectSmall = irr::core::recti(irr::core::vector2di((*m_MRTs)[i].RenderTexture->getSize().Width/4.0*i, 0),
irr::core::vector2di((*m_MRTs)[i].RenderTexture->getSize().Width/4.0*(i+1), (*m_MRTs)[i].RenderTexture->getSize().Height/4.0));
m_renderer->getRenderDevice()->getVideoDriver()->draw2DImage((*m_MRTs)[i].RenderTexture, gbuffRectSmall, gbuffRect);
}
}
}
void LightRenderer::OnRenderPassPreRender(E_SCENE_NODE_RENDER_PASS renderPass) {
}
void LightRenderer::OnRenderPassPostRender(E_SCENE_NODE_RENDER_PASS renderPass) {
if (renderPass == irr::scene::ESNRP_SOLID) {
auto device = m_renderer->getRenderDevice();
device->getVideoDriver()->setRenderTarget(m_solidFrameBuffer, true, false);
deferredRender();
device->getVideoDriver()->setRenderTarget(0, false, false);
device->getVideoDriver()->draw2DImage(m_solidFrameBuffer, irr::core::position2d<s32> (0,0));
}
}
void LightRenderer::OnNodePreRender(ISceneNode *node) {
}
void LightRenderer::OnNodePostRender(ISceneNode *node) {
}
void LightRenderer::deferredRender() {
// render ambient light
m_quadLight.setMaterialType((irr::video::E_MATERIAL_TYPE) m_ambientLightMaterial);
for (irr::u32 i = 0; i < m_MRTs->size(); i++) {
m_quadLight.setMaterialTexture(i, (*m_MRTs)[i].RenderTexture);
}
m_quadLight.render();
}
Code: Select all
QuadSceneNode::QuadSceneNode(Renderer* renderer, irr::scene::ISceneNode* parent)
: irr::scene::ISceneNode(parent, renderer->getRenderDevice()->getSceneManager())
{
m_buffer = new irr::scene::SMeshBuffer();
m_buffer->Vertices.push_back(irr::video::S3DVertex(
irr::core::vector3df(-1.0, 1.0, 0.0),
irr::core::vector3df(0.0, 0.0, 1.0), irr::video::SColor(255,255,255,255),
irr::core::vector2df(0.0, 0.0)));
m_buffer->Vertices.push_back(irr::video::S3DVertex(
irr::core::vector3df(1.0, 1.0, 0.0),
irr::core::vector3df(0.0, 0.0, 1.0), irr::video::SColor(255,255,255,255),
irr::core::vector2df(1.0, 0.0)));
m_buffer->Vertices.push_back(irr::video::S3DVertex(
irr::core::vector3df(1.0, -1.0, 0.0),
irr::core::vector3df(0.0, 0.0, 1.0), irr::video::SColor(255,255,255,255),
irr::core::vector2df(1.0, 1.0)));
m_buffer->Vertices.push_back(irr::video::S3DVertex(
irr::core::vector3df(-1.0, -1.0, 0.0),
irr::core::vector3df(0.0, 0.0, 1.0), irr::video::SColor(255,255,255,255),
irr::core::vector2df(0.0, 1.0)));
m_buffer->Indices.push_back(0);
m_buffer->Indices.push_back(1);
m_buffer->Indices.push_back(2);
m_buffer->Indices.push_back(3);
m_buffer->Indices.push_back(0);
m_buffer->Indices.push_back(2);
m_buffer->recalculateBoundingBox();
updateAbsolutePosition();
m_material.ZBuffer = false;
m_material.ZWriteEnable = false;
setMaterialFlag(irr::video::EMF_ZWRITE_ENABLE, false);
setMaterialFlag(irr::video::EMF_ZBUFFER, false);
setVisible(false);
}
void QuadSceneNode::render() {
auto driver = SceneManager->getVideoDriver();
driver->setTransform(irr::video::ETS_WORLD, AbsoluteTransformation);
driver->setMaterial(m_material);
driver->drawMeshBuffer(m_buffer);
}
QuadSceneNode::~QuadSceneNode() {
delete m_buffer;
}