Blending a transparent material

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
Shem
Halfling
Posts: 55
Joined: Fri Feb 16, 2018 9:32 am
x 8

Blending a transparent material

Post by Shem »

Hi All,

Again, sorry for the noob question. I have a material with a texture which is semi transparent in the center and fully transparent at the edges. I want to blend it with the background so the semi transparent area replaces the background but the fully transparent area shows the background. So for the center I want to use C1*A1 but for the edges C2*A2 (1-src, 2-dst).
A simple replace scene blend will obscure the area behind the fully transparent edges. I'm not sure alpha reject is what I need and in any case I was unable to use it for some reason. Any advice?

Win10 , OGL 3+, v1.10, Quadro K4000

Thanks in advance
Shem
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Blending a transparent material

Post by paroj »

sounds like a simple alpha_blend to me:
https://ogrecave.github.io/ogre/api/1.1 ... _005fblend
Shem
Halfling
Posts: 55
Joined: Fri Feb 16, 2018 9:32 am
x 8

Re: Blending a transparent material

Post by Shem »

Correct me if I'm wrong, but that will not replace the center of the object but blend it with background. I need the center to fully replace everything behind it but I can't change the alpha on the texture and make it opaque.

Thanks
Shem
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Blending a transparent material

Post by paroj »

ah.. missed the part that the center is semi transparent. Yes then alpha_rejection and "scene_blend add" should do what you need.
Shem
Halfling
Posts: 55
Joined: Fri Feb 16, 2018 9:32 am
x 8

Re: Blending a transparent material

Post by Shem »

Excellent! Now, one last thing (I think). It's slightly embarrassing but I can't seem to be able to use alpha rejection.
I tried placing it in the material file like so:

Code: Select all

alpha_rejection less_equal 5
I tried calling it from the code:

Code: Select all

pPass->setAlphaRejectSettings(CMPF_LESS_EQUAL, 5);
I tried turning on alpha test:

Code: Select all

glEnable(GL_ALPHA_TEST);
If I use

Code: Select all

setAlphaToCoverageEnabled(true)
I get strange 'interlacing' artifacts (but at least I know it's doing something!?)

I verified that the alpha value on the texture edge is indeed 0

What am I missing?

Thanks
Shem
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Blending a transparent material

Post by paroj »

try less & greater with a value of 128 - I am not completely sure which way the test is around.. (also always_fail & always_pass)
Shem
Halfling
Posts: 55
Joined: Fri Feb 16, 2018 9:32 am
x 8

Re: Blending a transparent material

Post by Shem »

I have tried all of them. None seem to work. I must be missing something else. I don't know if it's just me but the last few days I keep hitting these walls that shouldn't be there.

Anyway, I have moved to doing this in the fragment shader:

Code: Select all

  if(MyColor.a == 0)
    discard;
Thanks
Shem
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Blending a transparent material

Post by paroj »

if you had a shader attached to that pass the whole time, then it is expected that alpha_rejection did nothing.
It is read by the RTSS which ignores passes that already have shaders.
Shem
Halfling
Posts: 55
Joined: Fri Feb 16, 2018 9:32 am
x 8

Re: Blending a transparent material

Post by Shem »

I did not know that. Interesting. Is everything done on that pass ignored? The blending that I do on it works fine (now that I no longer set it on the clone material).
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: Blending a transparent material

Post by paroj »

not, all - only the ones that have a note like: https://ogrecave.github.io/ogre/api/lat ... our_005fop

that note is currently missing for alpha_rejection though.
Shem
Halfling
Posts: 55
Joined: Fri Feb 16, 2018 9:32 am
x 8

Re: Blending a transparent material

Post by Shem »

Many thanks Pavel. You've been a great help.
Shem
Post Reply