Blending a transparent material
-
- Halfling
- Posts: 55
- Joined: Fri Feb 16, 2018 9:32 am
- x 8
Blending a transparent material
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
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
-
- OGRE Team Member
- Posts: 1994
- Joined: Sun Mar 30, 2014 2:51 pm
- x 1074
- Contact:
Re: Blending a transparent material
sounds like a simple alpha_blend to me:
https://ogrecave.github.io/ogre/api/1.1 ... _005fblend
https://ogrecave.github.io/ogre/api/1.1 ... _005fblend
-
- Halfling
- Posts: 55
- Joined: Fri Feb 16, 2018 9:32 am
- x 8
Re: Blending a transparent material
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
Thanks
Shem
-
- OGRE Team Member
- Posts: 1994
- Joined: Sun Mar 30, 2014 2:51 pm
- x 1074
- Contact:
Re: Blending a transparent material
ah.. missed the part that the center is semi transparent. Yes then alpha_rejection and "scene_blend add" should do what you need.
-
- Halfling
- Posts: 55
- Joined: Fri Feb 16, 2018 9:32 am
- x 8
Re: Blending a transparent material
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:
I tried calling it from the code:
I tried turning on alpha test:
If I use 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
I tried placing it in the material file like so:
Code: Select all
alpha_rejection less_equal 5
Code: Select all
pPass->setAlphaRejectSettings(CMPF_LESS_EQUAL, 5);
Code: Select all
glEnable(GL_ALPHA_TEST);
Code: Select all
setAlphaToCoverageEnabled(true)
I verified that the alpha value on the texture edge is indeed 0
What am I missing?
Thanks
Shem
-
- OGRE Team Member
- Posts: 1994
- Joined: Sun Mar 30, 2014 2:51 pm
- x 1074
- Contact:
Re: Blending a transparent material
try less & greater with a value of 128 - I am not completely sure which way the test is around.. (also always_fail & always_pass)
-
- Halfling
- Posts: 55
- Joined: Fri Feb 16, 2018 9:32 am
- x 8
Re: Blending a transparent material
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:
Thanks
Shem
Anyway, I have moved to doing this in the fragment shader:
Code: Select all
if(MyColor.a == 0)
discard;
Shem
-
- OGRE Team Member
- Posts: 1994
- Joined: Sun Mar 30, 2014 2:51 pm
- x 1074
- Contact:
Re: Blending a transparent material
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.
It is read by the RTSS which ignores passes that already have shaders.
-
- Halfling
- Posts: 55
- Joined: Fri Feb 16, 2018 9:32 am
- x 8
Re: Blending a transparent material
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).
-
- OGRE Team Member
- Posts: 1994
- Joined: Sun Mar 30, 2014 2:51 pm
- x 1074
- Contact:
Re: Blending a transparent material
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.
that note is currently missing for alpha_rejection though.
-
- Halfling
- Posts: 55
- Joined: Fri Feb 16, 2018 9:32 am
- x 8
Re: Blending a transparent material
Many thanks Pavel. You've been a great help.
Shem
Shem