Shadow mapping at different heights?

Hi,

I’m working on implementing a shadow mapping solution, which I’m using as a “line of sight”. I basically use the same technic as shadow mapping to display what the enemy sees.
So far, this works great.

Now, I would like to represent what the enemy would see for a specific height: for example, if an object makes a height of 1, display where it would be visible from the enemy.

I tried to do this by modifying the shadow maps algorithm, by rendering the world position with + 1:

half4 FragOrtho (VertexOut i) : COLOR
        {
            float4 positionWorld = OrthoGraphicDepthToWorldPosition(i);
              float visible = 0.0;

              positionWorld.y += 1.0;
              visible += CalculateVisibility(positionWorld);
            return GenerateMask(visible);
        }

My problem is that it’s “bleeding” on other objects, and I don’t know how I can fix this.

Here is the code which is computing the visibility:

float CalculateVisibility(float4 pixelWorldPos)
        {
            // Calculate distance to source in range[0 - far plane]
            float sourceDistance = distance(pixelWorldPos.xyz, _SourceInfo.xyz);

            // Convert world space to LOS cam depth texture UV's
            float4 sourcePos = mul(_SourceWorldProj, pixelWorldPos);


            float3 sourceNDC = sourcePos.xyz / sourcePos.w;

            // Clip pixels outside of source
            clip(max(min(sourcePos.w, 1 - abs(sourceNDC.x)), _Settings.w - 0.5));

            // Convert from NDC to UV
            float2 sourceUV = sourceNDC.xy;
            sourceUV *= 0.5f;
            sourceUV += 0.5f;

            // VSM
            float2 moments = tex2D(_SourceDepthTex, sourceUV).rg;
            //moments.y = moments.y - 1;

            float visible = ChebyshevUpperBound(moments, sourceDistance, _Settings.z);

            // Handle vertical out of bound pixels
            visible += _Flags.x * _Flags.y * (1 - step(abs(sourceNDC.y), 1.0));
            visible = saturate(visible);

            // Ignore pixels behind source
            visible *= step(-sourcePos.w, 0);

            // Calculate fading
            float edgeFade = CalculateFade(abs(sourceNDC.x), _Settings.y);
            float distanceFade = CalculateFade(sourceDistance / _SourceInfo.w, _Settings.x);

            // Apply fading
            visible *= distanceFade;
            visible *= edgeFade;

            return visible;
        }

I think I would need to modify something there to take into account the +1 on the world pos, but I can’t find where…
Any idea for someone good at maths? :slight_smile:

Here is my current result, as you can see the back of the wall shouldn’t be green:

So this is way above my knowledge base as an artist although I know the logic for shadow maps. So Ill give this a shot
Not sure about the height thing, but for the bleeding - couldnt the polygon normals be read on the surface detected. If the normal of the polygon is facing the shadow caster, and the shader is opaque the shadow map ends at that polygon - does not travel further in that direction.

That could be a solution yes. but I think there’s a mistake in my equation, because when I don’t add the “height”, the visible pixels are right and it does not bleed.