Access to Unity's Internal ShadowMaps

Hello folks!
Is it possible to access internal shadow maps (from directional light) in Unity 4.x Pro?
Maybe macros in CG shader may do that, or maybe some script solution, does any one know?

Check the AutoLight.cginc - that contains all the shadow and attenuation macros.

I’m sure you could grab the maps themselves at run time and pull them out to your own textures if you want.

Thank you for the advice Farfarer, will try to dig AutoLight.cginc first, i hope it helps.

Check the Internal-Prepasscollectshadows.shader, Shadow-Screenblur.shader and Shadow-ScreenBlurRotated.shader files for hints.
EDIT: Also, i never tried and im not on my work machine now, but you can also try “_ShadowMapTexture” property. Who knows it might work.

Have no success with AutoLight.cginc, I only able to access it’s lights’ color values and some other Light/Shadow parameters, not the Shadow Map directly, seems like they are only accessible in special “per light” render passes.

Thanks for the suggestion Aubergine, but I’ve not found the shadow map here too,
for example in Internal-Prepasscollectshadows.shader we have texture property like this:

Properties {
	_ShadowMapTexture ("", any) = "" {}
}

So shadow maps are assigned to this property from the outside by some code.
Shadow-Screenblur.shader and Shadow-ScreenBlurRotated.shader work like post filters for composed shadow pass, so they do not use any of shadow maps.

I also try to use “_ShadowMapTexture” but it returns just flat gray value in all channels.
When I’m using multi_compile_fwdadd_fullshadows or multi_compile_shadowcollector together with #include “AutoLight.cginc”, compilator says that “_ShadowMapTexture” is already declared in “AutoLight.cginc”, and when I cut my declaration out, it says that “_ShadowMapTexture” is undeclared.
Anyway “_ShadowMapTexture” seems like unusable standalone without any array index or light parent.

Do you have any suggestion on how this can be done?

I miss that too

I never messed with unity shadows before, but as i read the cg files, it looks very interesting. I will also try to mess with these and let you know if i get anything interesting.

But have you tried the UNITY_SAMPLE_SHADOW macro on the _ShadowMapTexture which was gray as you mentioned?

_ShadowMapTexture is “gray” most likely because it is depth texture :wink:
but yeah, you really need to read up these cginc files for pointers

Yes, I’ve tried that, but nothing special had happened.

I am understand that Shadow Map is a Depth Map, so that’s why I said “flat” gray, I have checked each channel of this map for any pixel difference, and yes, it is flat.
I am still reading cgincs and still searching for the solution, if you surely know that it is possible to get internal ShadowMaps(LightDepthMaps) as textures or samplers, can I ask you for more direct tips?

well, there is nothing special about shadow map - apart from it being bound automagically by the engine. So just use _ShadowMapTexture as your normal sampler. Well, sure, dont forget that it is not kinda your usual texture.
So, just start with unitySampleShadow, and do a full text search through cgincludes to get the understanding on where and how it is used.

Thanks for the tip and advices, Alexey.
I will dig it deeper!

HLSL Support
lines 48-63