I tried to do a render target on a 32bits color texture initially cleared with fully transparent pixels. I ran into the following issue that the alpha blending rule when rendering onto this texture is not correct : the alpha result seems to take into consideration the color of the source texture (the render target) although its alpha is 0. The result pixels are then tint with the render target color and even the destination alpha is incorrect.
Here is a sample demonstrating the issue :
Code: Select all
int main()
{
// ask user for driver
video::E_DRIVER_TYPE driverType=driverChoiceConsole();
if (driverType==video::EDT_COUNT)
return 1;
// create device
core::dimension2d<u32> dim(800, 600);
IrrlichtDevice *device = createDevice(driverType, dim, 32);
if (device == 0)
return 1; // could not create selected driver.
device->setWindowCaption(L"Irrlicht Engine - 2D Graphics Demo");
video::IVideoDriver* driver = device->getVideoDriver();
// create 2 render target textures cleared with 2 different fully transparent colors : black and red,
// and then draw on it a semi transparent white square on it
video::ITexture* renderTarget1 = driver->addRenderTargetTexture(dim, "RTT1", video::ECF_A8R8G8B8);
if(renderTarget1)
{
driver->beginScene(true, true, video::SColor(255,0,0,0));
// set render target texture
driver->setRenderTarget(renderTarget1, true, true, video::SColor(0,0,0,0));
driver->setTransform(video::ETS_VIEW, core::IdentityMatrix); //<- set view matrix to identity
driver->draw2DRectangle(video::SColor(100,255,255,255),
core::rect<s32>(100, 0, 200, 100));
// set back old render target
// The buffer might have been distorted, so clear it
driver->setRenderTarget(0, true, true, video::SColor(0,0,0,0));
driver->setTransform(video::ETS_VIEW, core::IdentityMatrix); //<- set view matrix to identity
driver->endScene();
}
video::ITexture* renderTarget2 = driver->addRenderTargetTexture(dim, "RTT2", video::ECF_A8R8G8B8);
if(renderTarget2)
{
driver->beginScene(true, true, video::SColor(255,0,0,0));
// set render target texture
driver->setRenderTarget(renderTarget2, true, true, video::SColor(0,255,0,0));
driver->setTransform(video::ETS_VIEW, core::IdentityMatrix); //<- set view matrix to identity
driver->draw2DRectangle(video::SColor(100,255,255,255),
core::rect<s32>(200, 0, 300, 100));
// set back old render target
// The buffer might have been distorted, so clear it
driver->setRenderTarget(0, true, true, video::SColor(0,0,0,0));
driver->setTransform(video::ETS_VIEW, core::IdentityMatrix); //<- set view matrix to identity
driver->endScene();
}
while(device->run())
{
if (device->isWindowActive())
{
u32 time = device->getTimer()->getTime();
driver->beginScene(true, true, video::SColor(255,0,0,0));
driver->draw2DRectangle(core::rect<s32>(0, 50, 400, 150),
video::SColor(255,0,0,255), video::SColor(255,0,0,255),
video::SColor(255,0,255,0), video::SColor(255,0,255,0));
core::position2d<s32> m = device->getCursorControl()->getPosition();
driver->draw2DRectangle(video::SColor(100,255,255,255),
core::rect<s32>(0, 0, 100, 100));
driver->draw2DImage(renderTarget1, core::position2d<s32>(0,0),
core::rect<s32>(core::position2d<s32>(0,0), renderTarget1->getSize()), 0, video::SColor(255,255,255,255), true);
driver->draw2DImage(renderTarget2, core::position2d<s32>(0,0),
core::rect<s32>(core::position2d<s32>(0,0), renderTarget2->getSize()), 0, video::SColor(255,255,255,255), true);
driver->endScene();
}
}
device->drop();
return 0;
}
The 1st square on the left is directly rendered on the screen,
the second one is rendered through the 1st render target initially cleared with fully transparent black pixels,
and the 3rd one is rendered through rge 2nd render target initially cleared with fully transparent red pixels.