Changes to MRTs in 1.9-svn?

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
amziraro
Posts: 13
Joined: Fri Jan 22, 2016 2:09 pm
Location: Australia

Changes to MRTs in 1.9-svn?

Post by amziraro »

Hi all,

Not sure if this is the right place to post but here we go. I'm using the current SVN trunk version of Irrlicht.
I'm trying to update irrRenderer since I don't fancy writing a deferred renderer from scratch but I've had some difficulty understanding how Multiple Render Targets actually work in 1.9-svn vs 1.8.

1.8 seems to have this method which lets you give an array of IRenderTargets, but I can't find a directly corresponding method in 1.9.
I can see there's an addRenderTarget() method (and corresponding methods for remove and removeall...), so I assume you can add multiple render targets and then set them up with setRenderTargetEx?
Primarily I'm not really sure how addRenderTarget should be used to do what I want.

Any help would be excellent, thanks! :D
CuteAlien
Admin
Posts: 9733
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Changes to MRTs in 1.9-svn?

Post by CuteAlien »

Ugh, I haven't used MRT's yet myself, but from interface I'd say you call videoDriver->addRenderTarget() to get a new IRenderTarget.
In there you call setTexture - which despite it's name accepts an array.
And then activate with videoDriver->setRenderTargetEx

And be aware that setTexture might be marked deprecated and replaced by setTextures before 1.9 (renaming that to show it's plural and not a single texture or not renaming as that breaks the interface once more is one of those todo's which I can't decide on since years...). But probably I'll just accept it at this point *sigh*
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
amziraro
Posts: 13
Joined: Fri Jan 22, 2016 2:09 pm
Location: Australia

Re: Changes to MRTs in 1.9-svn?

Post by amziraro »

I think I might get it (I got it to compile right I think but I think I won't need this till later or I need to make changes elsewhere), the biggest hurdle here is I only vaguely understand how irrRenderer works even though its realistically not that much code, I'll have to dig in a bit deeper tomorrow. Seem to be a handful little things that aren't right and a few bigger ones...

I understand I might not get the most stable API from month to month if I use trunk/svn, but I think its worth stuff breaking occasionally rather than have to update *all* my code all at once when 1.9 is released, plus I get new features, but thanks for the heads up!

Many thanks!
amziraro
Posts: 13
Joined: Fri Jan 22, 2016 2:09 pm
Location: Australia

Re: Changes to MRTs in 1.9-svn?

Post by amziraro »

So after a bit of fiddling, I got it working. Ent1ty's update branch of irrRenderer was last updated in 2015 or so, but it does use the new video->addRenderTarget() so that saved me a lot of time. The missing link was that there had been changes to setRenderTarget() between svn in 2015 and svn in 2022 (funny how things change over 7 years haha) so I compared the docs for r5075 and r6355 and matched things up as well as I could:

setRenderTarget() in 2015 r5075

Code: Select all

setRenderTarget ( IRenderTarget *  target,
	const core::array< u32 > & activeTextureID,
	bool clearBackBuffer,
	bool clearDepthBuffer,
	bool clearStencilBuffer,
	SColor clearColor = video::SColor(255, 0, 0, 0) 
) 	
vs

setRenderTargetEx() in 2022 r6355

Code: Select all

setRenderTargetEx ( IRenderTarget *  target,
	u16 clearFlag,
	SColor clearColor = SColor(255, 0, 0, 0),
	f32 clearDepth = 1.f,
	u8 clearStencil = 0 
)
I don't know if there's an equivalent to the activeTextureID but as far as I can tell irrRenderer makes all the textures active anyway so I ignored it and it mostly works anyway ¯\_(ツ)_/¯

Its still a bit broken (the soft particle effects and other 2D effects don't work) but it compiles and sort of works so maybe I'll fix that later or maybe not. It can be found as is here: https://github.com/amziraro/irrRenderer/tree/update
CuteAlien
Admin
Posts: 9733
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Changes to MRTs in 1.9-svn?

Post by CuteAlien »

Hm, I suppose it's now meant that are textures set in the rendertarget are enabled. And yeah, rendertarget interface changed a lot since 1.8 (and is actually one of the biggest blockers for 1.9 release).
About soft particles - there also have been changes to alpha-handling (improvements mostly I hope).
One thing to check is if SMaterial::BlendOperation is set to EBO_ADD.

I guess irrRenderer is a good test-case for some of the changed interfaces. I mostly worked with the Irrlicht tests so far. So if you find any problems please report.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
amziraro
Posts: 13
Joined: Fri Jan 22, 2016 2:09 pm
Location: Australia

Re: Changes to MRTs in 1.9-svn?

Post by amziraro »

After some tinkering with the old version of Irrlicht, I can say that the reason irrRenderer's soft particles are messed up is because of me ignoring RenderIndices. When rendering transparency/soft particles irrRenderer wants to make only the first texture of the RenderTarget active (which would just be Diffuse Colour if I understand correctly) but I can't really find a mechanism to do that in current Irrlicht. Am I correct in thinking there's no mechanism to temporarily disable textures in the RenderTarget? I imagine I could make a new RenderTarget with less Textures but I'm pretty sure I'd be doing that twice per frame and that doesn't sound like a great idea :P .

Anyway I'll probably tinker with this some more next weekend.
CuteAlien
Admin
Posts: 9733
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Changes to MRTs in 1.9-svn?

Post by CuteAlien »

I think the idea is - create 2 different rendertargets each with the amount of textures you need. Swap those.
I suspect reason might have been that setting a render target up is expensive while making a setup active is cheap.
So old solution had creating the setup each frame, while you now have it only once.
But I'll put it on my todo to try figure it out (together with the other todo's for rendertarget) if that's really how it is now.
edit: And thinking a bit about it - having a function to enable/disable textures in there still would only have to be called once now.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
CuteAlien
Admin
Posts: 9733
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Changes to MRTs in 1.9-svn?

Post by CuteAlien »

I just looked at the interface changes related to that. Seems Nadro added that in March 1015 and removed it again in October. Commit comment was: Performance gain was too low to keep this parameter available.
Kinda unlucky to have written code for it just in between...

So seems only option is 2 arrays. Thought you shouldn't create those each frame. But once and then just swap the active ones in rendering.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
amziraro
Posts: 13
Joined: Fri Jan 22, 2016 2:09 pm
Location: Australia

Re: Changes to MRTs in 1.9-svn?

Post by amziraro »

Yeah that makes sense, I did tinker with it a bit more and tried something like that but I've fallen off at the moment.
I did notice that there is some sort of memory leak that becomes apparent at higher resolutions (this is in the base irrRenderer too, even without my attempts at updating it) which really killed my motivation to use it in my project. I'll get back to it at some point.
CuteAlien
Admin
Posts: 9733
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Changes to MRTs in 1.9-svn?

Post by CuteAlien »

OK. If you got a short example to reproduce the leak I can also take a look.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply