<p>There is a trick to shadows like this, but only this exact usecase. While you can certainly draw a true shadow using many techniques. The trick is you can just scale the object flat onto the floor plane.</p>
<p>So all you need to do is draw the object 2 times one time with a matrix that is scaled to zero on the floor axis. You can also use this technique to draw shadows that arent entirely top down by adding skew to counter the now rotated shadow.</p>
<p>This is super easy to implement. No extra cameras. But works only on one plane. This is a special case of shadow volumes without the need to draw the volumes.</p>

CC BY-SA 4.0
2020-12-04T16:26:13.537Z
2020-12-04T16:26:13.537Z
joojaa
<p>One approach for stuff like this that  I just heard is to do raymarching on simple analytical shapes that approximate the mesh, so you basically create an abstract coarse SDF representation of the mesh in question and raymarch some shadows. I have heard Iñigo Quilez mention it and talking on how he gave a conference about it once but I haven't found it, I think it was either Gamescon or SIGGRAPH.</p>

CC BY-SA 4.0
2020-12-16T04:27:37.800Z
2020-12-16T04:27:37.800Z
Felipe Gutierrez
<p>I can't tell you how exactly each 3d modeling software calculates shadows since I don't know their implementations. However, I guess the usual candidates for real-time shadow calculations are used. These are:</p>
<ul>
<li><a href="https://de.wikipedia.org/wiki/Shadow_Mapping" rel="nofollow noreferrer">Shadow mapping</a></li>
<li><a href="https://en.wikipedia.org/wiki/Shadow_volume" rel="nofollow noreferrer">Shadow Volumes</a></li>
</ul>
<p>To my knowledge, the second one isn't that popular since it is more complicated and usually computationally more expensive. If you just want to cast a silhouette as a shadow onto a flat surface without caring about the correct lighting of other objects that lie in the shadows you can use a simple approach like this:</p>
<p>Select a (single-channel) texture as your render target and clear its content. Now draw all your objects from the top without perspective projection. The fragment shader returns always the same color that must be different from the clear color. In the end, you have a texture that contains all the silhouettes from your objects. Now you only need to render a quad that uses this texture at the correct position into your scene slightly above the flat surface. Set the output color of the fragment shader to black. The alpha channel is either set to 0 if the texture color at the current fragment is equal to the clear color or to a value of your liking if it is not. (This requires blending to be enabled)</p>
<p>This is basically a very specialized and simplified shadow mapping special case that uses a texture instead of a z-buffer.</p>
<p><strong>Note:</strong></p>
<p>I originally suggested using the stencil buffer for this, but it would add an unnecessary indirection, and getting it working as intended can be quite a pain (at least in OpenGL).</p>

CC BY-SA 4.0
2020-12-03T14:57:03.757Z
*"Draw all your objects "looking from the top" and populate your *stencil* buffer"*
Did you mean "Z buffer"?
Simon F
CC BY-SA 4.0
2020-12-03T16:31:41.713Z
@SimonF I actually meant the stencil buffer. After rendering all the objects, the stencil buffer should contain basically a `true` or `false` value for each pixel. However, you still need to transform the data to the camera perspective which most likely requires creating a texture from it or populating the z-buffer. In the latter case, it is probably much easier to use the standard shadow mapping technique. In fact, I think shadow mapping is generally the best approach for this purpose. It's just that the word silhouette always makes me automatically think about stencil testing.
wychmaster
CC BY-SA 4.0
2020-12-03T17:35:11.663Z
After some time of thinking, I think this whole stencil buffer thing is unnecessary and makes everything overly complicated. I'll update my answer as soon as I find the time.
wychmaster
CC BY-SA 4.0
2020-12-04T08:41:31.740Z
I'm reasonably familiar with shadow volume approaches (from development of PowerVR series 1 and 2 (Dreamcast) which had optimised support for volumes) but what you were describing sounded more like a shadow buffer approach, ie. rendering from the light's view.
Simon F
CC BY-SA 4.0
2020-12-04T08:53:48.097Z
@SimonF I already updated my answer and you are right, what I described was a specialized shadow mapping approach and I never meant it to be something else. However, in my original approach, I unnecessarily wanted to use the stencil buffer to cut out the silhouettes. But it has nothing to do with the stencil buffer based shadow volumes technique. I think this is where the confusion came from.
wychmaster
CC BY-SA 4.0
2020-12-03T10:36:28.993Z
2020-12-04T08:37:44.113Z
2020-12-04T08:37:44.113Z
wychmaster
<p>There are some 3D applications which can cast shadow or silhouette below 3D models. They render pretty fast and smooth. I wonder what kind of technology is the standard procedure to get 3D model shadow/silhouette.</p>
<p>For example is there any C++ library like <a href="https://github.com/libigl/libigl" rel="nofollow noreferrer">libigl</a> or <a href="https://github.com/CGAL/cgal" rel="nofollow noreferrer">CGAL</a> to get shadow/silhouette pretty fast? Or maybe GLSL shading is used? Any hint would be appreciated on the standard technology stack.</p>
<p><a href="https://i.sstatic.net/9QPWG.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/9QPWG.png" alt="Screenshot" /></a></p>

