That step is only necessary if it isn't sufficient to use the depth as-is, as written by the output merger into the depth-stencil target, or if you need to cut holes into your geometry (alpha-testing), for example. Either way, the colour output isn't important in our case.
Depth shadow mapping question
Hi, DividedByZero, I took a look at you project and was able to get the shadows working.
The main issue seems to be in vs_shadow.hlsl, lines 43-45:
output.lightViewPosition = mul(input.position, matWorld);
output.lightViewPosition = mul(output.position, matLightView);
output.lightViewPosition = mul(output.position, matLightProjection);
Instead of output.position it should really be output.lightViewPosition. Otherwise you're not getting a correct light-space position in the corresponding fragment shader; looks like a copy-paste error.
However, I also had to move the camera
float camX = 10.0f;
float camY = 5.0f;
float camZ = -3.0f;
and increase the width and height of the light's ortho projection to get this result.
EDIT: was looking back through the thread and saw that blicili already pointed this out a while ago:)
@dietrich good catch! I went through that shader several times and just didn't see the copy-pasta at midnight
@pcmaster, haha, getting there took me way longer than I like to admit:)
Oh man, you guys are absolute legends.
output.lightViewPosition = mul(output.lightViewPosition, matLightView);
output.lightViewPosition = mul(output.lightViewPosition, matLightProjection);
A two line change and it worked.
Yeah, I knew the light camera would need some tweaking and anticipated a close up cut out, which happened with my default positioning. So that's cool.
I don't know how many times I looked at that shader trying various things. Even double and triple checking those calculations.
I rewrote the project from scratch four times being extremely meticulous as to what each step did. Yes, a bit of copy/paste of code that I was sure was working having scrutinised each line. LOL.
If nothing else, I understand each individual step a hell of a lot more than I would have if it worked first time. SO there is always a bright side.
Thanks once again, it is truly huge of you guys (and everyone who helped out).