<p>Raytracing is a great way to render spheres as Daniel mentioned.  Below is a screenshot of a raytraced scene I made but lost the source code to unfortunately.</p>

<p><a href="https://i.sstatic.net/ee8T2.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ee8T2.jpg" alt="enter image description here"></a></p>

<p>If you are looking to render smooth / non polygonal objects in general, it's not always easy, desired or even possible to do an analytical solve for ray vs object.</p>

<p>For these cases, a useful technique is something called "ray marching" (also called sphere tracing).  In ray marching, you take steps down a ray and at each point ask if you are inside or outside of the object (alternately, above or below).  When the answer changes, you know that the intersection of the ray occurred between the current and last point you tested on the ray.</p>

<p>Once you know the intersection occured between those two points, you can do various things to try and find the actual intersection, depending on quality needs vs computation costs.  Some common techniques:</p>

<ol>
<li>Just accept either the current or last point tested as the intersection point (fastest)</li>
<li>Binary search the range to get a better answer</li>
<li>If you have a function which gives you an (estimated) signed distance from a point to the surface, instead of just an "inside vs outside" test, you can do a linear interpolation between the last point and the current point to find where the "0" is, and take that as your intersection point.  This is what I've had most success with personally.</li>
</ol>

<p>Note that you can get an estimated signed distance numerically using finite differences and using the gradient. Check this link for more info on that: <a href="http://www.iquilezles.org/www/articles/distance/distance.htm" rel="nofollow noreferrer">http://www.iquilezles.org/www/articles/distance/distance.htm</a></p>

<p>You can find more info about finite difference methods here:
<a href="http://blog.demofox.org/2015/08/02/finite-differences/" rel="nofollow noreferrer">http://blog.demofox.org/2015/08/02/finite-differences/</a></p>

<p>With a signed distance estimating function, you can also use the gradient to get the normal, which is required for shading.</p>

<p>Below is a ray marched surface that is defined as a function $z=f(x,y)$, and is a screenshot of this webgl2 interactive demo: <a href="http://demofox.org/LeastSquaresSurfaceFit.html" rel="nofollow noreferrer">http://demofox.org/LeastSquaresSurfaceFit.html</a></p>

<p><a href="https://i.sstatic.net/bK8KL.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bK8KL.png" alt="enter image description here"></a></p>

<p>Alternately, here's a shadertoy which ray marches a cubic bezier rectangle - it's cubic on each axis, so is degree(3,3): <a href="https://www.shadertoy.com/view/4tfXz2" rel="nofollow noreferrer">https://www.shadertoy.com/view/4tfXz2</a></p>

<p><a href="https://i.sstatic.net/O7ORO.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/O7ORO.png" alt="enter image description here"></a></p>

<p>Back to talking about rendering spheres, you can also just rasterize a sphere as a 2d circle (possibly distorted by a view / projection matrix type setup in "2d"), and then shade it as if it was a 3d object.  It can also work for non spheres, and you see this a lot with renderings of metaballs.</p>

<p>Below is a screenshot of this shadertoy which renders metaballs: <a href="https://www.shadertoy.com/view/4sXXWM" rel="nofollow noreferrer">https://www.shadertoy.com/view/4sXXWM</a></p>

<p><a href="https://i.sstatic.net/CJoC4.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CJoC4.png" alt="enter image description here"></a></p>

<p>Lastly, I wanted to mention that all of these techniques are compatible with traditional renderers as well.  Like Daniel said, you can draw a screen space billboard that is larger than the shape (or draw a world space scaled and oriented unit cube that contains it) and then you do your raytracing, raymarching, or rasterization / fake 3d lighting within the pixel shader, to mix these techniques with standard rasterization rendering methods.</p>

CC BY-SA 3.0
2017-01-04T17:44:25.723Z
2017-01-04T19:18:24.873Z
2017-01-04T19:18:24.873Z
Alan Wolfe
<p>It seems that in all existing graphics libraries, 3D objects are always described in terms of triangles. Drawing triangles can be implemented very efficiently on video hardware and since any 3D object can be approximated with triangles, triangles are the only basic element needed. Triangles can be represented by 3-tuples and are simple to work with.</p>

<p>I have always wondered whether other approaches have been tried. There are certain complications when approximating spherical objects with triangles. Have there been any alternative approaches to drawing spherical objects (for example, without using polygons for approximations)? What are the problems with such approaches that make using triangles the best option?</p>

CC BY-SA 3.0
2017-01-03T04:57:01.723Z
Many raytracers implement analytical shapes. In fact we started 3d thatway and progressed to dicing of analytical shapes and only then to using polygons.
joojaa
CC BY-SA 3.0
2017-01-03T09:28:43.610Z
You may be interested to read about the [ellipsoid rendering of the Ecstatica series](http://gdalgorithms-list.narkive.com/qbLh34tI/ellipsoid-engine-used-in-game-ecstatica-how-its-done) back in the 1990s.

![Ecstatica screenshot](http://vignette4.wikia.nocookie.net/ecstatica/images/f/f7/Ecs_firstencounter.jpg/revision/latest?cb=20120813160048)
IneQuation
CC BY-SA 3.0
2017-01-03T22:06:59.027Z
For modeling more general curved surfaces 3d splines are also commonly used, such as Bézier patches and NURBS surfaces. Most graphics applications just approximate these curves using triangles, but there are methods for displaying them that do not require such approximations.
vgs
<shader><3d>
Is there a way to draw spherical objects without triangles?
martinkunev
# Is there a way to draw spherical objects without triangles?

(Asked by: username_0 on 2017-01-02)

It seems that in all existing graphics libraries, 3D objects are always described in terms of triangles. Drawing triangles can be implemented very efficiently on video hardware and since any 3D object can be approximated with triangles, triangles are the only basic element needed. Triangles can be represented by 3-tuples and are simple to work with.

I have always wondered whether other approaches have been tried. There are certain complications when approximating spherical objects with triangles. Have there been any alternative approaches to drawing spherical objects (for example, without using polygons for approximations)? What are the problems with such approaches that make using triangles the best option?

**Tags:** shader, 3d

> **Comments:**
> **username_1**: Many raytracers implement analytical shapes. In fact we started 3d thatway and progressed to dicing of analytical shapes and only then to using polygons.  
> **username_2**: You may be interested to read about the [ellipsoid rendering of the Ecstatica series](http://gdalgorithms-list.narkive.com/qbLh34tI/ellipsoid-engine-used-in-game-ecstatica-how-its-done) back in the 1990s.  ![Ecstatica screenshot](http://vignette4.wikia.nocookie.net/ecstatica/images/f/f7/Ecs_firstencounter.jpg/revision/latest?cb=20120813160048)  
> **username_3**: For modeling more general curved surfaces 3d splines are also commonly used, such as Bézier patches and NURBS surfaces. Most graphics applications just approximate these curves using triangles, but there are methods for displaying them that do not require such approximations.  

---

## 1 answers

### Answer by username_4 on 2017-01-04. Score: 2 | Accepted answer

Raytracing is a great way to render spheres as Daniel mentioned. Below is a screenshot of a raytraced scene I made but lost the source code to unfortunately.

[![enter image description here](https://i.sstatic.net/ee8T2.jpg)](https://i.sstatic.net/ee8T2.jpg)

If you are looking to render smooth / non polygonal objects in general, it's not always easy, desired or even possible to do an analytical solve for ray vs object.

For these cases, a useful technique is something called "ray marching" (also called sphere tracing). In ray marching, you take steps down a ray and at each point ask if you are inside or outside of the object (alternately, above or below). When the answer changes, you know that the intersection of the ray occurred between the current and last point you tested on the ray.

Once you know the intersection occured between those two points, you can do various things to try and find the actual intersection, depending on quality needs vs computation costs. Some common techniques:

1. Just accept either the current or last point tested as the intersection point (fastest)
2. Binary search the range to get a better answer
3. If you have a function which gives you an (estimated) signed distance from a point to the surface, instead of just an "inside vs outside" test, you can do a linear interpolation between the last point and the current point to find where the "0" is, and take that as your intersection point. This is what I've had most success with personally.

Note that you can get an estimated signed distance numerically using finite differences and using the gradient. Check this link for more info on that: <http://www.iquilezles.org/www/articles/distance/distance.htm>

You can find more info about finite difference methods here:
<http://blog.demofox.org/2015/08/02/finite-differences/>

With a signed distance estimating function, you can also use the gradient to get the normal, which is required for shading.

Below is a ray marched surface that is defined as a function $z=f(x,y)$, and is a screenshot of this webgl2 interactive demo: <http://demofox.org/LeastSquaresSurfaceFit.html>

[![enter image description here](https://i.sstatic.net/bK8KL.png)](https://i.sstatic.net/bK8KL.png)

Alternately, here's a shadertoy which ray marches a cubic bezier rectangle - it's cubic on each axis, so is degree(3,3): <https://www.shadertoy.com/view/4tfXz2>

[![enter image description here](https://i.sstatic.net/O7ORO.png)](https://i.sstatic.net/O7ORO.png)

Back to talking about rendering spheres, you can also just rasterize a sphere as a 2d circle (possibly distorted by a view / projection matrix type setup in "2d"), and then shade it as if it was a 3d object. It can also work for non spheres, and you see this a lot with renderings of metaballs.

Below is a screenshot of this shadertoy which renders metaballs: <https://www.shadertoy.com/view/4sXXWM>

[![enter image description here](https://i.sstatic.net/CJoC4.png)](https://i.sstatic.net/CJoC4.png)

Lastly, I wanted to mention that all of these techniques are compatible with traditional renderers as well. Like Daniel said, you can draw a screen space billboard that is larger than the shape (or draw a world space scaled and oriented unit cube that contains it) and then you do your raytracing, raymarching, or rasterization / fake 3d lighting within the pixel shader, to mix these techniques with standard rasterization rendering methods.


---

