From 56c5e61cac7d5097799477a7279d408a27d0b059 Mon Sep 17 00:00:00 2001 From: Renaud Rohlinger Date: Thu, 12 Sep 2024 20:15:47 +0900 Subject: [PATCH 1/2] WebGPURenderer: Fallback for alphaToCoverage if antialias is disabled --- src/materials/nodes/InstancedPointsNodeMaterial.js | 8 +++----- src/materials/nodes/NodeMaterial.js | 4 +++- src/renderers/webgl-fallback/utils/WebGLState.js | 2 +- src/renderers/webgpu/utils/WebGPUPipelineUtils.js | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/materials/nodes/InstancedPointsNodeMaterial.js b/src/materials/nodes/InstancedPointsNodeMaterial.js index 0e4a2c2880dc17..a26cca1aa2d17c 100644 --- a/src/materials/nodes/InstancedPointsNodeMaterial.js +++ b/src/materials/nodes/InstancedPointsNodeMaterial.js @@ -39,21 +39,19 @@ class InstancedPointsNodeMaterial extends NodeMaterial { this.setDefaultValues( _defaultValues ); - this.setupShaders(); - this.setValues( params ); } setup( builder ) { - this.setupShaders(); + this.setupShaders( builder ); super.setup( builder ); } - setupShaders() { + setupShaders( { renderer } ) { const useAlphaToCoverage = this.alphaToCoverage; const useColor = this.useColor; @@ -94,7 +92,7 @@ class InstancedPointsNodeMaterial extends NodeMaterial { const len2 = lengthSq( uv() ); - if ( useAlphaToCoverage ) { + if ( useAlphaToCoverage && renderer.samples > 1 ) { const dlen = float( len2.fwidth() ).toVar(); diff --git a/src/materials/nodes/NodeMaterial.js b/src/materials/nodes/NodeMaterial.js index 667c9961c5fdbb..b40565829ecc0d 100644 --- a/src/materials/nodes/NodeMaterial.js +++ b/src/materials/nodes/NodeMaterial.js @@ -183,7 +183,9 @@ class NodeMaterial extends Material { if ( globalClippingCount || localClippingCount ) { - if ( this.alphaToCoverage ) { + const samples = builder.renderer.samples; + + if ( this.alphaToCoverage && samples > 1 ) { // to be added to flow when the color/alpha value has been determined result = clippingAlpha(); diff --git a/src/renderers/webgl-fallback/utils/WebGLState.js b/src/renderers/webgl-fallback/utils/WebGLState.js index 3993a175427558..feedf240c877f5 100644 --- a/src/renderers/webgl-fallback/utils/WebGLState.js +++ b/src/renderers/webgl-fallback/utils/WebGLState.js @@ -512,7 +512,7 @@ class WebGLState { this.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits ); - material.alphaToCoverage === true + material.alphaToCoverage === true && this.backend.renderer.samples > 1 ? this.enable( gl.SAMPLE_ALPHA_TO_COVERAGE ) : this.disable( gl.SAMPLE_ALPHA_TO_COVERAGE ); diff --git a/src/renderers/webgpu/utils/WebGPUPipelineUtils.js b/src/renderers/webgpu/utils/WebGPUPipelineUtils.js index 6c749586b757b4..ef1a78dcfb0f3c 100644 --- a/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +++ b/src/renderers/webgpu/utils/WebGPUPipelineUtils.js @@ -138,7 +138,7 @@ class WebGPUPipelineUtils { }, multisample: { count: sampleCount, - alphaToCoverageEnabled: material.alphaToCoverage + alphaToCoverageEnabled: material.alphaToCoverage && sampleCount > 1 }, layout: device.createPipelineLayout( { bindGroupLayouts From b9e2419960d59718d35eef29322616defb4a7923 Mon Sep 17 00:00:00 2001 From: Renaud Rohlinger Date: Fri, 13 Sep 2024 14:32:53 +0900 Subject: [PATCH 2/2] handle line node material too --- src/materials/nodes/Line2NodeMaterial.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/materials/nodes/Line2NodeMaterial.js b/src/materials/nodes/Line2NodeMaterial.js index 56e3a346b775bc..04e9bee3bb1edb 100644 --- a/src/materials/nodes/Line2NodeMaterial.js +++ b/src/materials/nodes/Line2NodeMaterial.js @@ -52,13 +52,13 @@ class Line2NodeMaterial extends NodeMaterial { setup( builder ) { - this.setupShaders(); + this.setupShaders( builder ); super.setup( builder ); } - setupShaders() { + setupShaders( { renderer } ) { const useAlphaToCoverage = this.alphaToCoverage; const useColor = this.useColor; @@ -299,7 +299,7 @@ class Line2NodeMaterial extends NodeMaterial { if ( ! useDash ) { - if ( useAlphaToCoverage ) { + if ( useAlphaToCoverage && renderer.samples > 1 ) { const dnorm = norm.fwidth(); alpha.assign( smoothstep( dnorm.negate().add( 0.5 ), dnorm.add( 0.5 ), norm ).oneMinus() ); @@ -316,7 +316,7 @@ class Line2NodeMaterial extends NodeMaterial { // round endcaps - if ( useAlphaToCoverage ) { + if ( useAlphaToCoverage && renderer.samples > 1 ) { const a = vUv.x; const b = vUv.y.greaterThan( 0.0 ).select( vUv.y.sub( 1.0 ), vUv.y.add( 1.0 ) );