Skip to content

Commit

Permalink
WebGPURenderer: Fallback for alphaToCoverage if antialias is disabled (
Browse files Browse the repository at this point in the history
…mrdoob#29395)

* WebGPURenderer: Fallback for alphaToCoverage if antialias is disabled

* handle line node material too
  • Loading branch information
RenaudRohlinger committed Sep 14, 2024
1 parent 5a3fb41 commit c85a437
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
8 changes: 3 additions & 5 deletions src/materials/nodes/InstancedPointsNodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +92,7 @@ class InstancedPointsNodeMaterial extends NodeMaterial {

const len2 = lengthSq( uv().mul( 2 ).sub( 1 ) );

if ( useAlphaToCoverage ) {
if ( useAlphaToCoverage && renderer.samples > 1 ) {

const dlen = float( len2.fwidth() ).toVar();

Expand Down
8 changes: 4 additions & 4 deletions src/materials/nodes/Line2NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() );
Expand All @@ -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 ) );
Expand Down
4 changes: 3 additions & 1 deletion src/materials/nodes/NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,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();
Expand Down
2 changes: 1 addition & 1 deletion src/renderers/webgl-fallback/utils/WebGLState.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/webgpu/utils/WebGPUPipelineUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class WebGPUPipelineUtils {
},
multisample: {
count: sampleCount,
alphaToCoverageEnabled: material.alphaToCoverage
alphaToCoverageEnabled: material.alphaToCoverage && sampleCount > 1
},
layout: device.createPipelineLayout( {
bindGroupLayouts
Expand Down

0 comments on commit c85a437

Please sign in to comment.