CC BY-SA 4.0
2020-12-15T00:31:50.790Z
This looks like an implementation of "planar shadows" but the "standard" implementation of shadows for rasterized graphics is "shadow mapping". You can google either of these and get a resplendent amount of info on how to implement and use them.
pmw1234
<3d><computational-geometry><mesh><shadow><silhouette>
Silhouette below 3D model
Megidd
# Silhouette below 3D model

(Asked by: username_0 on 2020-12-02)

There are some 3D applications which can cast shadow or silhouette below 3D models. They render pretty fast and smooth. I wonder what kind of technology is the standard procedure to get 3D model shadow/silhouette.

For example is there any C++ library like [libigl](https://github.com/libigl/libigl) or [CGAL](https://github.com/CGAL/cgal) to get shadow/silhouette pretty fast? Or maybe GLSL shading is used? Any hint would be appreciated on the standard technology stack.

[![Screenshot](https://i.sstatic.net/9QPWG.png)](https://i.sstatic.net/9QPWG.png)

**Tags:** 3d, computational-geometry, mesh, shadow, silhouette

> **Comments:**
> **username_1**: This looks like an implementation of "planar shadows" but the "standard" implementation of shadows for rasterized graphics is "shadow mapping". You can google either of these and get a resplendent amount of info on how to implement and use them.  

---

## 3 answers

### Answer by username_2 on 2020-12-04. Score: 3

There is a trick to shadows like this, but only this exact usecase. While you can certainly draw a true shadow using many techniques. The trick is you can just scale the object flat onto the floor plane.

So all you need to do is draw the object 2 times one time with a matrix that is scaled to zero on the floor axis. You can also use this technique to draw shadows that arent entirely top down by adding skew to counter the now rotated shadow.

This is super easy to implement. No extra cameras. But works only on one plane. This is a special case of shadow volumes without the need to draw the volumes.


---

### Answer by username_3 on 2020-12-16. Score: 1

One approach for stuff like this that I just heard is to do raymarching on simple analytical shapes that approximate the mesh, so you basically create an abstract coarse SDF representation of the mesh in question and raymarch some shadows. I have heard Iñigo Quilez mention it and talking on how he gave a conference about it once but I haven't found it, I think it was either Gamescon or SIGGRAPH.


---

### Answer by username_4 on 2020-12-03. Score: 1

I can't tell you how exactly each 3d modeling software calculates shadows since I don't know their implementations. However, I guess the usual candidates for real-time shadow calculations are used. These are:

* [Shadow mapping](https://de.wikipedia.org/wiki/Shadow_Mapping)
* [Shadow Volumes](https://en.wikipedia.org/wiki/Shadow_volume)

To my knowledge, the second one isn't that popular since it is more complicated and usually computationally more expensive. If you just want to cast a silhouette as a shadow onto a flat surface without caring about the correct lighting of other objects that lie in the shadows you can use a simple approach like this:

Select a (single-channel) texture as your render target and clear its content. Now draw all your objects from the top without perspective projection. The fragment shader returns always the same color that must be different from the clear color. In the end, you have a texture that contains all the silhouettes from your objects. Now you only need to render a quad that uses this texture at the correct position into your scene slightly above the flat surface. Set the output color of the fragment shader to black. The alpha channel is either set to 0 if the texture color at the current fragment is equal to the clear color or to a value of your liking if it is not. (This requires blending to be enabled)

This is basically a very specialized and simplified shadow mapping special case that uses a texture instead of a z-buffer.

**Note:**

I originally suggested using the stencil buffer for this, but it would add an unnecessary indirection, and getting it working as intended can be quite a pain (at least in OpenGL).

> **Comments:**
> **username_5**: *"Draw all your objects "looking from the top" and populate your *stencil* buffer"* Did you mean "Z buffer"?  
> **username_4**: @username_5 I actually meant the stencil buffer. After rendering all the objects, the stencil buffer should contain basically a `true` or `false` value for each pixel. However, you still need to transform the data to the camera perspective which most likely requires creating a texture from it or populating the z-buffer. In the latter case, it is probably much easier to use the standard shadow mapping technique. In fact, I think shadow mapping is generally the best approach for this purpose. It's just that the word silhouette always makes me automatically think about stencil testing.  
> **username_4**: After some time of thinking, I think this whole stencil buffer thing is unnecessary and makes everything overly complicated. I'll update my answer as soon as I find the time.  
> **username_5**: I'm reasonably familiar with shadow volume approaches (from development of PowerVR series 1 and 2 (Dreamcast) which had optimised support for volumes) but what you were describing sounded more like a shadow buffer approach, ie. rendering from the light's view.  
> **username_4**: @username_5 I already updated my answer and you are right, what I described was a specialized shadow mapping approach and I never meant it to be something else. However, in my original approach, I unnecessarily wanted to use the stencil buffer to cut out the silhouettes. But it has nothing to do with the stencil buffer based shadow volumes technique. I think this is where the confusion came from.  

---

