Disable alpha testing for transparent materials

Discussion area about developing with Ogre-Next (2.1, 2.2 and beyond)


Post Reply
User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 267
Joined: Wed Apr 23, 2014 3:49 pm
Location: Bologna, Italy
x 75
Contact:

Disable alpha testing for transparent materials

Post 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).

Senior programmer at 505 Games; former senior engine programmer at Sandbox Games
Worked on: Racecraft EsportRacecraft Coin-Op, Victory: The Age of Racing

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

Re: Disable alpha testing for transparent materials

Post by dark_sylinc »

I do not recall alpha testing being tied to alpha blending. Perhaps there's a bug?
User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 267
Joined: Wed Apr 23, 2014 3:49 pm
Location: Bologna, Italy
x 75
Contact:

Re: Disable alpha testing for transparent materials

Post 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.

Senior programmer at 505 Games; former senior engine programmer at Sandbox Games
Worked on: Racecraft EsportRacecraft Coin-Op, Victory: The Age of Racing

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

Re: Disable alpha testing for transparent materials

Post 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
User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 267
Joined: Wed Apr 23, 2014 3:49 pm
Location: Bologna, Italy
x 75
Contact:

Re: Disable alpha testing for transparent materials

Post 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).

Senior programmer at 505 Games; former senior engine programmer at Sandbox Games
Worked on: Racecraft EsportRacecraft Coin-Op, Victory: The Age of Racing

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

Re: Disable alpha testing for transparent materials

Post 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
User avatar
TaaTT4
OGRE Contributor
OGRE Contributor
Posts: 267
Joined: Wed Apr 23, 2014 3:49 pm
Location: Bologna, Italy
x 75
Contact:

Re: Disable alpha testing for transparent materials

Post 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.

Senior programmer at 505 Games; former senior engine programmer at Sandbox Games
Worked on: Racecraft EsportRacecraft Coin-Op, Victory: The Age of Racing

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

Re: Disable alpha testing for transparent materials

Post by dark_sylinc »

Yeah, that option is less flexible but still OK.
Post Reply