Skip to content

Instantly share code, notes, and snippets.

@ArieLeo
Forked from aras-p/gist:dea83b8309a75554067c
Created December 22, 2015 06:28
Show Gist options
  • Save ArieLeo/49a83d9bbd74d0ddb1d9 to your computer and use it in GitHub Desktop.
Save ArieLeo/49a83d9bbd74d0ddb1d9 to your computer and use it in GitHub Desktop.
sampling shadowmap without comparison on d3d11
// Problem is that by default SamplerComparisonState sampler is coupled with the shadowmap.
// So if you want to sample it regularly, you'll have to find a suitable sampler from another used texture.
// For example, let's say _MainTex has a suitable sampler (set to bilinear, whatever).
UNITY_DECLARE_TEX2D(_MainTex); // will declare Texture2D _MainTex and SamplerState sampler_MainTex
UNITY_DECLARE_SHADOWMAP(_Myshadow); // will declare Texture2D _Myshadow and SamplerComparisonState sampler_Myshadow
// sample as a shadowmap with comparison (all platforms)
float s = UNITY_SAMPLE_SHADOW_PROJ(_Myshadow, float4(xy,depth,1.0));
// sample depth value without comparison
#ifdef SHADER_API_D3D11
float z = _Myshadow.Sample (sampler_MainTex, xy); // use sampler from _MainTex
#else
// well, something else on other platforms
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment