Sunday, May 5, 2024
HomeGame Developmentunity - Using ShaderGraph for UI elements with transparency

unity – Using ShaderGraph for UI elements with transparency


Or alpha test.

There are some builtin shaders that do this, but the general idea is to check the alpha value of the texture (which goes from 0% to 100% from one side to the other) and compare that value with a float property (driven by your player’s HP). If it’s less, output 0. If it’s more, output 1.

It tends to leave a jagged edge, though, which is one of the reasons I created these shaders a number of years ago. It treats that boundary a little more fuzzily so that any imperfections in the texture are blurred out, as well as allowing for edges that aren’t completely hard. I tend to get the best results with a blend value of about 0.02; small enough that some blurring occurs, but not so strongly that the data precision (i.e. the readability of the graphic) is lost. $2 asset is $2 because that’s the lowest non-free price and anyone with understanding of HSLS can create the included shaders themselves in about an hour.

I’m not sure how ShaderGraph would handle this, if there’s already a builtin function for it (I’d be surprised if there wasn’t), but creating it manually with a few nodes should be easy enough now that you know what the process is.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments