materialAlphaTest
Provides the material's alpha test threshold, a 0-1 float value used in the shader to decide whether to discard (not render) a fragment if its alpha is below this value.
Core Advantages
Completely abstracts the underlying Uniform management and `discard` logic, seamlessly integrating with the `material.alphaTest` property and greatly simplifying the workflow for creating cutout or hard-edged transparency effects.
Common Uses
Rendering vegetation (like leaves and grass) to get sharp silhouettes.
Creating cutout effects like chain-link fences or cloth with holes.
Efficiently rendering irregularly shaped particles.
Debugging alpha channels to visualize the threshold effect.
How to adjust
Modify the `material.alphaTest` property (0-1) in JavaScript. A value of 0 effectively disables the test. As the value increases, more semi-transparent pixels are discarded, causing the visible area of the object to shrink and the "cutout" to become more aggressive.
Code Examples
1// Get the final alpha value, e.g., from a texture
2const finalAlpha = texture( map, uv() ).a;
3
4// If the final alpha is less than the material's alphaTest threshold, discard the fragment
5if ( finalAlpha.lessThan( materialAlphaTest ) ) {
6
7 discard();
8
9}