<p>I would start by looking into deferred decals (you can start <a href="https://bartwronski.com/2015/03/12/fixing-screen-space-deferred-decals/" rel="nofollow">here</a> for example, this blogpost has a lot of useful links)</p>

<p>If you understand how the positions are calculated and compared with the volume then you should be able to apply the same logic in the lighting phase.</p>

CC BY-SA 3.0
2016-10-05T15:12:35.930Z
2016-10-05T15:12:35.930Z
moradin
<p>Alan Wolfe is pretty spot on, but I will sum up any way :)</p>

<ul>
<li>render the back-faces of your "unit"-sized-box, [-1;1]</li>
<li>sample the zbuffer and transform into light-local coordinates (see <a href="http://f0716f2bff707a1b9e85-36c178e006d3d30c5b9c8dd905f8236a.r70.cf2.rackcdn.com/rendering_inside.pdf">our slides</a> for a fast way to do that).</li>
<li>early-out of the pixelshader if outside of the box, i.e. if any coordinate in the local-position is outside of -1;1.</li>
<li>then do the dot-product between the normal and the lightdir, in whatever space is convenient (you can extract the worldspace-lightdir from the object-to-world matrix).</li>
<li>projecting a texture is easy, the UV-coordinates are simply the localspace xy (moved to [0;1])</li>
<li>using a falloff texture is eays, the coordinate is simply the localspace z (moved to [0;1])</li>
</ul>

<p>In an actual game, you of course want to use some sort of acceleration to discard early; we used old-school stencil culling (and should have used depthbounds), but likely tiled culling, clustered culling or similar is better.</p>

<p>You could use zgreater testing to discard pixels where background is entirely behind the light, but iirc on most modern GPUs this will not actually be an advantage, as there will be no early-discard due to the hierarchical zbuffer being primed in the direction of zless.</p>

CC BY-SA 3.0
2016-10-05T14:07:22.863Z
That is coming from the man himself! I'm not sure if it'll be helpful, but here's a raytraced implementation in shadertoy:
https://www.shadertoy.com/view/4lV3zV
Alan Wolfe
CC BY-SA 3.0
2016-10-05T11:14:03.440Z
2016-10-05T11:14:03.440Z
Mikkel Gjoel
<p>I am currently trying to implement a specific directional light type.</p>

<p>This light type has been used in the game INSIDE and is called orthogonal spotlight (aka local directional light). I assume that this is a directional light which behaves like a spot light and have a squared or rectangular attenuation but I have some difficulties to integrate it in my deferred pipeline and get the general concept of this light type.</p>

<p>Classical directional light : <code>dot(worldNormal, lightDir)</code></p>

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

<p>I hope that you'll be able to give me some clues.
Thanks a lot !</p>

CC BY-SA 3.0
2016-10-03T14:05:19.983Z
Do you by chance have a screenshot of what you are trying to achieve? (:
Alan Wolfe
CC BY-SA 3.0
2016-10-03T14:11:13.550Z
Unfortunately not but here is a little diagram. It's easy to do a simple directional light `dot(worldNormal, lightDir)` but how to limit it.
MaT
CC BY-SA 3.0
2016-10-03T15:27:39.650Z
This isn't a full answer but essentially you want to test if a point is in the oriented box defined by the light. You may want to soften the edges as it gets farther away from the light source but that is more challenging.
Alan Wolfe
<shader><glsl><lighting><hlsl><deferred-rendering>
Special directional light type
MaT
# Special directional light type

(Asked by: username_0 on 2016-10-03)

I am currently trying to implement a specific directional light type.

This light type has been used in the game INSIDE and is called orthogonal spotlight (aka local directional light). I assume that this is a directional light which behaves like a spot light and have a squared or rectangular attenuation but I have some difficulties to integrate it in my deferred pipeline and get the general concept of this light type.

Classical directional light : `dot(worldNormal, lightDir)`

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

I hope that you'll be able to give me some clues.
Thanks a lot !

**Tags:** shader, glsl, lighting, hlsl, deferred-rendering

> **Comments:**
> **username_1**: Do you by chance have a screenshot of what you are trying to achieve? (:  
> **username_0**: Unfortunately not but here is a little diagram. It's easy to do a simple directional light `dot(worldNormal, lightDir)` but how to limit it.  
> **username_1**: This isn't a full answer but essentially you want to test if a point is in the oriented box defined by the light. You may want to soften the edges as it gets farther away from the light source but that is more challenging.  

---

## 2 answers

### Answer by username_3 on 2016-10-05. Score: 4 | Accepted answer

username_1 username_1 is pretty spot on, but I will sum up any way :)

* render the back-faces of your "unit"-sized-box, [-1;1]
* sample the zbuffer and transform into light-local coordinates (see [our slides](http://f0716f2bff707a1b9e85-36c178e006d3d30c5b9c8dd905f8236a.r70.cf2.rackcdn.com/rendering_inside.pdf) for a fast way to do that).
* early-out of the pixelshader if outside of the box, i.e. if any coordinate in the local-position is outside of -1;1.
* then do the dot-product between the normal and the lightdir, in whatever space is convenient (you can extract the worldspace-lightdir from the object-to-world matrix).
* projecting a texture is easy, the UV-coordinates are simply the localspace xy (moved to [0;1])
* using a falloff texture is eays, the coordinate is simply the localspace z (moved to [0;1])

In an actual game, you of course want to use some sort of acceleration to discard early; we used old-school stencil culling (and should have used depthbounds), but likely tiled culling, clustered culling or similar is better.

You could use zgreater testing to discard pixels where background is entirely behind the light, but iirc on most modern GPUs this will not actually be an advantage, as there will be no early-discard due to the hierarchical zbuffer being primed in the direction of zless.

> **Comments:**
> **username_1**: That is coming from the man himself! I'm not sure if it'll be helpful, but here's a raytraced implementation in shadertoy: https://www.shadertoy.com/view/4lV3zV  

---

### Answer by username_2 on 2016-10-05. Score: 2

I would start by looking into deferred decals (you can start [here](https://bartwronski.com/2015/03/12/fixing-screen-space-deferred-decals/) for example, this blogpost has a lot of useful links)

If you understand how the positions are calculated and compared with the volume then you should be able to apply the same logic in the lighting phase.


---

