Page 1 of 1

Disable alpha testing for transparent materials

Posted: Thu Sep 27, 2018 5:02 pm
by TaaTT4
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).

Re: Disable alpha testing for transparent materials

Posted: Thu Sep 27, 2018 5:57 pm
by dark_sylinc
I do not recall alpha testing being tied to alpha blending. Perhaps there's a bug?

Re: Disable alpha testing for transparent materials

Posted: Thu Sep 27, 2018 6:42 pm
by TaaTT4
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.

Re: Disable alpha testing for transparent materials

Posted: Thu Sep 27, 2018 7:32 pm
by dark_sylinc
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

Re: Disable alpha testing for transparent materials

Posted: Fri Sep 28, 2018 8:59 am
by TaaTT4
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).

Re: Disable alpha testing for transparent materials

Posted: Fri Sep 28, 2018 4:41 pm
by dark_sylinc
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

Re: Disable alpha testing for transparent materials

Posted: Fri Sep 28, 2018 6:32 pm
by TaaTT4
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.

Re: Disable alpha testing for transparent materials

Posted: Fri Sep 28, 2018 7:00 pm
by dark_sylinc
Yeah, that option is less flexible but still OK.