Projective Texturing
Edit: I forgot to add tags. I'm using DX11 & sharpdx
I've tried to mimic a sort of spotlight shadow technique but wasn't able to get that to work since there are pretty much no tutorials on shadows for deferred shading pipelines.
I fear, that you need a shadow mapping approach to solve this problem.The benefit of projective textures is, that you often don't need a shadow mapping approach (which makes it a lot slower), therefor my first tip would be, to accept the artefact and restrict the projection range (quantity vs quality). You've already implemented CSM and point light shadows, the principle is all the same:
Reconstruct the point in camera space and reproject it into the projection (shadow camera) space, then get the shadow value, if it is in shadow, discard the pixel. If it is not in shadow, use the xy shadowmap coord to access the projection texture.
float4 position = //bunch of code to reconstruct world space position from log depth
float4 decalPos = mul(position, DecalViewProjection);
float shadowDepth = ProjectorDepthMap.Sample(pointSampler, decalTexCoord.xy);
if(shadowDepth < decalPos.z / decalPos.w)
discard;
I agree that a Shadow-Mapping approach for Projective texturing is easier to get up&running faster. Plus, you will then be able to reuse parts of the pipeline for other stuff.
Before we had SM HW, we had to do projective texturing manually and it is truly a PITA to implement correctly and generally enough.
[attachment=14956:RuinValor 2013-04-17 19-33-24-01.png]
The projector camera is positioned approximately where the cursor is and is looking straight downwards. Ive changed the code from before slightly
float4 decalPos = mul(position, DecalViewProjection);
decalPos /= decalPos.w;
decalPos.xy = float2(decalPos.x, -decalPos.y) / 2.0f + 0.5f;
float shadowDepth = ProjectorDepthMap.Sample(pointSampler, decalPos.xy);
return float4(shadowDepth.rrr, 1);