<blockquote>
  <p>is it a total pipe dream to hope to solve the Ray/Bezier-surface intersection algebraically</p>
</blockquote>

<p>Yes, it's a pipe dream. A bicubic Bezier patch is an algebraic surface of degree 18. To intersect a ray with this surface, you have to find the roots of a polynomial of degree 18. There is no formula for these roots -- you have to find them by numerical methods. In fact, there are mathematical results (<a href="https://en.wikipedia.org/wiki/Abel%E2%80%93Ruffini_theorem" rel="noreferrer">the Abel-Ruffini theorem</a>) telling us that there can never be formulae for roots of equations beyond degree 4. The math doesn't just say that the formulae have not yet been found; it says that they never will be found, because they can't exist.</p>

<p>If you really want to do analytical (algebraic) ray-tracing of curvaceous shapes, you might try using <a href="https://www.researchgate.net/publication/234780280_Ray_tracing_of_Steiner_patches" rel="noreferrer">Steiner patches</a>. These have degree 4, so the ray-patch intersection can be computed by finding the <a href="https://en.wikipedia.org/wiki/Quartic_function" rel="noreferrer">roots of a quartic</a> (i.e. a polynomial of degree 4). There are formulae for finding roots of quartics, but they're pretty nasty, and it's surprisingly hard to write code that implements the formulae reliably.</p>

CC BY-SA 3.0
2017-10-30T12:45:56.897Z
2017-11-01T12:09:22.133Z
2017-11-01T12:09:22.133Z
bubba
<p>Another option, which I used a couple of decades ago (yikes!), is to use  <a href="https://www.cs.drexel.edu/~david/Classes/CS586/Papers/p171-toth.pdf" rel="nofollow">Toth's scheme from 1985</a> that employed interval arithmetic to narrow down the search space. IIRC, eventually it will resort to Newton-Rhapson but, again IIRC, I think it rarely required more than one or two steps to get to a good solution.</p>

<p>Though I haven't looked at it (well, apart from a quick glance) <a href="http://mentallandscape.com/Papers_graphicsinterface90b.pdf" rel="nofollow">Mitchell</a> has published some more recent work on ray tracing with interval maths.</p>

<p><em>(I should add that, if you are only doing Bezier surfaces, then the interval method might be a bit "overkill" since you can use tricks like blossoming to get bounds and derivatives. If, however, you combine Bezier curves with other functions, e.g. rotation around an axis, then its generality is more useful.)</em></p>

CC BY-SA 3.0
2015-09-02T12:40:38.147Z
2015-09-03T16:41:57.353Z
2015-09-03T16:41:57.353Z
Simon F
<p><a href="https://www.shadertoy.com/results?query=bezier" rel="nofollow noreferrer">https://www.shadertoy.com/results?query=bezier</a>
sort by age, in case of compatibility issues:</p>

<p>,...shows many solutions of many spline-subsets, either returning the distance to a 2d spline, or tracing a 3d patch. Splines and patches come in many forms. heavensine beind simplest, bezier being simple, nurbs being overly complex. The more constrains yo add to your spline, the simpler it gets. NURBS is extension overkill; 
- its Non-Uniform-ness of weights (the "NU") diminishes efficiency in comparison to to more symmetric splines 
- its Ration-al-ness (the R) also adds some complexity, for segmenting (rationing) and mixing with nearby segments (recursively solved).</p>

<p>bezier-patch-tracing is root-solving and with that comes contextual prioritization on precision; in what order to solve the quadratic equation.
this becomes impractical on higher exponents than cubic, due to exponential complexity and precision loss.</p>

<p>ray-marching==sphere-tracking is the simpler heuristic approach to root-solving, which seems to be the simple and most efficient solution to rendering most splines patches.</p>

<p>Lagrange-representation simplifies tracing/marching (as the L-points are ON the spline while the ControlVector-points (of the exact same spline) are rarely on the spline)</p>

<p>The special case of a heavensine-spline, where first derivatives of stat and end are ==0. simplifies continuity and involves less differentials (less subtraction).
A heavensine-patch can be traced efficiently in a single pass:
<a href="https://www.shadertoy.com/view/4djfW3" rel="nofollow noreferrer">https://www.shadertoy.com/view/4djfW3</a>
while other cubic (or higher) splines make the heuristic sphere-tracking/ray-marching approach more efficient (and "precise enough") than daring to analytically calculate all the roots to keep the smallest positive root (with exponentially accumulating precision errors for each root).</p>

<hr>

<p>In computer graphics, splines and patches have been nearly completely replaced by z-brushing by 2006. z-brushing uses displacement maps with homogeneous coordinates, or even using a "type" that us a union of sphere and linesegments (linesegments have a radius of 0, spheres have a length of 0, a union is simple and useful). For a minor loss in precision for a big gain in performance at relatively low memory cost for a look-up-table, that is easily made dynamic on a gpu.</p>

CC BY-SA 3.0
2017-08-24T15:53:26.563Z
Nevermind. all 3d patch solutions are done by sphere tracking.
ollj
CC BY-SA 3.0
2017-08-24T15:56:34.310Z
it just significantly increases performance and precision when the patch is simpler. to a point where a patch of seamess heavensines gets you very far in a few iterations:
ollj
CC BY-SA 3.0
2017-08-24T15:56:48.017Z
https://www.shadertoy.com/view/MtsXzl
ollj
CC BY-SA 3.0
2017-08-24T15:50:24.077Z
2017-08-24T15:50:24.077Z
ollj
<p><a href="https://www.shadertoy.com/view/MldczM" rel="nofollow noreferrer">https://www.shadertoy.com/view/MldczM</a>
Is ANALYTIC intersection of a ray with a triangular b-spline, 3 quadratic bezier splines, 3 CVs for each spline, 3 corner CVs are shared by 2 splines. All cv heights are orthogonal to the triangle plane. It solves for &lt;=2 roots in barycentric coordinates. There's never 3 intersections, so this is a surprisingly simple tracing of a curved function.
The first derivative is super short, too.</p>
<p>ESDF keys for camera movement
The parent shader in the comments has less optimized, less precise, more repetitive, naive simpler code.</p>
<p>It still has the error of rendering the negative surface if the camera is inside the prism of the triangle (above or below triangle). This seems to be a simpler special case, with only 1 root, where it fails to ignore the other root. The branch to solve this may be rather simple.</p>

CC BY-SA 4.0
2020-07-18T12:21:01.443Z
Welcome to CGSE. Please add the relevant code snippets of the linked source into your answer. If the link expires, your answer won't be helpful anymore.
wychmaster
CC BY-SA 4.0
2020-07-21T16:59:01.067Z
Interesting, but to be honest, it's only one step up from a triangle, and IIRC (but unfortunately being out of the office I can't access my copy of Farin's "Curves and Surfaces for CAGD" to check)  to get C1 (or G1?) continuity I believe you need a _quartic_ Bezier triangle, i.e. 15 control points
Simon F
CC BY-SA 4.0
2020-07-18T09:20:52.260Z
2020-07-21T17:00:27.490Z
2020-07-21T17:00:27.490Z
ollj
<p>most bezier-tracing is non analytic, 18 roots for a rectangular bezier patch.</p>
<p>while quaretic-root-solving (4 roots (or less)) is analytic, it involves so long fractions for each of the 4 roots (independently, and your first root must be solved this way), that the precision suffers significantly (for finding the 1st  root) (compared to calculating 3 cubic roots of a cubic-solver), that 32-bit-floats are likely not precise enough for (naive) quartic-root-solving.
naive quartic root solving solves 4 roots independently.
non naive solves 1of4 roots this way, and then inserts that as low-precision-constant into a remaining problem of cubic-root-solving, getting you slightly better precision,. but only IF the first root is not-too-far-away from the other 3 roots. if it is far away, the precision is likely even worse, than the naive solver (but the non-naive process is likely still much energy-efficient)</p>
<p>And you ideally know in advance, which of the 4 roots is closest tot he other 3 roots, and solve that root first, and then solve the remaining 3 roots as cubic.</p>
<p>This is why shadertoy.com mostly stops at cubic-root-solving and while it /shows/demoes/knows and has quartc-root solving (opngl opensource), it also knows that it is too slow and too low precision with 32 bit floats.</p>

