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

Nodes: port wide line changes from standard renderer examples #27349 #27474

Merged
merged 1 commit into from
Dec 31, 2023
Merged
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
48 changes: 18 additions & 30 deletions examples/jsm/nodes/materials/Line2NodeMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,50 +133,38 @@ class Line2NodeMaterial extends NodeMaterial {
if ( useWorldUnits ) {

// get the offset direction as perpendicular to the view vector
const worldDir = end.xyz.sub( start.xyz ).normalize();

const offset = positionGeometry.y.lessThan( 0.5 ).cond(
start.xyz.cross( worldDir ).normalize(),
end.xyz.cross( worldDir ).normalize()
const worldDir = end.xyz.sub( start.xyz ).normalize();
const tmpFwd = mix( start.xyz, end.xyz, 0.5 ).normalize();
const worldUp = worldDir.cross( tmpFwd ).normalize();
const worldFwd = worldDir.cross( worldUp );

);
const worldPos = varyingProperty( 'vec4', 'worldPos' );

// sign flip
offset.assign( positionGeometry.x.lessThan( 0.0 ).cond( offset.negate(), offset ) );
worldPos.assign( positionGeometry.y.lessThan( 0.5 ).cond( start, end) );

const forwardOffset = worldDir.dot( vec3( 0.0, 0.0, 1.0 ) );
// height offset
const hw = materialLineWidth.mul( 0.5 );
worldPos.addAssign( vec4( positionGeometry.x.lessThan( 0.0 ).cond( worldUp.mul( hw ), worldUp.mul( hw ).negate() ), 0 ) );

// don't extend the line if we're rendering dashes because we
// won't be rendering the endcaps
if ( ! useDash ) {

// extend the line bounds to encompass endcaps
start.assign( start.sub( vec4( worldDir.mul( materialLineWidth ).mul( 0.5 ), 0 ) ) );
end.assign( end.add( vec4( worldDir.mul( materialLineWidth ).mul( 0.5 ), 0 ) ) );
// cap extension
worldPos.addAssign( vec4( positionGeometry.y.lessThan( 0.5 ).cond( worldDir.mul( hw ).negate(), worldDir.mul( hw ) ), 0 ) );

// shift the position of the quad so it hugs the forward edge of the line
offset.assign( offset.sub( vec3( dir.mul( forwardOffset ), 0 ) ) );
offset.z.assign( offset.z.add( 0.5 ) );

}

// endcaps
// add width to the box
worldPos.addAssign( vec4( worldFwd.mul( hw ), 0 ) );

If( positionGeometry.y.greaterThan( 1.0 ).or( positionGeometry.y.lessThan( 0.0 ) ), () => {
// endcaps
If( positionGeometry.y.greaterThan( 1.0 ).or( positionGeometry.y.lessThan( 0.0 ) ), () => {

offset.assign( offset.add( vec3( dir.mul( 2.0 ).mul( forwardOffset ), 0 ) ) );
worldPos.subAssign( vec4( worldFwd.mul( 2.0 ).mul( hw ), 0 ) );

} );

// adjust for linewidth
offset.assign( offset.mul( materialLineWidth ).mul( 0.5 ) );

// set the world position

const worldPos = varyingProperty( 'vec4', 'worldPos' );
} );

worldPos.assign( positionGeometry.y.lessThan( 0.5 ).cond( start, end ) );
worldPos.assign( worldPos.add( vec4( offset, 0 ) ) );
}

// project the worldpos
clip.assign( cameraProjectionMatrix.mul( worldPos ) );
Expand Down