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

Grid object #743

Merged
merged 27 commits into from
May 28, 2024
Merged

Grid object #743

merged 27 commits into from
May 28, 2024

Conversation

almarklein
Copy link
Member

@almarklein almarklein commented Apr 25, 2024

Addresses one point in #739.

Techniques

I'm looking (until now) at two approaches:

I'm comparing these and will likely combine the best of both ... wip.

Notes

  • Grid range:
    • Sometimes you want a grid with a specific range. Sometimes infinite.
    • This is more a matter of doing the right tricks in the vertex shader. Does not (really) matter for the grid-drawing.
  • Line width:
    • Can be in screen coords, world coords.
    • The Prestine grid mimics a texture grid, and is in world coords, but flat in the plane (not bill-boarded).
    • Can probably take code from line rendering to make it do whatever we want.
  • Major and minor ticks:
    • Must be done in one shader; drawing two grids does not blend well.
    • The Nico-grid does this. Can probably make this work for Prestine grid.
  • Performance:
    • Do a small benchmark to see if one is significantly slower.
  • AA:
    • super in both.
  • Distance fading and suppression of Moiré artifacts:
    • Very good in the Prestine-grid. Not sure yet for the Nico-grid.

Use-cases / scope

Focusing on grids for axes in this PR. Will also consider log, polar and map projections, to at least know how it will fit in.

Other use-cases (for later):

  • Draw a surface (height map) and have planar grid lines or isosurface lines drawn on top.
  • Draw gridlines over a mesh, the texcoords specify the grid space. Maybe a MeshGridMaterial.
  • Render checkerboard instead of a grid.

Early result of the prestine grid:

image

@Korijn
Copy link
Collaborator

Korijn commented Apr 25, 2024

  • Major and minor ticks:

    • Must be done in one shader; drawing two grids does not blend well.
    • The Nico-grid does this. Can probably make this work for Prestine grid.

The prestine grid has this feature all the way at the bottom of the article, including a link to shader source:

image

@almarklein
Copy link
Member Author

Also easy to make prestine grid use screen-space line width.

@kushalkolar
Copy link
Contributor

That is indeed a very nice grid with minimal moire 😮

@almarklein
Copy link
Member Author

almarklein commented May 16, 2024

Almost done! Only Cartesian grids for now. Want to look at log/polar/maps later.

image

One remaining problem is that the inf grid looks rather odd on LavaPipe ... 🤔

image

@almarklein almarklein marked this pull request as ready for review May 16, 2024 08:50
@almarklein almarklein requested a review from Korijn as a code owner May 16, 2024 08:50
@Korijn
Copy link
Collaborator

Korijn commented May 19, 2024

Is the default orientation the same as a plane geometry? :)

@almarklein
Copy link
Member Author

Is the default orientation the same as a plane geometry? :)

No, it's not. The default plane orientation is xy. I opted for a default xz because that way it can function as a floor in most our examples. I can change the default to match xy. We can force the user to specify the orientation, leaving less room for surprises.

@Korijn
Copy link
Collaborator

Korijn commented May 21, 2024

image

Something that stands out to me is that the infinite grid does not actually reach out to the horizon :) I think I can see its borders and a corner

@kushalkolar
Copy link
Contributor

Something that stands out to me is that the infinite grid does not actually reach out to the horizon :) I think I can see its borders and a corner

I was wondering this too, is it the camera clipping planes along depth?

@almarklein
Copy link
Member Author

the infinite grid does not actually reach out to the horizon :)

That's because it's not actually infinite, but scaled and positioned to appear infinite. If I scale the grid too much, the grid coords become unstable. But I'll have a look to see if I can crack it up a bit.

@Korijn
Copy link
Collaborator

Korijn commented May 22, 2024

So how does the prestine grid shader article achieve this effect then?

@almarklein
Copy link
Member Author

Updates:

  • The horizon is much better now. The vertex shader now creates a square consisting of a small inner quad and a (much) larger outer region. That way we have accuracy nearby, and massive range for a proper horizon.
  • Changed the grid's orientation to be in xy-plane if its not rotated. The orientation argument is mandatory.
  • The glitched screenshot I posted earlier applied to Vulkan (not just Lavapipe). It was due to how the uv for axis-lines was clamped, Fixed.
  • Also saw how the grid looked bad for large step sizes. Turned out the math was not correct. Fixed that too.

@almarklein
Copy link
Member Author

Ready from my end.

image

@Korijn Korijn merged commit b0ded77 into main May 28, 2024
12 checks passed
@Korijn Korijn deleted the grid branch May 28, 2024 12:30
@kushalkolar
Copy link
Contributor

Just played with it, it works really well! 🥳

@almarklein
Copy link
Member Author

Yeah, I'm really happy with the end result. The prestine grid is amazing! And mixing it with a few ideas from Nicolas (most notable handling edges of non-finite grids) makes it more generally useful.

@kushalkolar
Copy link
Contributor

10 million points and zooming along the grid 😆

https://www.youtube.com/watch?v=7pv0zurv7x0

@almarklein almarklein mentioned this pull request Jul 9, 2024
7 tasks
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.

3 participants