# Stencil projection demo

**URL:** <https://discourse.threejs.org/t/stencil-projection-demo/63889>\
**Category:** Showcase\
**Created:** [April 9, 2024, 7:13pm UTC](https://discourse.threejs.org/t/stencil-projection-demo/63889 "2024-04-09T19:13:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubois](https://avatars.discourse-cdn.com/v4/letter/d/e9c0ed/32.png) [@dubois](https://discourse.threejs.org/u/dubois)\
**Post date:** [April 9, 2024, 7:13pm UTC](https://discourse.threejs.org/t/stencil-projection-demo/63889/1 "2024-04-09T19:13:48Z")

</div>

I had an interview recently and we discussed how would one project this spline representing a vehicles trajectory onto uneven terrain. I proposed something like stencil shadows instead of textures. This is a demo of that - there is a spline that can be moved, it’s above the terrain, and it projects a shadow basically.  
It’s not the whole stencil shadow algorithm since it doesn’t compute any contours and such, but the way it writes to stencil is borrowed from there.  
[Link](https://codesandbox.io/p/sandbox/three-js-forked-jnk3w8)

---

<div class="post-metadata">

**Author:** ![Oxyn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/oxyn/32/12902_2.png) [@Oxyn](https://discourse.threejs.org/u/Oxyn)\
**Post date:** [April 10, 2024, 9:13am UTC](https://discourse.threejs.org/t/stencil-projection-demo/63889/2 "2024-04-10T09:13:53Z")

</div>

Very interesting way of doing it using shadows for quick realtime interaction.  
And coupled with offscreen scene and a `THREE.WebGLRenderTarget` it still can be converted back to texture/mask for more complex shenanigans.

---

<div class="post-metadata">

**Author:** ![Antonio](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/antonio/32/27527_2.png) [@Antonio](https://discourse.threejs.org/u/Antonio)\
**Post date:** [April 10, 2024, 12:29pm UTC](https://discourse.threejs.org/t/stencil-projection-demo/63889/3 "2024-04-10T12:29:42Z")

</div>

This is very usefull, thanks for sharing!