CC BY-SA 4.0
2024-03-21T07:40:34.843Z
2024-03-21T07:40:34.843Z
ollj
<p>simple case == analytic: (4 roots or less)</p>
<p>For the simplest bezier patch; a base-triangle in 3d space (of any shape, just have 3 non-colinear-points in 3d.) (ideally all .z coordinates are == zero ... for triangle-normal-simplicity and faster speed (mote zeroes in matrices and dot-products), with 3 triangle-plane-normals on the triangle corners, and 3 triangle-plane-normals on the triangle-side-midpoints, having one of 6 CV-heights on each of those 6 plane-normals (can be positive or negative or 0), that define a quatratic-bezier patch, that plane-normal-projects exactly on the base-triangle the intersection of a line with such a simple bezier patch is actually analytic and fast and precise (enough within how i use it with ieee 32 bit float .).</p>
<p><a href="https://www.shadertoy.com/view/fsBcWc" rel="nofollow noreferrer">https://www.shadertoy.com/view/fsBcWc</a>
demonstrates this, but it has a culling-bug, IF the camera is above or below the base-triangle.
Bonus: the surface-normal is rather cheap to calculate.</p>
<p>===</p>
<p>general case = likely non analytic, long slow loops, but relatively low O(n) complexity (more than 4 roots, usually around 16 roots):</p>
<p>GENERALLY, solving for intersection of line-or-ray with almost-all-bezier-patches is non-analytic (more than 4 roots);</p>
<p>and usually a slow iteration process (with all the primitive-recursions of a bezier, that can be turned into loops-with-accumulator)
to a point where other approaches are done:</p>
<ul>
<li>Rasterization into triangle meshes (relatively fast for bezier patches)</li>
<li>substituting the surface with a height-map or displacement map, with various 3d-estimating rendering approaches (super fast, but textures need more memory)</li>
<li>substituting the surface with a signed-distance-field and perform sphere-tracking on it (arbitrarily fast/precise, usually less energy inefficient, costs too much energy for mobile-hardware)</li>
<li>possibly complex numbers, double-integrals and 3rd derivatives, who knows, but this may not be worth the compute cost for insignificant gains in precision.</li>
</ul>
<p>(shadertoy.com has MANY approaches to &quot;bezier patches that span a square/rectangle&quot;) some ray-trace (usually iterating a surface) some sphere-track (ray--march), not many rasterize, because shadertoy is 99% fragment shading and next to null vertex-shading.)</p>

CC BY-SA 4.0
2024-03-21T07:15:28.427Z
2024-03-21T07:26:04.987Z
2024-03-21T07:26:04.987Z
ollj
<p>First off, here's the Kajiya method I think you're thinking of: Kajiya, <em>Ray Tracing Parametric Patches</em>, SIGGRAPH 82. <a href="http://core.ac.uk/download/pdf/4891798.pdf">The tech report version</a> might be more informative.</p>

<p>What I hope you get from that is that it's not impossible and it's not conceptually difficult if you don't mind getting your hands dirty with some algebraic geometry and complex numbers. However, doing it directly is absurdly expensive.</p>

<p>"Real" ray tracers tend to do some combination of two things:</p>

<ul>
<li>Placing a bounding hierarchy (e.g. AABBs) on the patch to get a good "initial value" for a numeric root finder. If you do this well, you can avoid the "wrinkle" problem.</li>
<li>Tesselating the patch into <a href="http://ddg.cs.columbia.edu">DDG shells</a> and ray tracing them like polygon meshes.</li>
</ul>

