Skip to content

alphaTest with fixed mipmap level sample #20522

@Fyrestar

Description

@Fyrestar

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:
alphaTest2

Sampling again with fixed mipmap level:
alphaTest1

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions