5
\$\begingroup\$

I'm writing a custom shader in unity 5 that requires a shadowmap (not just for drawing shadows but also for different computations involving scattering particles through fog). Does anybody know how to actually get the shadow map in unity rather than just using the fallback option? That is including the actual Z buffer not just the resulting 1's and 0's.

I could also use the depth buffer from the camera but that only appears to apply to camera used by the player rather than the second one I can add to replace the light (inside the light).

\$\endgroup\$
2
  • \$\begingroup\$ Maybe this Helps: alastaira.wordpress.com/2014/12/30/… \$\endgroup\$ Mar 10, 2015 at 13:51
  • \$\begingroup\$ That uses the LIGHT_ATTENUATION which automatically samples if something is within the light but does not actually give the Z values of the shadowmap. \$\endgroup\$
    – Thijser
    Mar 10, 2015 at 15:57

1 Answer 1

5
+50
\$\begingroup\$

In the Unity docs under shader references.

Shadow mapping macros

Declaring and sampling shadow maps can be very different depending on the platform, so Unity has several macros to help with that:

UNITY_DECLARE_SHADOWMAP(tex) - declares a shadowmap texture variable with name “tex”.
UNITY_SAMPLE_SHADOW(tex,uv) - samples shadowmap texture “tex” at given “uv” coordinate (XY components are texture location, Z component is depth to compare with). Returns single float value with the shadow term in 0..1 range.
UNITY_SAMPLE_SHADOW_PROJ(tex,uv) - similar to above, but does a projective shadowmap read. “uv” is a float4, all other components are divided by .w for doing the lookup.
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .