[fixed]Possible render to texture transparency bug

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
techiemac
Posts: 14
Joined: Tue Dec 26, 2006 7:16 pm

[fixed]Possible render to texture transparency bug

Post by techiemac »

I think I might have found a possible bug though my use of the EDT_BURNINGSVIDEO renderer.
Currently I have been playing with rendering scenes in textures but I think I might have run smack center into a bug. Hopefully it's in my code so then it's a much easier fix :)

When I create a EDT_BURNINGSVIDEO device the scene that should be rendered in the actual texture is transparent (material type is EMT_TRANSPARENT_ALPHA_CHANNEL). But when I use the EDT_DIRECT3D9 device, everything works perfectly (scene is not transparent).

This is done with the Irrlicht 1.3 engine.

The best illustration of this is some hacked up code I have attached form Example 13 RenderToTexture. Simply replace the code in main.cpp with the code below to illustrate the problem.

Code: Select all


/*
This tutorial shows how to render to a texture using Irrlicht. Render to texture is a feature with which
it is possible to create nice special effects. In addition, this tutorial shows how to enable specular
highlights.

In the beginning, everything as usual. Include the needed headers, ask the user for the rendering
driver, create the Irrlicht Device:
*/

#include <irrlicht.h>
#include <iostream>

using namespace irr;

#pragma comment(lib, "Irrlicht.lib")

int main()
{
	// create device and exit if creation failed

	IrrlichtDevice *device =
    createDevice(video::EDT_DIRECT3D9 EDT_BURNINGSVIDEO, core::dimension2d<s32>(640, 480), 32, false, false);

	if (device == 0)
		return 1; // could not create selected driver.

	video::IVideoDriver* driver = device->getVideoDriver(); 
  scene::ISceneManager* smgrRender = device->getSceneManager();
  scene::ISceneManager* smgrTexture = smgrRender->createNewSceneManager();

	// load and display animated fairy mesh
	scene::IAnimatedMeshSceneNode* fairy = smgrTexture->addAnimatedMeshSceneNode(smgrTexture->getMesh("../../media/faerie.md2"));

	if (fairy)
	{
		fairy->setMaterialTexture(0, driver->getTexture("../../media/faerie2.bmp")); // set diffuse texture
		fairy->setMaterialFlag(video::EMF_LIGHTING, false); // disable dynamic lighting
		fairy->setPosition(core::vector3df(-10,0,-100));
	}

	// add fps camera
	scene::ICameraSceneNode* fpsCamera = smgrRender->addCameraSceneNodeFPS();
	fpsCamera->setPosition(core::vector3df(-50,50,-150));

	// disable mouse cursor
	device->getCursorControl()->setVisible(false);

  // Add skybox
	smgrRender->addSkyBoxSceneNode(
	                        driver->getTexture("../../media/irrlicht2_up.jpg"),
	                        driver->getTexture("../../media/irrlicht2_dn.jpg"),
	                        driver->getTexture("../../media/irrlicht2_lf.jpg"),
	                        driver->getTexture("../../media/irrlicht2_rt.jpg"),
	                        driver->getTexture("../../media/irrlicht2_ft.jpg"),
	                        driver->getTexture("../../media/irrlicht2_bk.jpg"));


	// create test cube
	scene::ISceneNode* testCube = smgrRender->addCubeSceneNode(60);

	testCube->setPosition(core::vector3df(-100,0,-100));
	testCube->setMaterialFlag(video::EMF_LIGHTING, false); // disable dynamic lighting

	// set window caption
	device->setWindowCaption(L"Irrlicht Engine - Render to Texture and Specular Highlights example");

	// create render target
	video::ITexture* rt = 0;
	scene::ICameraSceneNode* fixedCam = 0;
	
	if (driver->queryFeature(video::EVDF_RENDER_TO_TARGET))
	{
		rt = driver->createRenderTargetTexture(core::dimension2d<s32>(256,256));

    // add fixed camera
		fixedCam = smgrTexture->addCameraSceneNode(0, core::vector3df(10,10,-80), core::vector3df(-10,10,-100));
    smgrTexture->setActiveCamera(fixedCam);

		testCube->setMaterialTexture(0, rt); // set material of cube to render target                          
    testCube->setMaterialType(irr::video::EMT_TRANSPARENT_ALPHA_CHANNEL); 
	}

	while(device->run())
  {
	  if (device->isWindowActive())
	  {
		  driver->beginScene(true, true, 0);

		  if (rt)
		  {
			  // draw scene into render target
  			
			  // set render target texture
			  driver->setRenderTarget(rt, true, true, video::SColor(255,0,0,255));

			  // draw whole scene into render buffer
			  smgrTexture->drawAll();

			  // set back old render target
			  driver->setRenderTarget(0);
		  }
  		
		  // draw scene normally
		  smgrRender->drawAll(); 

		  driver->endScene();
	  }
  }



	if (rt)
		rt->drop(); // drop render target because we created if with a create() method

  if (NULL != device)
  {
   device->drop(); // drop device
  }

  if (NULL != smgrTexture)
  {
    smgrTexture->drop();
  }

  return 0;
}


Obviously if you want to see everything working as designed, change the device to EDT_DIRECT3D9.
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

Thats whats it is should look like :wink: .

RTT in ogl and dx have the alpha bit off (so is their framebuffers). Since the fairy has no alpha data it is captured correctly in burning video and thus is transparent! see my post in the bug reports.
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
techiemac
Posts: 14
Joined: Tue Dec 26, 2006 7:16 pm

So...

Post by techiemac »

The weird part about that is the actual object when rendering in the Burning Video renderer is transparent instead of the object background.

So it seems somewhat counter intuitive. In other words, I would expect the background to be transparent instead of the object in the scene.

If I can find a place to host an image, I can attach screenshots.

So if this is just something in my code (originally I had posted to the Advanced Help area since I though it could be my code but the post got moved here), what needs to be fixed to allow the object in the scene being rendered to the texture to have a transparent background?

Thanks
omaremad
Competition winner
Posts: 1027
Joined: Fri Jul 15, 2005 11:30 pm
Location: Cairo,Egypt

Post by omaremad »

give the objects a texture with alpha info and change the clear colour for the scene:

Code: Select all

           driver->setRenderTarget(rt, true, true, video::SColor(255,0,0,255)); 

to

Code: Select all

           driver->setRenderTarget(rt, true, true, video::SColor(255,0,0,0)); 
"Irrlicht is obese"

If you want modern rendering techniques learn how to make them or go to the engine next door =p
techiemac
Posts: 14
Joined: Tue Dec 26, 2006 7:16 pm

Post by techiemac »

Thanks for the response.
Hmm it didn't seem to work. So I found a site to throw some screenshot up.

Following image uses BurningVideo with the following setRender target code

Code: Select all

driver->setRenderTarget(rt, true, true, video::SColor(0,0,0,0));
Image


Following image uses DirectX 9 with the following setRender target code

Code: Select all

driver->setRenderTarget(rt, true, true, video::SColor(0,0,0,0));
Image


Following image uses BurningVideo with the following setRender target code

Code: Select all

driver->setRenderTarget(rt, true, true, video::SColor(255,0,0,0));
Image


Following image uses DirectX 9 with the following setRender target code

Code: Select all

driver->setRenderTarget(rt, true, true, video::SColor(255,0,0,0));
Image


So as you can see it looks like something is somewhat wierd with the transparent render pass on the burning video rasterizer.

Am I missing something in the code I attached?

Thanks again for posting a response!
techiemac
Posts: 14
Joined: Tue Dec 26, 2006 7:16 pm

Post by techiemac »

