Material not updating properly when using setAlphaOperation

Problems building or running the engine, queries about how to use features etc.
Post Reply
fd9_
Halfling
Posts: 64
Joined: Wed Aug 20, 2008 9:20 pm
x 22

Material not updating properly when using setAlphaOperation

Post by fd9_ »

I have an overlay with a plain white texture that I'm using to achieve a fade-in/fade-out effect. I am using setAlphaOperation() to change the alpha value of the texture at run time:

Code: Select all

panel->getMaterial()->getTechnique(0)->getPass(0)->getTextureUnitState(0)->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_MANUAL, Ogre::LBS_TEXTURE, myAlpha);
The odd thing about this problem is that it appears to work correctly the first time, but when I use it to change the alpha value over time, it has no effect. In other words, it only works the first time I use the function. I tried calling load() and _notifyNeedsRecompile() on the material each time I change the alpha value but to no avail. I am running Ogre 1.9 on iOS. (By the way, I also tried using Rectangle2D instead of overlays which didn't help either).
fd9_
Halfling
Posts: 64
Joined: Wed Aug 20, 2008 9:20 pm
x 22

Re: Material not updating properly when using setAlphaOperat

Post by fd9_ »

I'm bumping this thread because I'm out of ideas on what to do.
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Material not updating properly when using setAlphaOperat

Post by c6burns »

What's probably happening is that you are using RTSS and you are modifying the original technique, but RTSS has generated a new shader based technique which is the one being used. The easiest thing might be to invalidate the material every time you change the alpha (but easiest is often not best for performance). This is how you would go about it in your case:

Code: Select all

Ogre::RTShader::ShaderGenerator::getSingleton().invalidateMaterial(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, panel->getMaterial()->getName());
fd9_
Halfling
Posts: 64
Joined: Wed Aug 20, 2008 9:20 pm
x 22

Re: Material not updating properly when using setAlphaOperat

Post by fd9_ »

c6burns wrote:What's probably happening is that you are using RTSS and you are modifying the original technique, but RTSS has generated a new shader based technique which is the one being used. The easiest thing might be to invalidate the material every time you change the alpha (but easiest is often not best for performance). This is how you would go about it in your case:

Code: Select all

Ogre::RTShader::ShaderGenerator::getSingleton().invalidateMaterial(Ogre::RTShader::ShaderGenerator::DEFAULT_SCHEME_NAME, panel->getMaterial()->getName());
That does seem to "fix" the problem, however it's way too slow to invalidate each frame. Is there any other solution? I am using the iOS template, which uses RTSS by default. I tried disabling it, but all I get is a blank white screen (no console errors/crashes), so I assume that some part of the code must rely on it...
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Material not updating properly when using setAlphaOperat

Post by c6burns »

You can try doing the operation on technique 1 (which will be the RTSS generated technique if your original material only had 1 technique) instead of 0 ... not sure if that actually works. If not you might be able to tune the transparency by changing it directly in the diffuse color. It depends on how the RTSS shader is set up, which I honestly don't know as I use my own shaders.
fd9_
Halfling
Posts: 64
Joined: Wed Aug 20, 2008 9:20 pm
x 22

Re: Material not updating properly when using setAlphaOperat

Post by fd9_ »

Do you happen to know if RTSS is required for my application if I'm using GLES2? I am not really using it, and I'd rather not have it enabled... but it breaks my application when I tried to remove it (nothing except the viewport background color is displayed).
User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 5296
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 1278
Contact:

Re: Material not updating properly when using setAlphaOperat

Post by dark_sylinc »

Why do you need to invalidate every frame? Alpha operations should rarely need change, less alone once per frame.

Changing the material properties every frame is a bad idea no matter the system being used. What you could do is to clone the material and have two (or more) materials each with the setting you need, and swap the material. That should be fast.

But again, what is it that you're doing that requires such change frequency?
fd9_ wrote:Do you happen to know if RTSS is required for my application if I'm using GLES2? I am not really using it, and I'd rather not have it enabled... but it breaks my application when I tried to remove it (nothing except the viewport background color is displayed).
RTSS emulates the fixed function pipeline (FFP for short); as long as your materials don't use custom shaders; you're going to need it since GLES2 doesn't support the FFP, as it is a shader-only API.
In Ogre 2.0 the Hlms system will be used instead which prevents things like "you need to tell the RTSS you changed the material"; but it's a work in progress at the time of writing.
Even then, your problem (slowdown per frame) is not specific to the RTSS.
User avatar
c6burns
Beholder
Posts: 1512
Joined: Fri Feb 22, 2013 4:44 am
Location: Deep behind enemy lines
x 138

Re: Material not updating properly when using setAlphaOperat

Post by c6burns »

The problem is the user is fading in/out an overlay. So either they need to adjust material properties every frame, or write a custom shader. My impression is that they didn't have the ability (at least at this point) to write a custom shader. Changing the material properties each frame is not *that* bad ... it's a league above invalidating the RTSS technique every frame. I mainly wanted them to try that to confirm their issue.
fd9_
Halfling
Posts: 64
Joined: Wed Aug 20, 2008 9:20 pm
x 22

Re: Material not updating properly when using setAlphaOperat

Post by fd9_ »

Alright guys, thanks for the information.
Post Reply