-
-
Notifications
You must be signed in to change notification settings - Fork 36.1k
Description
When using alphaTest the alpha value from map is used where the corresponding mipmap level has been used, but this causes objects to "dissolve" quickly, leaves of trees for example will disappear quickly and they end up as blank trunks.
By sampling the map for alphaTest with a fixed level this problem disappears/gets reduced enough to prevent this to happen too early. Here are 2 tests, the first using the sample from map and the second using fixed mipmap level.
Using diffuseColor.a from map:

Sampling again with fixed mipmap level:

You see in the first there are barely trunks left while they remain filled in the second, it generally improved finer details that tend to disappear quickly. It also could be implemented optionally as it adds another texture fetch, if MSAA is available the issue is reduced a lot as well. However, otherwise there is dissolving vegetation, hair or other which can get really ugly.
I've been using textureLod here, but bias with texture2D seems to be the same visually. I've temporarily implemented it like this:
#ifdef ALPHATEST
#if defined( USE_MAP ) && __VERSION__ == 300
float alphaTest = textureLod( map, vUv, 0.0 ).a;
if ( alphaTest < ALPHATEST ) discard;
#else
if ( diffuseColor.a < ALPHATEST ) discard;
#endif
#endif
Edit: i changed it to texture and the bias being a parameter, as it works very well with less detailed textures but can turn harshly pixelated close up with very fine detailed textures like hair, this is something that needs to be fine tuned depending on the texture details / mesh size, but for most cases it works well with some general value.