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

Draw lines and points using triangles #8276

Closed
unknownbrackets opened this issue Dec 19, 2015 · 17 comments
Closed

Draw lines and points using triangles #8276

unknownbrackets opened this issue Dec 19, 2015 · 17 comments
Milestone

Comments

@unknownbrackets
Copy link
Collaborator

unknownbrackets commented Dec 19, 2015

Some games use lines and points (not a ton.) At higher resolutions than 1x, these draw incorrectly, especially on mobile.

We currently use glLineWidth and glPointSize to emulate these on desktop. However, glLineWidth is deprecated - it won't work in Core Profile (Mac) and is unsupported in GLES. Further, lines still draw incorrectly even with this - especially at non-even resolutions.

See #8270 for more discussion on how to technically construct lines/points using polygons. Ideally some testing on how these work in transform mode (especially width) might make sense.

This would fix #3871 and #3332.

As noted in #3332, line caps can be a concern.

-[Unknown]

@unknownbrackets
Copy link
Collaborator Author

I think even GLES 3.1 doesn't include support for geometry shaders, so one way or another we need a solution that doesn't require them. At that point the question is - do we build two solutions to this problem, or just one?

-[Unknown]

@ADormant
Copy link

ADormant commented Jan 4, 2016

Though OpenGL ES 3.2 does have geometry shaders.

@hrydgard
Copy link
Owner

hrydgard commented Jan 4, 2016

That's true, but hardly any devices support ES 3.2 yet, there will be devices with ES 3.1 or lower around for the foreseeable future so we still need a non-geometry shader solution.

@ADormant
Copy link

What about this simias/rustation@f6514ed

@unknownbrackets
Copy link
Collaborator Author

Not really, that seems to be doing what we currently do: using glLineWidth or something, which is unsupported on GLES. It also seems to be inaccurate for our needs. Also it's written in Rust.

-[Unknown]

@hrydgard
Copy link
Owner

hrydgard commented Nov 20, 2017

We already sort-of do this for RECT primitives, it would not be very hard to add triangulation of points and lines, a nice little project.

Geometry shaders are probably not worth it as they are (almost) only available on PC, which will easily be fast enough for software triangulation anyway.

@hrydgard hrydgard added this to the v1.6.0 milestone Nov 20, 2017
@hrydgard
Copy link
Owner

hrydgard commented Mar 12, 2018

Geometry shaders are starting to show up on mobile devices using Vulkan (for example, my Galaxy S8 has them after upgrading to Android 8.0 Oreo) but still, we probably shouldn't use them for this, instead we'll just do the same we do with rectangles - transform them in software and split into triangles, as discussed.

@unknownbrackets , you had some WIP code for this, right? You removed it from #8270 , and now I can't find it.

@unknownbrackets
Copy link
Collaborator Author

Oh, sorry, yes. It's not doing many things, I was just trying to get it to draw the lines in Ridge Racer (#8509) as a test but didn't account for diagonal lines (perpendicular unit vector for width, I guess?), or more importantly transform (could possibly just multiply to get the perpendicular unit vector?)

Pushed it here after a quick rebase:
master...unknownbrackets:lines

But the speedometer wasn't working iirc and I forgot about it...

-[Unknown]

@hrydgard
Copy link
Owner

Thanks.

Getting a perpendicular vector is very easy: rotate90(x, y) = (-y, x). So not much complicated math needed really.

@unknownbrackets
Copy link
Collaborator Author

Right, but wasn't so sure about transform (since we want to do that in screen coordinates - which software transform doesn't do.) I think you'd suggested just transforming the entire line into through, which I haven't really thought through.

-[Unknown]

@hrydgard
Copy link
Owner

hrydgard commented Mar 17, 2018

Well we already do it with rectangles. We put the two points defining them through software transform and out they come in screen space, at which point we expand them in 2D. Same would go for lines and points.

EDIT: Never mind, it's not that easy - the space we expand rectangles in is before projection and that's inappropriate for the scaling of lines and points.

@Panderner
Copy link
Contributor

Panderner commented Nov 19, 2021

Hi there But how about Test Drive Unlimited minimaps lines?

Latest Build:
Screenshot (49)

Stable 1.12.3:
Screenshot (50)

Vulkan 1.12.3:
Screenshot (51)

Here's a GE dump:
recording.zip

@unknownbrackets
Copy link
Collaborator Author

I tried this frame dump on a PSP, but there's some post-processing at the end which seems to be pulling from a previously renderered frame, and so it's hard to compare. Just noting for later.

-[Unknown]

@Panderner
Copy link
Contributor

Drawing Lines using triangles is a bad idea for Echochrome and Test Drive Unlimited Mini-map, see (#15556)

@hrydgard
Copy link
Owner

hrydgard commented May 27, 2022

Nah, it's a good idea, just seems like there's some bug to fix in the implementation. But thanks for tracking it down.

@unknownbrackets unknownbrackets modified the milestones: Future, v1.13.0 Jul 25, 2022
@unknownbrackets
Copy link
Collaborator Author

Points and lines are drawn using triangles now. There's still some things that could be improved, but there are already other issues open for them. I'm going to close this.

-[Unknown]

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

No branches or pull requests

4 participants