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

Line2NodeMaterial: Add opacityNode support #29964

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from

Conversation

Makio64
Copy link
Contributor

@Makio64 Makio64 commented Nov 25, 2024

Related issue: #29962

Add opacityNode support to line2NodeMaterial

wip : worked almost straightforward but at the intersection of line there is a round corner added
Screenshot 2024-11-25 at 23 13 24

Copy link

github-actions bot commented Nov 25, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 339.14
78.99
339.14
78.99
+0 B
+0 B
WebGPU 483.41
134.17
483.45
134.18
+40 B
+9 B
WebGPU Nodes 482.88
134.07
482.92
134.08
+40 B
+10 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 464.62
111.98
464.62
111.98
+0 B
+0 B
WebGPU 552.54
149.53
552.54
149.53
+0 B
+0 B
WebGPU Nodes 508.42
139.24
508.42
139.24
+0 B
+0 B

@Makio64
Copy link
Contributor Author

Makio64 commented Nov 25, 2024

Screenshot 2024-11-25 at 23 23 47

It looks better but we can still see a point between segmentation

@Makio64
Copy link
Contributor Author

Makio64 commented Nov 25, 2024

I had to modify LineGeometry to fix the fact the segment were over each others..

also updated the demo
Screenshot 2024-11-26 at 01 53 51

@Mugen87 let me know what you think of it, i didn't see bad side effects

@sunag sunag changed the title add opacityNode support to line2NodeMaterial Line2NodeMaterial: Add opacityNode support Nov 25, 2024
@sunag sunag added this to the r171 milestone Nov 25, 2024
@Mugen87
Copy link
Collaborator

Mugen87 commented Nov 25, 2024

Wide line materials do not support alpha because of the resulting artifacts, see #23680.

I'm not familiar enough with the wide line implementation so I hope @WestLangley or @gkjohnson can have a look at this PR.

@WestLangley
Copy link
Collaborator

Please test with wider lines and fewer points so you can see the artifacts. The segmented colors look like a previous issue.

Screenshot 2024-11-25 at 3 12 11 PM

Setting transparent to true, it looks pretty much the same for me. ???
Screenshot 2024-11-25 at 3 18 52 PM

@gkjohnson
Copy link
Collaborator

Setting transparent to true, it looks pretty much the same for me. ???

Without something like a stencil test (see #23680 (comment)) it won't be possible to avoid these artifacts. Even with the pre-depth / stencil test, though, overlapping lines won't display correctly which would be even more noticeable with per-line opacity.

I don't have strong opinions on this other than it won't look right or work "out of the box" in the connected line segments case - this can be useful for users who know how to work around it, though. Separated line segments should look okay, as well. With more control over render order or ability to render an object with two passes in three.js it would be more possible to make a variant of this that "just works" (overlapping aside).

I wonder if something like a compute shader rasterizer or some custom per-segment depth adjustment could help with the artifacts.

Comment on lines 18 to 24
const count = array.length / 3 - 1;
const points = new Float32Array( 6 * count );

const length = array.length - 3;
const points = new Float32Array( 2 * length );
for ( let i = 0; i < count; i ++ ) {

for ( let i = 0; i < length; i += 3 ) {

points[ 2 * i ] = array[ i ];
points[ 2 * i + 1 ] = array[ i + 1 ];
points[ 2 * i + 2 ] = array[ i + 2 ];

points[ 2 * i + 3 ] = array[ i + 3 ];
points[ 2 * i + 4 ] = array[ i + 4 ];
points[ 2 * i + 5 ] = array[ i + 5 ];
points.set( array.slice( 3 * i, 3 * ( i + 1 ) ), 6 * i );
points.set( array.slice( 3 * ( i + 1 ), 3 * ( i + 2 ) ), 6 * i + 3 );
Copy link
Collaborator

@gkjohnson gkjohnson Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to revert these changes to LineGeometry and keep the PR focused on any changes related to material opacity. I find it harder to read and it will be slower and generate more garbage with the unnecessary "slice" calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert to previous synthax

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like there's still a pretty significant diff in the LineGeometry.js file. I don't think it needs to be touched at all for the changes being proposed.

@Makio64
Copy link
Contributor Author

Makio64 commented Nov 26, 2024

@WestLangley I just tested with wider lines and it looks good on my mac m3 see this screenshot :

without alpha
Screenshot 2024-11-26 at 12 19 58

with alpha
Screenshot 2024-11-26 at 12 19 55

You need to apply my changes to the LineGeometry as well to make it works

But the problem is you can't see behind the line ( make sense as its draw as one object ? ) and more complex approach like suggest by @gkjohnson might be necessary for it ? Still I think its a little improvement compare to before and can be used to varius effect like making a line appear using alpha ( simulating line drawing as example ) or adding painting/particles textures to the line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants