Skip to content

Commit 5fa82c7

Browse files
authored
Line2NodeMaterial: Add opacity support using backdrop (#29979)
* add `opacity` support * cleanup
1 parent 5855564 commit 5fa82c7

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/materials/nodes/Line2NodeMaterial.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ import NodeMaterial from './NodeMaterial.js';
22
import { varyingProperty } from '../../nodes/core/PropertyNode.js';
33
import { attribute } from '../../nodes/core/AttributeNode.js';
44
import { cameraProjectionMatrix } from '../../nodes/accessors/Camera.js';
5-
import { materialColor, materialLineScale, materialLineDashSize, materialLineGapSize, materialLineDashOffset, materialLineWidth } from '../../nodes/accessors/MaterialNode.js';
5+
import { materialColor, materialLineScale, materialLineDashSize, materialLineGapSize, materialLineDashOffset, materialLineWidth, materialOpacity } from '../../nodes/accessors/MaterialNode.js';
66
import { modelViewMatrix } from '../../nodes/accessors/ModelNode.js';
77
import { positionGeometry } from '../../nodes/accessors/Position.js';
88
import { mix, smoothstep } from '../../nodes/math/MathNode.js';
99
import { Fn, float, vec2, vec3, vec4, If } from '../../nodes/tsl/TSLBase.js';
1010
import { uv } from '../../nodes/accessors/UV.js';
1111
import { viewport } from '../../nodes/display/ScreenNode.js';
1212
import { dashSize, gapSize } from '../../nodes/core/PropertyNode.js';
13+
import { viewportSharedTexture } from '../../nodes/display/ViewportSharedTextureNode.js';
1314

1415
import { LineDashedMaterial } from '../LineDashedMaterial.js';
16+
import { NoBlending } from '../../constants.js';
1517

1618
const _defaultValues = /*@__PURE__*/ new LineDashedMaterial();
1719

@@ -46,6 +48,8 @@ class Line2NodeMaterial extends NodeMaterial {
4648
this.dashSizeNode = null;
4749
this.gapSizeNode = null;
4850

51+
this.blending = NoBlending;
52+
4953
this.setValues( params );
5054

5155
}
@@ -267,7 +271,7 @@ class Line2NodeMaterial extends NodeMaterial {
267271

268272
} );
269273

270-
this.fragmentNode = Fn( () => {
274+
this.colorNode = Fn( () => {
271275

272276
const vUv = uv();
273277

@@ -383,6 +387,14 @@ class Line2NodeMaterial extends NodeMaterial {
383387

384388
} )();
385389

390+
if ( this.transparent ) {
391+
392+
const opacityNode = this.opacityNode ? float( this.opacityNode ) : materialOpacity;
393+
394+
this.outputNode = vec4( this.colorNode.rgb.mul( opacityNode ).add( viewportSharedTexture().rgb.mul( opacityNode.oneMinus() ) ), this.colorNode.a );
395+
396+
}
397+
386398
}
387399

388400

0 commit comments

Comments
 (0)