r/GraphicsProgramming • • 3d ago

Question Problem while drawing line with max values of float (a bug)

Recently I have been working on a problem with two different GPUs (let’s call them A&B)
Here is problem
Due to a bug a line is being drawn using opengl at x=5 and y is +-FLT_MAX
for testing I kept ortho as 10 for x & y
Also note for testing origin is at the centre of display

GPU A
(there is a default guardband of 1.5 being used in the code while setting the gpu )

While drawing the huge line, the entire line doesn’t show up on the display

GPU B

there is a default guardband of 1.0 being used in the code while setting the gpu )

While drawing the huge line, only the upper half of line shows on display
Bottom half doesn’t show up on the display

1 Upvotes

3 comments sorted by

•

u/AutoModerator 3d ago

Recently updated rules. Please check that your post is in compliance with Rules 1, 4, 5, and 6 on the sidebar. TL;DR:

  • No showcases.

  • Disclose AI usage in post or project.

  • Present a topic to talk about, e.g. how something works.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

3

u/Noseense 3d ago edited 3d ago

Edit: I read it hastily and answered wrong. Here's a real answer:

It's float imprecision. The more a float diverges from 0, the less precision you have on the lower end. at float_max, the imprecision on small values makes it impossible to tell where the line really is on the screen, has a completely different magnitude.
I don't know what the bug is, so the answer is probably fixing that, but I'm not sure. It's also common to clamp values, which is something you could do.

I'd stick with default opengl viewport values of 0 to 1 and scale from that, though. Meaning that when you go to draw, just do `number / your_scale`, in this case `n / 10`.

To be even more precise, this happens because the GPU will clip everything to the viewport. At float_max, the gap between neighboring floats is huge compared to the screen values of 0 to 1, so the clip point ends up in the center. The two different GPU's being different is expected.

1

u/S48GS 3d ago

other comment answered - float scale with steps

https://blog.demofox.org/2017/11/21/ - scroll to precision table

that is your step-scale - at max float there 5 billion range step - your screen smaller than this step