<p>A long time ago I made an application that used volumetric rendering and I developed some shadowing equations that I felt very happy with, since they have pretty good results.</p>

<p>For these equations to work one needs the object that occludes the light that is closest to the currently-being-shaded fragment (rather than the one closest to the light source)</p>

<p>However, with shadow maps, you invariably get the first point that occludes the light, even if there are points behind it that also occlude the light.</p>

<p>I had originally intended to use volumetric rendering over shadow maps and use clever hashing for optimization.</p>

<p>But 800 triangles consume 90% of a GTX 1070's cpus power. In other words, just 800 triangle checks per fragment are enough to lag the entire pipeline.</p>

<p>I wanted to know if there is a way to get the distance to the closest point occluding the light (from the fragment perspective) using shadow maps. Or if I have to give away with my pretty shadows</p>

<p>Edit:</p>

<p>When I refer to distance I am speaking about distance from the occluded point to the light. So if A is a surface and R is the ray from that surface to the light, then the "closest" point is a point right on A and the "farthest" point is a point right on the light.</p>

<p>Edit:</p>

<p>As per request, a poorly drawn diagram of what I mean. There are 2 walls occluding the light and one is closer to the shadow point than the other</p>

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

CC BY-SA 3.0
2018-02-13T23:33:54.620Z
I don't quite understand how the last object information is helpful for standard shadow mapping. Isn't any element behind "first one" along direction from light source occluded? Can you explain what are you trying to achieve? Are you up to some kind of  transparency? If so then "depth peeling" might be the keyword.
mdkdy
CC BY-SA 3.0
2018-02-13T23:34:48.683Z
Can you clarify what's meant by "first" and "closest" here? Are you talking about closest distance to the light source, closest distance to the camera, or something else? A diagram might help. I'm having a hard time understanding the question.
Nathan Reed
CC BY-SA 3.0
2018-02-14T00:32:42.787Z
@narthex go outside on a sunny day and look at something casting a shadow, a tree, a car, a sign. Put your hand on the shadow and lift it up a couple centimeters, you will notice that there are 2 shadows now, one is your hand one is the bigger shadow of the object.
Makogan
CC BY-SA 3.0
2018-02-14T00:44:09.030Z
The latter shadow is caused by your hand blocking light from the rest of the sky, not from it extra-blocking light that the first object already blocked. The usual way to approximate that is with ambient occlusion, but I’d be interested to hear your approach.
Noah Witherspoon
CC BY-SA 3.0
2018-02-14T00:54:11.550Z
It's not light from the rest of the sky, as you have noticed when you go outside, shadows are not balck, this is because air refracts light so at all points in space there is residual  light rays bouncing on the air molecules, what we commonly know as "ambient ligth". When your hand is close to the ground it blocks a little more of these residual light rays, thus generating a second, darker, shadow. Taking this into consideration, if you know how far away you are from the object that last occluded the light from you, you can calculated a shadow intensity modifier.
Makogan
CC BY-SA 3.0
2018-02-14T08:38:01.440Z
If what you're after is simply the inversion of order, why not simply invert the depth test?
IneQuation
CC BY-SA 3.0
2018-02-14T09:58:42.230Z
Very interesting. I actually have been observing shadows like you said but to spot a phenomenon know as variable penumbra size - the longer distance from occluder to receiver, the bigger penumbra. You probably mean some Ambient Occlusion or Sky Occlusion.
mdkdy
CC BY-SA 3.0
2018-02-14T10:07:24.417Z
At some point, when distance is big, the shadow dissapears into blurriness. But it depends on light angular size.
mdkdy
<shadow><shading><shadow-mapping>
How can you efficiently get the last element occluding light when rendering shadows?
Makogan
# How can you efficiently get the last element occluding light when rendering shadows?

(Asked by: username_0 on 2018-02-13)

A long time ago I made an application that used volumetric rendering and I developed some shadowing equations that I felt very happy with, since they have pretty good results.

For these equations to work one needs the object that occludes the light that is closest to the currently-being-shaded fragment (rather than the one closest to the light source)

However, with shadow maps, you invariably get the first point that occludes the light, even if there are points behind it that also occlude the light.

I had originally intended to use volumetric rendering over shadow maps and use clever hashing for optimization.

But 800 triangles consume 90% of a GTX 1070's cpus power. In other words, just 800 triangle checks per fragment are enough to lag the entire pipeline.

I wanted to know if there is a way to get the distance to the closest point occluding the light (from the fragment perspective) using shadow maps. Or if I have to give away with my pretty shadows

Edit:

When I refer to distance I am speaking about distance from the occluded point to the light. So if A is a surface and R is the ray from that surface to the light, then the "closest" point is a point right on A and the "farthest" point is a point right on the light.

Edit:

As per request, a poorly drawn diagram of what I mean. There are 2 walls occluding the light and one is closer to the shadow point than the other

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

**Tags:** shadow, shading, shadow-mapping

> **Comments:**
> **username_1**: I don't quite understand how the last object information is helpful for standard shadow mapping. Isn't any element behind "first one" along direction from light source occluded? Can you explain what are you trying to achieve? Are you up to some kind of  transparency? If so then "depth peeling" might be the keyword.  
> **username_2**: Can you clarify what's meant by "first" and "closest" here? Are you talking about closest distance to the light source, closest distance to the camera, or something else? A diagram might help. I'm having a hard time understanding the question.  
> **username_0**: @narthex go outside on a sunny day and look at something casting a shadow, a tree, a car, a sign. Put your hand on the shadow and lift it up a couple centimeters, you will notice that there are 2 shadows now, one is your hand one is the bigger shadow of the object.  
> **username_3**: The latter shadow is caused by your hand blocking light from the rest of the sky, not from it extra-blocking light that the first object already blocked. The usual way to approximate that is with ambient occlusion, but I’d be interested to hear your approach.  
> **username_0**: It's not light from the rest of the sky, as you have noticed when you go outside, shadows are not balck, this is because air refracts light so at all points in space there is residual  light rays bouncing on the air molecules, what we commonly know as "ambient ligth". When your hand is close to the ground it blocks a little more of these residual light rays, thus generating a second, darker, shadow. Taking this into consideration, if you know how far away you are from the object that last occluded the light from you, you can calculated a shadow intensity modifier.  
> **username_4**: If what you're after is simply the inversion of order, why not simply invert the depth test?  
> **username_1**: Very interesting. I actually have been observing shadows like you said but to spot a phenomenon know as variable penumbra size - the longer distance from occluder to receiver, the bigger penumbra. You probably mean some Ambient Occlusion or Sky Occlusion.  
> **username_1**: At some point, when distance is big, the shadow dissapears into blurriness. But it depends on light angular size.  

---

## 0 answers

