Skip to content

Commit

Permalink
Line2NodeMaterial: Add opacity support using backdrop (#29979)
Browse files Browse the repository at this point in the history
* add `opacity` support

* cleanup
  • Loading branch information
sunag authored Nov 27, 2024
1 parent 5855564 commit 5fa82c7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/materials/nodes/Line2NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import NodeMaterial from './NodeMaterial.js';
import { varyingProperty } from '../../nodes/core/PropertyNode.js';
import { attribute } from '../../nodes/core/AttributeNode.js';
import { cameraProjectionMatrix } from '../../nodes/accessors/Camera.js';
import { materialColor, materialLineScale, materialLineDashSize, materialLineGapSize, materialLineDashOffset, materialLineWidth } from '../../nodes/accessors/MaterialNode.js';
import { materialColor, materialLineScale, materialLineDashSize, materialLineGapSize, materialLineDashOffset, materialLineWidth, materialOpacity } from '../../nodes/accessors/MaterialNode.js';
import { modelViewMatrix } from '../../nodes/accessors/ModelNode.js';
import { positionGeometry } from '../../nodes/accessors/Position.js';
import { mix, smoothstep } from '../../nodes/math/MathNode.js';
import { Fn, float, vec2, vec3, vec4, If } from '../../nodes/tsl/TSLBase.js';
import { uv } from '../../nodes/accessors/UV.js';
import { viewport } from '../../nodes/display/ScreenNode.js';
import { dashSize, gapSize } from '../../nodes/core/PropertyNode.js';
import { viewportSharedTexture } from '../../nodes/display/ViewportSharedTextureNode.js';

import { LineDashedMaterial } from '../LineDashedMaterial.js';
import { NoBlending } from '../../constants.js';

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

Expand Down Expand Up @@ -46,6 +48,8 @@ class Line2NodeMaterial extends NodeMaterial {
this.dashSizeNode = null;
this.gapSizeNode = null;

this.blending = NoBlending;

this.setValues( params );

}
Expand Down Expand Up @@ -267,7 +271,7 @@ class Line2NodeMaterial extends NodeMaterial {

} );

this.fragmentNode = Fn( () => {
this.colorNode = Fn( () => {

const vUv = uv();

Expand Down Expand Up @@ -383,6 +387,14 @@ class Line2NodeMaterial extends NodeMaterial {

} )();

if ( this.transparent ) {

const opacityNode = this.opacityNode ? float( this.opacityNode ) : materialOpacity;

this.outputNode = vec4( this.colorNode.rgb.mul( opacityNode ).add( viewportSharedTexture().rgb.mul( opacityNode.oneMinus() ) ), this.colorNode.a );

}

}


Expand Down

0 comments on commit 5fa82c7

Please sign in to comment.