Projective Texturing

Started by
5 comments, last by riuthamus 10 years, 11 months ago
I'm trying to implement projective texturing but I'm having some trouble getting it to a usable state. Right now it works but it projects to infinity (or more specifically, to the far plane). I can't just pull back the far plane because it could result in the texture being cut off on steep surfaces, and wouldn't solve the problem of projecting through surfaces. 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. So, my question: How do you get a projective texture to stop at the first surface it hits?


Edit: I forgot to add tags. I'm using DX11 & sharpdx
Advertisement

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.

That's what I figured but I wasn't able to get it to work. It just considers everything to be out of the shadow.

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.

VladR My 3rd person action RPG on GreenLight: http://steamcommunity.com/sharedfiles/filedetails/?id=92951596

I found part of the problem was from me using the ViewProjection matrix from the wrong camera but now there seems to be an issue with the sampling coordinates for the projection depth map being wrong.

[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);

Yeah that certainly does look off. Anybody else got any ideas on this?

One last shameless bump... we still do not have this figured out.

This topic is closed to new replies.

Advertisement