Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebGPURenderer: Fallback for alphaToCoverage if antialias is disabled #29395

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() );

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 @@ -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();
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