<p>That last point sounds like it kills the "super-smoothness" requirement, but it isn't nearly as bad as that if you're using <a href="https://graphics.stanford.edu/papers/trd/">ray differentials</a>. Matching the tessellation level to the "size" of the ray bounds the error nicely. Besides, you probably need differentials for texture coordinates anyway, so you might as well use it to control the accuracy of the intersection test too.</p>

<p>Exploiting temporal coherence isn't a bad idea, but exactly how you'd do that depends a lot on your scene graph representation. You might want to look at ray coherence. Ask your favourite search engine about <a href="http://cseweb.ucsd.edu/~ravir/whitted.pdf">ray packet tracing</a> and <a href="https://graphics.stanford.edu/~boulos/papers/reorder_rt08.pdf">ray reordering</a>.</p>

CC BY-SA 3.0
2015-08-31T02:12:03.533Z
2015-08-31T02:12:03.533Z
Pseudonym
<p>I tried <a href="https://math.stackexchange.com/questions/348806/intersect-a-line-with-a-bicubic-bezier-surface-patch">this question on math.SE</a> and surprisingly, the answer was "the equations are too nasty, just feed the function it to a numerical root-finder". But if you consider yourself "a graphics guy" like me, and have played extensively with Bezier curves for design work, I got to believe that better can be done. There is a published algorithm by Kajiya that I don't have the background to understand (Sylvester Matrices), but the related advice on math.SE was that the result is a degree-18 polynomial in t, and you still need to solve that numerically. <a href="https://math.stackexchange.com/questions/1083240/can-a-bicubic-bezier-surface-be-represented-as-a-bernstein-polynomial">I had another idea with similar result</a>.</p>

<p>So, is it a total pipe dream to hope to solve the Ray/Bezier-surface intersection algebraically, thus making it possible to code explicitly and have super-fast super-smoothness?</p>

<p>Barring that, what's the fastest method for performing this calculation? Can you "find the wiggles" to get a tight bound (and target) for recursive subdivision? If you have to use a numerical root-finder (sigh), what properties does it need and is there a best choice for speed?</p>

<p>My original thought was about preparing for a specific surface, similar to Laplace expansion as described in the answer to my <a href="https://math.stackexchange.com/questions/297588/for-bsp-generation-how-to-intersect-or-locate-a-triangle-with-a-plane-defined-b">other math question about triangles</a>. But I'd be interested in general methods, too. I'm just thinking of a fixed set of shapes, like <a href="https://stackoverflow.com/questions/14807341/how-to-do-a-space-partitioning-of-the-utah-teapot">the Utah teapot</a>. But I'd be very interested in ways of optimizing for temporal coherence across animated frames.</p>

CC BY-SA 3.0
2015-08-30T22:05:22.257Z
Are you looking for a general method that you can apply to an arbitrary Bezier surface, or a way of preparing a fast method for a specific surface? Will your surface shape be fixed before runtime?
trichoplax is on Codidact now
CC BY-SA 3.0
2015-08-31T04:16:10.380Z
Note that you can raymarch bezier surfaces a lot easier than raytracing it. You can also raytrace or raymarch univariate surfaces a lot easier than other kinds!  http://blog.demofox.org/2015/07/28/rectangular-bezier-patches/
Alan Wolfe
<raytracing><bezier-curve>
How to raytrace Bezier surfaces?
luser droog
# How to raytrace Bezier surfaces?

(Asked by: username_0 on 2015-08-30)

