+8

Properly Implementing _Cutoff in Alpha Tested shaders

robert briscoe 10 years ago 0
So not long ago _Cutoff was added into SF alpha tested shaders to fix some issues with post processing. The problem is that it isn't really implemented as it should be.

_Cutoff determines the values at which an texture's alpha is considered opaque or transparent, and is kind of useful for tweaking the visual look of alpha tested stuff.

Looking at unity's built-in shaders I haven't been able to determine how exactly _cutoff is used to determine this range, but from my own experimentation, it's something like this:

Image 180

This reproduces the same behaviour as _Cutoff in Unity's built-in shaders as far as I can tell.

I'm not sure how people would feel about this, but perhaps the cutoff calculation should be added (internally) whenever alpha testing is in use? It does add a couple of instructions, but I doubt that's any more than what the default unity shaders are adding.

Also, by just having _Cutoff added but hidden, it seems to cause some issues in selecting objects with alpha tested shaders in the editor. I also noticed that despite creating my own _Cutoff parameter, SF still creates a hidden _Cutoff parameter, which is obviously not desirable. 

Finally, I noticed that after the hidden _Cutoff parameter was removed, I could properly select objects in the viewport again. I think unity uses the value of the alpha mask/cutoff in the view port to determine if an object is selectable, which makes sense really.