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
Kobold
Posts: 26
Joined: Fri Feb 16, 2018 9:32 am

Blending a transparent material

Post by Shem » Thu Jul 04, 2019 2:47 pm

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
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 924
Joined: Sun Mar 30, 2014 2:51 pm
x 209
Contact:

Re: Blending a transparent material

Post by paroj » Thu Jul 04, 2019 3:37 pm

sounds like a simple alpha_blend to me:
https://ogrecave.github.io/ogre/api/1.1 ... _005fblend
0 x

Shem
Kobold
Posts: 26
Joined: Fri Feb 16, 2018 9:32 am

Re: Blending a transparent material

Post by Shem » Thu Jul 04, 2019 4:21 pm

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
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 924
Joined: Sun Mar 30, 2014 2:51 pm
x 209
Contact:

Re: Blending a transparent material

Post by paroj » Thu Jul 04, 2019 6:19 pm

ah.. missed the part that the center is semi transparent. Yes then alpha_rejection and "scene_blend add" should do what you need.
1 x

Shem
Kobold
Posts: 26
Joined: Fri Feb 16, 2018 9:32 am

Re: Blending a transparent material

Post by Shem » Thu Jul 04, 2019 7:05 pm

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
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 924
Joined: Sun Mar 30, 2014 2:51 pm
x 209
Contact:

Re: Blending a transparent material

Post by paroj » Fri Jul 05, 2019 1:45 am

try less & greater with a value of 128 - I am not completely sure which way the test is around.. (also always_fail & always_pass)
0 x

Shem
Kobold
Posts: 26
Joined: Fri Feb 16, 2018 9:32 am

Re: Blending a transparent material

Post by Shem » Fri Jul 05, 2019 8:08 am

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
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 924
Joined: Sun Mar 30, 2014 2:51 pm
x 209
Contact:

Re: Blending a transparent material

Post by paroj » Fri Jul 05, 2019 9:25 pm

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.
0 x

Shem
Kobold
Posts: 26
Joined: Fri Feb 16, 2018 9:32 am

Re: Blending a transparent material

Post by Shem » Sat Jul 06, 2019 8:00 am

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).
0 x

paroj
OGRE Team Member
OGRE Team Member
Posts: 924
Joined: Sun Mar 30, 2014 2:51 pm
x 209
Contact:

Re: Blending a transparent material

Post by paroj » Sat Jul 06, 2019 12:15 pm

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.
0 x

Shem
Kobold
Posts: 26
Joined: Fri Feb 16, 2018 9:32 am

Re: Blending a transparent material

Post by Shem » Sat Jul 06, 2019 4:26 pm

Many thanks Pavel. You've been a great help.
Shem
0 x

Post Reply