I tried [this question on math.SE](https://math.stackexchange.com/questions/348806/intersect-a-line-with-a-bicubic-bezier-surface-patch) and surprisingly, the answer was "the equations are too nasty, just feed the function it to a numerical root-finder". But if you consider yourself "a graphics guy" like me, and have played extensively with Bezier curves for design work, I got to believe that better can be done. There is a published algorithm by Kajiya that I don't have the background to understand (Sylvester Matrices), but the related advice on math.SE was that the result is a degree-18 polynomial in t, and you still need to solve that numerically. [I had another idea with similar result](https://math.stackexchange.com/questions/1083240/can-a-bicubic-bezier-surface-be-represented-as-a-bernstein-polynomial).

So, is it a total pipe dream to hope to solve the Ray/Bezier-surface intersection algebraically, thus making it possible to code explicitly and have super-fast super-smoothness?

Barring that, what's the fastest method for performing this calculation? Can you "find the wiggles" to get a tight bound (and target) for recursive subdivision? If you have to use a numerical root-finder (sigh), what properties does it need and is there a best choice for speed?

My original thought was about preparing for a specific surface, similar to Laplace expansion as described in the answer to my [other math question about triangles](https://math.stackexchange.com/questions/297588/for-bsp-generation-how-to-intersect-or-locate-a-triangle-with-a-plane-defined-b). But I'd be interested in general methods, too. I'm just thinking of a fixed set of shapes, like [the Utah teapot](https://stackoverflow.com/questions/14807341/how-to-do-a-space-partitioning-of-the-utah-teapot). But I'd be very interested in ways of optimizing for temporal coherence across animated frames.

**Tags:** raytracing, bezier-curve

> **Comments:**
> **username_1**: Are you looking for a general method that you can apply to an arbitrary Bezier surface, or a way of preparing a fast method for a specific surface? Will your surface shape be fixed before runtime?  
> **username_2**: Note that you can raymarch bezier surfaces a lot easier than raytracing it. You can also raytrace or raymarch univariate surfaces a lot easier than other kinds!  http://blog.demofox.org/2015/07/28/rectangular-bezier-patches/  

---

## 7 answers

### Answer by username_7 on 2015-08-31. Score: 16 | Accepted answer

First off, here's the Kajiya method I think you're thinking of: Kajiya, *Ray Tracing Parametric Patches*, SIGGRAPH 82. [The tech report version](http://core.ac.uk/download/pdf/4891798.pdf) might be more informative.

What I hope you get from that is that it's not impossible and it's not conceptually difficult if you don't mind getting your hands dirty with some algebraic geometry and complex numbers. However, doing it directly is absurdly expensive.

"Real" ray tracers tend to do some combination of two things:

* Placing a bounding hierarchy (e.g. AABBs) on the patch to get a good "initial value" for a numeric root finder. If you do this well, you can avoid the "wrinkle" problem.
* Tesselating the patch into [DDG shells](http://ddg.cs.columbia.edu) and ray tracing them like polygon meshes.

That last point sounds like it kills the "super-smoothness" requirement, but it isn't nearly as bad as that if you're using [ray differentials](https://graphics.stanford.edu/papers/trd/). Matching the tessellation level to the "size" of the ray bounds the error nicely. Besides, you probably need differentials for texture coordinates anyway, so you might as well use it to control the accuracy of the intersection test too.

Exploiting temporal coherence isn't a bad idea, but exactly how you'd do that depends a lot on your scene graph representation. You might want to look at ray coherence. Ask your favourite search engine about [ray packet tracing](http://cseweb.ucsd.edu/~ravir/whitted.pdf) and [ray reordering](https://graphics.stanford.edu/~boulos/papers/reorder_rt08.pdf).


---

### Answer by username_3 on 2017-10-30. Score: 10

> is it a total pipe dream to hope to solve the Ray/Bezier-surface intersection algebraically

Yes, it's a pipe dream. A bicubic Bezier patch is an algebraic surface of degree 18. To intersect a ray with this surface, you have to find the roots of a polynomial of degree 18. There is no formula for these roots -- you have to find them by numerical methods. In fact, there are mathematical results ([the Abel-Ruffini theorem](https://en.wikipedia.org/wiki/Abel%E2%80%93Ruffini_theorem)) telling us that there can never be formulae for roots of equations beyond degree 4. The math doesn't just say that the formulae have not yet been found; it says that they never will be found, because they can't exist.

If you really want to do analytical (algebraic) ray-tracing of curvaceous shapes, you might try using [Steiner patches](https://www.researchgate.net/publication/234780280_Ray_tracing_of_Steiner_patches). These have degree 4, so the ray-patch intersection can be computed by finding the [roots of a quartic](https://en.wikipedia.org/wiki/Quartic_function) (i.e. a polynomial of degree 4). There are formulae for finding roots of quartics, but they're pretty nasty, and it's surprisingly hard to write code that implements the formulae reliably.


---

### Answer by username_4 on 2015-09-02. Score: 5

Another option, which I used a couple of decades ago (yikes!), is to use [Toth's scheme from 1985](https://www.cs.drexel.edu/~david/Classes/CS586/Papers/p171-toth.pdf) that employed interval arithmetic to narrow down the search space. IIRC, eventually it will resort to Newton-Rhapson but, again IIRC, I think it rarely required more than one or two steps to get to a good solution.

Though I haven't looked at it (well, apart from a quick glance) [Mitchell](http://mentallandscape.com/Papers_graphicsinterface90b.pdf) has published some more recent work on ray tracing with interval maths.

*(I should add that, if you are only doing Bezier surfaces, then the interval method might be a bit "overkill" since you can use tricks like blossoming to get bounds and derivatives. If, however, you combine Bezier curves with other functions, e.g. rotation around an axis, then its generality is more useful.)*


---

### Answer by username_5 on 2017-08-24. Score: 1

<https://www.shadertoy.com/results?query=bezier>
sort by age, in case of compatibility issues:

,...shows many solutions of many spline-subsets, either returning the distance to a 2d spline, or tracing a 3d patch. Splines and patches come in many forms. heavensine beind simplest, bezier being simple, nurbs being overly complex. The more constrains yo add to your spline, the simpler it gets. NURBS is extension overkill;
- its Non-Uniform-ness of weights (the "NU") diminishes efficiency in comparison to to more symmetric splines
- its Ration-al-ness (the R) also adds some complexity, for segmenting (rationing) and mixing with nearby segments (recursively solved).

bezier-patch-tracing is root-solving and with that comes contextual prioritization on precision; in what order to solve the quadratic equation.
this becomes impractical on higher exponents than cubic, due to exponential complexity and precision loss.

ray-marching==sphere-tracking is the simpler heuristic approach to root-solving, which seems to be the simple and most efficient solution to rendering most splines patches.

Lagrange-representation simplifies tracing/marching (as the L-points are ON the spline while the ControlVector-points (of the exact same spline) are rarely on the spline)

The special case of a heavensine-spline, where first derivatives of stat and end are ==0. simplifies continuity and involves less differentials (less subtraction).
A heavensine-patch can be traced efficiently in a single pass:
<https://www.shadertoy.com/view/4djfW3>
while other cubic (or higher) splines make the heuristic sphere-tracking/ray-marching approach more efficient (and "precise enough") than daring to analytically calculate all the roots to keep the smallest positive root (with exponentially accumulating precision errors for each root).

---

In computer graphics, splines and patches have been nearly completely replaced by z-brushing by 2006. z-brushing uses displacement maps with homogeneous coordinates, or even using a "type" that us a union of sphere and linesegments (linesegments have a radius of 0, spheres have a length of 0, a union is simple and useful). For a minor loss in precision for a big gain in performance at relatively low memory cost for a look-up-table, that is easily made dynamic on a gpu.

> **Comments:**
> **username_5**: Nevermind. all 3d patch solutions are done by sphere tracking.  
> **username_5**: it just significantly increases performance and precision when the patch is simpler. to a point where a patch of seamess heavensines gets you very far in a few iterations:  
> **username_5**: https://www.shadertoy.com/view/MtsXzl  

---

### Answer by username_5 on 2020-07-18. Score: 1

<https://www.shadertoy.com/view/MldczM>
Is ANALYTIC intersection of a ray with a triangular b-spline, 3 quadratic bezier splines, 3 CVs for each spline, 3 corner CVs are shared by 2 splines. All cv heights are orthogonal to the triangle plane. It solves for <=2 roots in barycentric coordinates. There's never 3 intersections, so this is a surprisingly simple tracing of a curved function.
The first derivative is super short, too.

ESDF keys for camera movement
The parent shader in the comments has less optimized, less precise, more repetitive, naive simpler code.

It still has the error of rendering the negative surface if the camera is inside the prism of the triangle (above or below triangle). This seems to be a simpler special case, with only 1 root, where it fails to ignore the other root. The branch to solve this may be rather simple.

> **Comments:**
> **username_6**: Welcome to CGSE. Please add the relevant code snippets of the linked source into your answer. If the link expires, your answer won't be helpful anymore.  
> **username_4**: Interesting, but to be honest, it's only one step up from a triangle, and IIRC (but unfortunately being out of the office I can't access my copy of Farin's "Curves and Surfaces for CAGD" to check)  to get C1 (or G1?) continuity I believe you need a _quartic_ Bezier triangle, i.e. 15 control points  

---

### Answer by username_5 on 2024-03-21. Score: 0

most bezier-tracing is non analytic, 18 roots for a rectangular bezier patch.

while quaretic-root-solving (4 roots (or less)) is analytic, it involves so long fractions for each of the 4 roots (independently, and your first root must be solved this way), that the precision suffers significantly (for finding the 1st root) (compared to calculating 3 cubic roots of a cubic-solver), that 32-bit-floats are likely not precise enough for (naive) quartic-root-solving.
naive quartic root solving solves 4 roots independently.
non naive solves 1of4 roots this way, and then inserts that as low-precision-constant into a remaining problem of cubic-root-solving, getting you slightly better precision,. but only IF the first root is not-too-far-away from the other 3 roots. if it is far away, the precision is likely even worse, than the naive solver (but the non-naive process is likely still much energy-efficient)

And you ideally know in advance, which of the 4 roots is closest tot he other 3 roots, and solve that root first, and then solve the remaining 3 roots as cubic.

This is why shadertoy.com mostly stops at cubic-root-solving and while it /shows/demoes/knows and has quartc-root solving (opngl opensource), it also knows that it is too slow and too low precision with 32 bit floats.


---

### Answer by username_5 on 2024-03-21. Score: 0

simple case == analytic: (4 roots or less)

For the simplest bezier patch; a base-triangle in 3d space (of any shape, just have 3 non-colinear-points in 3d.) (ideally all .z coordinates are == zero ... for triangle-normal-simplicity and faster speed (mote zeroes in matrices and dot-products), with 3 triangle-plane-normals on the triangle corners, and 3 triangle-plane-normals on the triangle-side-midpoints, having one of 6 CV-heights on each of those 6 plane-normals (can be positive or negative or 0), that define a quatratic-bezier patch, that plane-normal-projects exactly on the base-triangle the intersection of a line with such a simple bezier patch is actually analytic and fast and precise (enough within how i use it with ieee 32 bit float .).

<https://www.shadertoy.com/view/fsBcWc>
demonstrates this, but it has a culling-bug, IF the camera is above or below the base-triangle.
Bonus: the surface-normal is rather cheap to calculate.

===

general case = likely non analytic, long slow loops, but relatively low O(n) complexity (more than 4 roots, usually around 16 roots):

GENERALLY, solving for intersection of line-or-ray with almost-all-bezier-patches is non-analytic (more than 4 roots);

and usually a slow iteration process (with all the primitive-recursions of a bezier, that can be turned into loops-with-accumulator)
to a point where other approaches are done:

* Rasterization into triangle meshes (relatively fast for bezier patches)
* substituting the surface with a height-map or displacement map, with various 3d-estimating rendering approaches (super fast, but textures need more memory)
* substituting the surface with a signed-distance-field and perform sphere-tracking on it (arbitrarily fast/precise, usually less energy inefficient, costs too much energy for mobile-hardware)
* possibly complex numbers, double-integrals and 3rd derivatives, who knows, but this may not be worth the compute cost for insignificant gains in precision.

(shadertoy.com has MANY approaches to "bezier patches that span a square/rectangle") some ray-trace (usually iterating a surface) some sphere-track (ray--march), not many rasterize, because shadertoy is 99% fragment shading and next to null vertex-shading.)


---

