diff --git a/src/materials/Material.js b/src/materials/Material.js index 3e8a4539f8797aaeabd44a1be01f1e9ddc17d754..4869192811aaaa6e7ba482058f2f1f619f7a32a8 100644 --- a/src/materials/Material.js +++ b/src/materials/Material.js @@ -62,7 +62,7 @@ class Material extends EventDispatcher { this.dithering = false; - this.alphaTest = 0; + this.alphaTest = null; this.alphaToCoverage = false; this.premultipliedAlpha = false; @@ -308,7 +308,7 @@ class Material extends EventDispatcher { if ( this.dithering === true ) data.dithering = true; - if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest; + if ( this.alphaTest !== null ) data.alphaTest = this.alphaTest; if ( this.alphaToCoverage === true ) data.alphaToCoverage = this.alphaToCoverage; if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha; diff --git a/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js b/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js index 0fc5629651456aa530105f85c84943508a093a73..5f971d95be80cdd915ae8c9bece5badfb316d06f 100644 --- a/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js +++ b/src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl.js @@ -1,5 +1,7 @@ export default /* glsl */` +#ifdef USE_ALPHATEST if ( diffuseColor.a < alphaTest ) discard; +#endif `; diff --git a/src/renderers/shaders/ShaderChunk/alphatest_pars_fragment.glsl.js b/src/renderers/shaders/ShaderChunk/alphatest_pars_fragment.glsl.js index a744487b0ac59f3cc5e064221c5009850940798c..d7cc59722a40ed6c9e94d8eff16123479856fbfc 100644 --- a/src/renderers/shaders/ShaderChunk/alphatest_pars_fragment.glsl.js +++ b/src/renderers/shaders/ShaderChunk/alphatest_pars_fragment.glsl.js @@ -1,5 +1,7 @@ export default /* glsl */` +#ifdef USE_ALPHATEST uniform float alphaTest; +#endif `; diff --git a/src/renderers/webgl/WebGLMaterials.js b/src/renderers/webgl/WebGLMaterials.js index ee266adcbbb7b29c2ca1764d730144700921eae4..4bc147acec1949b487d49173de117b0a98b0d991 100644 --- a/src/renderers/webgl/WebGLMaterials.js +++ b/src/renderers/webgl/WebGLMaterials.js @@ -107,7 +107,6 @@ function WebGLMaterials( properties ) { function refreshUniformsCommon( uniforms, material ) { - uniforms.alphaTest.value = material.alphaTest; uniforms.opacity.value = material.opacity; if ( material.color ) { @@ -134,6 +133,12 @@ function WebGLMaterials( properties ) { } + if ( material.alphaTest !== null ) { + + uniforms.alphaTest.value = material.alphaTest; + + } + if ( material.specularMap ) { uniforms.specularMap.value = material.specularMap; diff --git a/src/renderers/webgl/WebGLProgram.js b/src/renderers/webgl/WebGLProgram.js index b3abd5787028051b0ddbfcbcb2ae177311bc3df8..82d6721197785eab89b8ad31699abdcd3a86a4b4 100644 --- a/src/renderers/webgl/WebGLProgram.js +++ b/src/renderers/webgl/WebGLProgram.js @@ -607,6 +607,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) { parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '', parameters.metalnessMap ? '#define USE_METALNESSMAP' : '', parameters.alphaMap ? '#define USE_ALPHAMAP' : '', + parameters.alphaTest ? '#define USE_ALPHATEST' : '', parameters.sheen ? '#define USE_SHEEN' : '', parameters.transmission ? '#define USE_TRANSMISSION' : '', diff --git a/src/renderers/webgl/WebGLPrograms.js b/src/renderers/webgl/WebGLPrograms.js index 62547b236e9dcb20115ad84385403e3e1e1e292d..235f432098d5b8df2639835b8e57af45d825e6a7 100644 --- a/src/renderers/webgl/WebGLPrograms.js +++ b/src/renderers/webgl/WebGLPrograms.js @@ -38,7 +38,7 @@ function WebGLPrograms( renderer, cubemaps, extensions, capabilities, bindingSta 'map', 'mapEncoding', 'matcap', 'matcapEncoding', 'envMap', 'envMapMode', 'envMapEncoding', 'envMapCubeUV', 'lightMap', 'lightMapEncoding', 'aoMap', 'emissiveMap', 'emissiveMapEncoding', 'bumpMap', 'normalMap', 'objectSpaceNormalMap', 'tangentSpaceNormalMap', 'clearcoatMap', 'clearcoatRoughnessMap', 'clearcoatNormalMap', 'displacementMap', 'specularMap', 'roughnessMap', 'metalnessMap', 'gradientMap', - 'alphaMap', 'combine', 'vertexColors', 'vertexAlphas', 'vertexTangents', 'vertexUvs', 'uvsVertexOnly', 'fog', 'useFog', 'fogExp2', + 'alphaMap', 'alphaTest', 'combine', 'vertexColors', 'vertexAlphas', 'vertexTangents', 'vertexUvs', 'uvsVertexOnly', 'fog', 'useFog', 'fogExp2', 'flatShading', 'sizeAttenuation', 'logarithmicDepthBuffer', 'skinning', 'maxBones', 'useVertexTexture', 'morphTargets', 'morphNormals', 'premultipliedAlpha', 'numDirLights', 'numPointLights', 'numSpotLights', 'numHemiLights', 'numRectAreaLights', @@ -197,6 +197,7 @@ function WebGLPrograms( renderer, cubemaps, extensions, capabilities, bindingSta metalnessMap: !! material.metalnessMap, specularMap: !! material.specularMap, alphaMap: !! material.alphaMap, + aphaTest: material.alphaTest !== null, gradientMap: !! material.gradientMap,