Page 1 of 1

Blending a transparent material

Posted: Thu Jul 04, 2019 2:47 pm
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

Re: Blending a transparent material

Posted: Thu Jul 04, 2019 3:37 pm
by paroj
sounds like a simple alpha_blend to me:
https://ogrecave.github.io/ogre/api/1.1 ... _005fblend

Re: Blending a transparent material

Posted: Thu Jul 04, 2019 4:21 pm
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

Re: Blending a transparent material

Posted: Thu Jul 04, 2019 6:19 pm
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.

Re: Blending a transparent material

Posted: Thu Jul 04, 2019 7:05 pm
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

Re: Blending a transparent material

Posted: Fri Jul 05, 2019 1:45 am
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)

Re: Blending a transparent material

Posted: Fri Jul 05, 2019 8:08 am
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

Re: Blending a transparent material

Posted: Fri Jul 05, 2019 9:25 pm
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.

Re: Blending a transparent material

Posted: Sat Jul 06, 2019 8:00 am
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).

Re: Blending a transparent material

Posted: Sat Jul 06, 2019 12:15 pm
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.

Re: Blending a transparent material

Posted: Sat Jul 06, 2019 4:26 pm
by Shem
Many thanks Pavel. You've been a great help.
Shem