Does anyone out there know if there is a doc that describes the internals of BurningsRenderer? I have started to step into the code and poke around but if there is a README or something (maybe there is and I'm just missing it), it would help with debugging!


Edit:
I should note that this issue does not occur with Irrlicht 1.2
techiemac
Posts: 14
Joined: Tue Dec 26, 2006 7:16 pm

Progress

Post by techiemac »

Anyone know if a svn update may have a bug fix for this issue?

Currently I'm working around it for the sake of my project's release schedule but it does make things a little more difficult.

If there is a pointer to a design of Burning's Renderer then I may be able to find a fix (so my company can give back to irrlicht).
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

At least for the last question I can give the definitive answer that no fixes are in SVN, yet. No documentation either, at least none publically available that I know of.
squisher
Competition winner
Posts: 91
Joined: Sat May 17, 2008 2:23 am
Contact:

Post by squisher »

Hiya Hybrid,

Bumping an old thread but it seems to me this is still a problem and not just with BurningsVideo. I use OpenGL on Linux.

Code: Select all

#include <irrlicht.h>

#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#endif

using namespace irr;
using namespace scene;
using namespace video;
using namespace gui;
using namespace core;


/*** main function **************************************************************/

int main(int argc, char* argv[])
{
   u32 height = 300;
   u32 width = 400;
   IrrlichtDevice* device = createDevice(video::EDT_OPENGL, dimension2d<s32>(width, height), 32,
       false, false, true);
 
   IVideoDriver* driver = device->getVideoDriver();
   ISceneManager* smgr = device->getSceneManager();

   smgr->addLightSceneNode(0, vector3df(1000,0,-1000), SColorf(0.1f,0.2f,0.3f), 2200.0f);
   smgr->addLightSceneNode(0, vector3df(-50.0f, 300.0f, 500.0f), SColorf(0.5f, 0.4f, 0.25f, 0.8f), 5000000.0f);
   smgr->setAmbientLight(SColorf(0.12f, 0.18f, 0.24f));

   smgr->addCameraSceneNode();
   
   ISceneNode* cube = smgr->addCubeSceneNode(20, 0, -1, vector3df(0,0,35), vector3df(200, 45,-130));
   ISceneNode* renderNode = smgr->addCubeSceneNode(40, 0, -1, vector3df(12,-5,68), vector3df(0, 0, 0));
   
   ITexture* renderTexture = driver->createRenderTargetTexture(dimension2d<s32>(256, 256));
   renderNode->getMaterial(0).setTexture(0, renderTexture);
   renderNode->getMaterial(0).Lighting = false;
   renderNode->getMaterial(0).MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
   renderNode->getMaterial(0).BackfaceCulling = false;
   
   while(device->run())
   {
       driver->beginScene(true, true, 0);
       
       driver->setRenderTarget(renderTexture, true, true, SColor(0,0,0,0));
       cube->setVisible(true);
       renderNode->setVisible(false);
       smgr->drawAll();
       
       driver->setRenderTarget(0, true, true, SColor(255,0,64,0));
       cube->setVisible(false);
       renderNode->setVisible(true);
       smgr->drawAll();
       driver->endScene();
   }
} 
Produces the following scene:

Image

I expect to see a blue cube on a green background, with no black areas -- kinda like techiemac's second screenshot.

I do this by first setting the fill color of the renderTexture to SColor(0,0,0,0), which I believe to be transparent black. Then I render the cube on to the renderTexture, and finally render the "black" cube. The "black" cube's material is EMT_TRANSPARENT_ALPHA_CHANNEL_REF, which means the areas on the cube that are still colored with (0,0,0,0) should be completely transparent -- right?

I hope I am just missing a step in my code... if so please let me know. That would be much easier than waiting for a bug fix :-)
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

Try
renderNode->render() or renderNode->draw() (can't remember)
instead of drawall()
squisher
Competition winner
Posts: 91
Joined: Sat May 17, 2008 2:23 am
Contact:

Post by squisher »

Code: Select all

   while(device->run())
   {
       driver->beginScene(true, true, 0);
       
       driver->setRenderTarget(renderTexture, true, true, SColor(0,0,0,0));
       renderNode->setVisible(false);
       smgr->drawAll();
       
       driver->setRenderTarget(0, true, true, SColor(255,0,64,0));
       renderNode->setVisible(true);
       renderNode->render();
       driver->endScene();
   }
Tried as you suggested... still the same result
hybrid
Admin
Posts: 14143
Joined: Wed Apr 19, 2006 9:20 pm
Location: Oldenburg(Oldb), Germany
Contact:

Post by hybrid »

You have to use SVN/trunk, because the RTT transparency has been added only to this repository.
Dorth
Posts: 931
Joined: Sat May 26, 2007 11:03 pm

Post by Dorth »

ah, well, my apologies ^^
burningreggae
Posts: 66
Joined: Wed Oct 04, 2006 2:07 pm

Post by burningreggae »

fixed in burningvideo 0.40.

supporting destination-alpha
burningreggae
Post Reply