[2.1] _setPass(...) ignores blendblock [kind of SOLVED]

Problems building or running the engine, queries about how to use features etc.
Post Reply
chaos creator
Gnoblar
Posts: 22
Joined: Tue May 08, 2012 5:56 pm
x 4

[2.1] _setPass(...) ignores blendblock [kind of SOLVED]

Post by chaos creator »

"Solution"
I rendered the GUI via _injectRenderWithPass(...)
This function calls _setPass(...), wich never sets the Blendblock.
so I just added

Code: Select all

const Ogre::HlmsBlendblock *blendblock = mPass->getBlendblock();
mSceneMgr->getDestinationRenderSystem()->_setHlmsBlendblock(blendblock);
which feels very hacky but works.




I was trying to implement ImGUI in Ogre 2.1, and got it nearly to work.

Image

The only part missing is rendering alpha correctly.
If I understood right, the way to do it in 2.1 is setting the blendblock:

Code: Select all

Ogre::HlmsBlendblock blendblock(*mPass->getBlendblock());
blendblock.mSourceBlendFactor = Ogre::SBF_SOURCE_ALPHA;
blendblock.mDestBlendFactor = Ogre::SBF_ONE_MINUS_SOURCE_ALPHA;
blendblock.mSourceBlendFactorAlpha = Ogre::SBF_ONE_MINUS_SOURCE_ALPHA;
blendblock.mDestBlendFactorAlpha = Ogre::SBF_ZERO;
blendblock.mBlendOperation = Ogre::SBO_ADD;
blendblock.mBlendOperationAlpha = Ogre::SBO_ADD;
blendblock.mSeparateBlend = true;
blendblock.mIsTransparent = true;

mPass->setBlendblock(blendblock);
...and after that the GUI gets rendered manually:

Code: Select all

mSceneMgr->_injectRenderWithPass(mPass, renderable, 0, false, false);
wich obviously renders correctly, but ignores the blendblock.
As I stepped through the source code of the rendering process I didn't saw the blendmode getting set anywhere either, but I could just have missed it.
Anyway, RenderDoc also shows the alpha getting written to the frameBuffer, but in the wrong way:

Image
Image

So the question is:
What's the correct way of doing it? Or is it a bug?

(note that I want to render it manually as the Gui Content may be changing every frame)
Last edited by chaos creator on Sun Sep 18, 2016 2:30 pm, edited 1 time in total.
User avatar
devxkh
Halfling
Posts: 84
Joined: Tue Aug 02, 2016 6:07 pm
Location: Germany
x 12

Re: [2.1] _injectRenderWithPass(...) ignores blendblock

Post by devxkh »

I'm using a movableobject for the ingame gui and have no problems with alpha.
But i'm using a material file, no code:

Code: Select all

hlms HlmsUnlit1 unlit
{
	diffuse_map			TestAtlas.png	
	scene_blend			alpha_blend
	depth_check			off
	depth_write			off
}
Maybe you find the helping code in the Ogre deserializer, that's interpreting this 'commands'.

I'm interested in an ImGUI implementation for 2.1, too (didn't had the time till now).
Will you share your's? :)
My little OGRE engine -> FrankE WIP
chaos creator
Gnoblar
Posts: 22
Joined: Tue May 08, 2012 5:56 pm
x 4

Re: [2.1] _injectRenderWithPass(...) ignores blendblock

Post by chaos creator »

Right now it's just the ImGui binding by Crashy (http://www.ogre3d.org/forums/viewtopic.php?f=5&t=89081),
ported to Ogre 2.1 and SDL.

It is using custom shaders and no movable object.
If the alpha problem can be solved easily, the binding is ready to use.
If not, I will try using a movable object, but then I also need to call RenderQueue::addRenderable(...) which really adds unnecessary complexity.

The problem is that ImGUI is, well, an immediate mode GUI, so you have to build the vertex buffer every frame.
I first tried to do it the v2 way but it didn't work out well AND was horribly slow :D

Of course I will share everything ;)
chaos creator
Gnoblar
Posts: 22
Joined: Tue May 08, 2012 5:56 pm
x 4

Re: [2.1] _injectRenderWithPass(...) ignores blendblock

Post by chaos creator »

Now look at that :D

Image

I really tried not to be hacky, but... rendering a movable object the right way seems to be too complicated to do quickly right now.
It would be great if you could enlighten me how you do that.

To the solution of my problem:
The _injectRenderWithPass function has a bunch of stuff commented out, probably the function is outdated.
The blendblock is never set.
So what I did was adding

Code: Select all

const Ogre::HlmsBlendblock *blendblock = mPass->getBlendblock();
mSceneMgr->getDestinationRenderSystem()->_setHlmsBlendblock(blendblock);
right before calling the _injectRenderWithPass.

I'd like to save and restore the old blendblock so it feels less hacky, but there is no function to get the current one, and probably it isn't needed either

Now I'll clean everything up, add scissoring and post the result :)
User avatar
devxkh
Halfling
Posts: 84
Joined: Tue Aug 02, 2016 6:07 pm
Location: Germany
x 12

Re: [2.1] _injectRenderWithPass(...) ignores blendblock

Post by devxkh »

gratz!
I really tried not to be hacky, but... rendering a movable object the right way seems to be too complicated to do quickly right now.
It would be great if you could enlighten me how you do that.
I've already posted my -> implementation
I think you just would have to feed the renderableLayer with the Indexes/vertices from imgui.

I'm not sure if it's the 'right way' since darc_sylinc recommend somewhere to use a listerner. But for me it works and looks clean/simple.
Using just a material file makes it very flexible, too.

Since i would use imgui 'only' for debugging/editing i wouldn't care about it, if it's the best and correct way. As long as it's easy to integrate -_-
My little OGRE engine -> FrankE WIP
chaos creator
Gnoblar
Posts: 22
Joined: Tue May 08, 2012 5:56 pm
x 4

Re: [2.1] _setPass(...) ignores blendblock [kind of SOLVED]

Post by chaos creator »

Thanks!

You're probably right, I left it as it is since it just works.
And it doesn't affect normal rendering as far as I could tell, so maybe it isn't that bad.

The finished version is here -> http://www.ogre3d.org/forums/viewtopic. ... 59#p531059

And for the integrating part... I doubt it could get easier than calling one single function to initialise the manager ;)
Post Reply