Greased line visual glitch at large scale

Hey there,

I am making large scale orbit meshes and I want to use greased lines as thick lines are really cool :ok_hand:

I am having some artifacts when making the orbits very large:

And this does not happen with regular lines (toggle L49 in the following PG for comparison):

Is it a fundamental limitation of greased lines or am I missing some tricks to make it work?

Pinging @roland as you are the greased line lord around here ^^

1 Like

cc @roland

1 Like

I think it’s a floating point precision issue as the orbital ranges you have vary from 0.0001 to 100000, which would cause rendering glitches scene wide. It probably explains why planets aren’t showing at those scales either, but when 100000 is changed to 1000 everything works (planets and greased line orbits). I see now the planet positions exceed camera.maxZ so that’s why they don’t show at those extreme ranges, but I still think you’re hitting a hardware floating point precision limit.

You might need to consider scaling everything down and/or implementing floating origin and/or breaking geometry up into tiles.

Thanks for investigating! I am making a 1:1 scale space game so those precision issues are often a challenge ^^ What I don’t get is why the simple lines work while the greased lines are glitchy: I would expect the lines to have the same issues.

Even if the scale is large, space is mostly empty so z-fighting is not an issue for the orbit lines, so I still have hope!

This PG already has the camera at the origin so floating origin will not improve the precision further unfortunately :confused: Breaking the geometry into tiles might be the solution if I can’t fix greased lines yes

Just guessing but greased lines use triangles whereas lineset does not, but I get your point.

1 Like

Hello! Thanks :smiley:

Guys, sorry for the late reply I’m quite busy these days…

So, @inteja is absolutely right. It’s all about loosing the correct vertex positions due to precision loss in the vertex shader. float32s has only 23 bits mantisa so every value beyond 10^7 gets only 1 unit precision at the end.

The solution would be the floating origin approach proposed by @inteja and if I can recall it correctly, you already posted some question about this technique.

The problem is the vertex positions are too far from the camera origin. You could rescale the positions and/or use a separate dybamically positioned camera for the orbit lines.

Surely it will introduce complexity to your code but unfortunately I can’t come up with any other solution.

Thanks for the answer ^^

Yeah I was afraid you would say that :confused: Looks like the thin lines work fine only because the float imprecision is not as visible.

However, it worked in the past: Fix #140 by BarthPaleologue Ā· Pull Request #147 Ā· BarthPaleologue/CosmosJourneyer Ā· GitHub (see the screenshot in the PR), so there must be more than a precision issue :thinking:

I used Babylon 7.21.4 at the time so there might have been a regression since then. I will try to narrow the version range a bit so it’s more useful :wink:

Unfortunately that’s not really possible if I am making a 1:1 scale solar system, the camera might be around some planet and should still be able to see the orbit lines of planets far away.

For now, I will keep things simple and stick to thin lines

So I have been doing some git bisect and narrowed the version regression range.

This dep upgrade broke the greased line for me: upgrade deps Ā· BarthPaleologue/CosmosJourneyer@8c42d47 Ā· GitHub

So there must have been something between 7.49.0 and 7.54.3

Here is a PG that proves that it worked in 7.49.0: https://playground.babylonjs.com/?version=7.49.0#6HWY5R#8 @roland

2 Likes

The issue was introduced here:

It fixed the issue with rendering lines really close to the camera. Unfortunately, it also unleashed the bug you sensed in the Force. :disappointed_face: Sorry about that, my fellow Jedi.

I’ll be off on a brief retreat to a distant system for the next 10 days, but once I return, I’ll face this bug head-on and bring balance to the PR.

Your vigilance has not gone unnoticed, thank you for reporting this disturbance in the codebase. The Dark Side respects such keen observation!

:smiling_face_with_sunglasses:

5 Likes

Ah I can see how it’s not easy to have both at the same time, maybe we need to turn to the dark side ^^

Take care :wink: it’s not urgent

2 Likes

Fix on the way:

4 Likes

Merged :slight_smile:

2 Likes

Thanks a lot! You are the best :ok_hand:

2 Likes