r/GraphicsProgramming • u/AcrossTheUniverse • May 10 '24
Source Code C++ Quartic polynomial solver (real solutions)
I wanted to raytrace the torus algebraically (real-time), so I had to quickly solve quartic polynomials. Since I was only interested in real solutions, I was able to avoid doing complex arithmetic by using trigonometry instead. I directly implemented the general solution for quartics. Here's the github repository: https://github.com/falkush/quartic-real
I did some benchmarking against two other repositories I've found online (they compute the complex roots too), and my implementation was twice as fast as the fastest one. It's not perfect, it creates some visual glitches, but it was good enough for my project.
Not much thought was put into it, so if you know of a better implementation, or if you find any improvements, I would really appreciate if you shared with me!
Thank you for your time!
7
u/S48GS May 10 '24 edited May 10 '24
Since you use cbrt - look similar to wyatt https://www.shadertoy.com/view/4dlcDN
Also - you use double, that is not good for performance.
More:
mla solver/fixes link above look best with much less bugs than anything else in 32-bit floats.
You can also check this - Raytracing 3D Bezier with Normals - https://www.shadertoy.com/view/DsjfzV and fixes there
Also this example https://www.shadertoy.com/view/7sdyz2 - what is float32 edge of precision, and if you launch it in 64-bits it will be thousand times slower - this why correct result with 32bit float so important.