Disable alpha testing for transparent materials

Design / architecture / roadmap discussions related to future of Ogre3D (version 2.0 and above)
Post Reply
User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 139
Joined: Wed Apr 23, 2014 3:49 pm
x 4

Disable alpha testing for transparent materials

Post by TaaTT4 » Thu Sep 27, 2018 5:02 pm

Like the title says, is it possible to disable alpha testing for transparent materials in color buffer rendering?
Imagine to have a vertical plane with a fence texture on it. In this scenario, alpha testing is needed to let the plane be able to cast shadow. At the same time, alpha testing "destroys" how the plane is rendered in the color buffer (the fence tends to disappear at the distance, see here for explanation).
0 x
Senior game programmer at Vae Victis
Working on Racecraft

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3776
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 134
Contact:

Re: Disable alpha testing for transparent materials

Post by dark_sylinc » Thu Sep 27, 2018 5:57 pm

I do not recall alpha testing being tied to alpha blending. Perhaps there's a bug?
0 x

User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 139
Joined: Wed Apr 23, 2014 3:49 pm
x 4

Re: Disable alpha testing for transparent materials

Post by TaaTT4 » Thu Sep 27, 2018 6:42 pm

They're not tied in a strict way, but there's no way to enable alpha testing just for the shadow caster pass. If I activate alpha testing, it acts both on color and shadow caster pass.
What I need is transparency in color pass and alpha testing JUST in shadow caster pass.
0 x
Senior game programmer at Vae Victis
Working on Racecraft

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3776
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 134
Contact:

Re: Disable alpha testing for transparent materials

Post by dark_sylinc » Thu Sep 27, 2018 7:32 pm

Ah! Now I get it. Alpha testing JUST for the caster pass.
Yeah, that would be a feature request. Probably not a hard one to get. Though we're thinking of doing a shader refactor, it may happen after that. I'm not sure.

It's all about introducing a new boolean to indicate this, and a new property
0 x

User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 139
Joined: Wed Apr 23, 2014 3:49 pm
x 4

Re: Disable alpha testing for transparent materials

Post by TaaTT4 » Fri Sep 28, 2018 8:59 am

I am a bit on hurry about this. Do you have an ETA? Otherwise, if you point me out how to properly do it, I can submit a PR. I guess it's a matter of choosing between an additional bool param in alpha_test key vs a totally new key (something like alpha_test_in_shadow_caster_only).
0 x
Senior game programmer at Vae Victis
Working on Racecraft

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3776
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 134
Contact:

Re: Disable alpha testing for transparent materials

Post by dark_sylinc » Fri Sep 28, 2018 4:41 pm

If it's that urgent you'll have to implement it yourself and submit a PR.

I suggest you do a find in files for the following keywords in Samples/Media/Hlms and source/header files:
  • "alpha_test"
  • HlmsBaseProp::AlphaTest
  • mAlphaTestCmp
  • mAlphaTestThreshold
  • setAlphaTest
  • getAlphaTest
  • setAlphaTestThreshold
My recommendation: Split everything in two: AlphaTest Receiver and AlphaTest Caster; while still maintaining the old public functions (e.g. setAlphaTest) to modify both receiver and caster at the same time. Though I suggest to keep the alpha threshold as one for both, since otherwise you'll have trouble shuffling things around in memory to send both values to the GPU buffers.
As for JSON import/export, the old alpha_test keyword affects both, while alpha_test_receiver and alpha_test_caster affects them individually.
You can ignore the Hlms mobile implementations.

Cheers
0 x

User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 139
Joined: Wed Apr 23, 2014 3:49 pm
x 4

Re: Disable alpha testing for transparent materials

Post by TaaTT4 » Fri Sep 28, 2018 6:32 pm

I don't see any real scenario that need different values for the compare function and the alpha threshold between color and shadow caster passes. I don't even see a use case for having alpha testing enabled in color pass, but not in shadow caster pass. For these reasons I thought about a more simpler approach.

In the material JSON declaration:

Code: Select all

"alpha_test" : ["greater", 0.5, true]
where the third boolean parameter is optional and indicates if alpha testing is active just in shadow caster pass or not.

In OgreHlmsDatablock replace

Code: Select all

void setAlphaTest( CompareFunction compareFunction );
with

Code: Select all

void setAlphaTest( CompareFunction compareFunction, bool shadowCasterOnly = false );
This approach is less flexible for sure than duplicating every member and property, but it doesn't break the API and keeps the changes to source code (both in C++ and shaders) at its minimum.
0 x
Senior game programmer at Vae Victis
Working on Racecraft

User avatar
dark_sylinc
OGRE Team Member
OGRE Team Member
Posts: 3776
Joined: Sat Jul 21, 2007 4:55 pm
Location: Buenos Aires, Argentina
x 134
Contact:

Re: Disable alpha testing for transparent materials

Post by dark_sylinc » Fri Sep 28, 2018 7:00 pm

Yeah, that option is less flexible but still OK.
0 x

Post Reply