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

Line2: Add support for Alpha To Coverage #21451

Merged
merged 9 commits into from
Mar 15, 2021
Merged

Conversation

gkjohnson
Copy link
Collaborator

@gkjohnson gkjohnson commented Mar 12, 2021

Related issue: --

Description

Adds support for alphaToCoverage to Line2. It's a subtle effect but it enables anti aliasing on the rounded tips of the line segments which can be seen on the line ends and when the line is curving in the demo:

https://raw.githack.com/gkjohnson/three.js/atc-line2/examples/webgl_lines_fat.html

cc @WestLangley

@WestLangley
Copy link
Collaborator

Interesting idea: anti-aliasing of the line end-caps. It is very subtle.

I'll defer to @Mugen87 on this one.

@WestLangley
Copy link
Collaborator

Although with very fat (50px) straight lines I see artifacts.

Screen Shot 2021-03-11 at 9 08 23 PM

@gkjohnson
Copy link
Collaborator Author

gkjohnson commented Mar 12, 2021

@WestLangley

It is very subtle.

Heh I've noticed it forever and it's always bugged me and now it can be addressed! It's definitely more noticeable on lower DPI displays and it also helps some jaggedness around curved corners on paths where the end points meet.

Although with very fat (50px) straight lines I see artifacts.

I'm not seeing this on the two machines I'm able to test with but I suspect it's because a derivative was being taken in a conditional the behavior of which probably varies depending on hardware. I've attempted to fix this by defining len2 before the conditional to ensure it's defined. Can you give it a try to see if that fixed it? Should I update the example so you can raise the line thickness to 50px?

A couple other fixes I just pushed:

  • Adjust how the alpha coverage factor is computed.
  • Set shader to use the derivatives extension so WebGL1 is supported.

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 12, 2021

I can see the artifacts, too. The only appear with AtC.

image

This glitch is visible with a 10px wide line and only at the start and end.

@gkjohnson
Copy link
Collaborator Author

I can see the artifacts, too. The only appear with AtC.

Heh uh oh 😅

@Mugen87

What hardware are you using? I'm hoping I can reproduce it somehow otherwise this won't be a fun one to track down.

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 12, 2021

It's an iMac (10.15.7) with a AMD Radeon R9 M295X 4 GB. Chrome version: 89.0.4389.82

@gkjohnson
Copy link
Collaborator Author

I was able to reproduce the issue on a mac laptop and have fixed them (in my case). It seems that on some hardware taking a derivative inside a conditional at all can cause undefined behavior even if the variable is defined outside the condition. I should have fixed it in the last commit -- let me know!

@mrdoob mrdoob added this to the r127 milestone Mar 12, 2021
@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 13, 2021

Looks better now!

@mrdoob mrdoob requested a review from WestLangley March 13, 2021 11:44
Copy link
Collaborator

@WestLangley WestLangley left a comment

Choose a reason for hiding this comment

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

Yep, looks better.

@mrdoob mrdoob merged commit 4ef312e into mrdoob:dev Mar 15, 2021
@mrdoob
Copy link
Owner

mrdoob commented Mar 15, 2021

Thanks!

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.

4 participants