#ifndef SHADOW_H #define SHADOW_H #include "common.hlsli" uniform sampler s_smap : register(ps, s0); // 2D/cube shadowmap #define KERNEL .6f ////////////////////////////////////////////////////////////////////////////////////////// // software ////////////////////////////////////////////////////////////////////////////////////////// float sample_sw(float2 tc, float2 shift, float depth_cmp) { static const float ts = KERNEL / float(SMAP_size); tc += shift * ts; float texsize = SMAP_size; float offset = 0.5f / texsize; float2 Tex00 = tc + float2(-offset, -offset); float2 Tex01 = tc + float2(-offset, offset); float2 Tex10 = tc + float2(offset, -offset); float2 Tex11 = tc + float2(offset, offset); float4 depth = float4( depth_cmp - tex2D(s_smap, Tex00).x, depth_cmp - tex2D(s_smap, Tex01).x, depth_cmp - tex2D(s_smap, Tex10).x, depth_cmp - tex2D(s_smap, Tex11).x); float4 compare = step(depth, 0.0f); float2 fr = frac(Tex00 * texsize); float2 ifr = float2(1.0f, 1.0f) - fr; float4 fr4 = float4(ifr.x * ifr.y, ifr.x * fr.y, fr.x * ifr.y, fr.x * fr.y); return dot(compare, fr4); } float shadow_sw(float4 tc) { float2 tc_dw = tc.xy / tc.w; float4 s; s.x = sample_sw(tc_dw, float2(-1, -1), tc.z); s.y = sample_sw(tc_dw, float2(+1, -1), tc.z); s.z = sample_sw(tc_dw, float2(-1, +1), tc.z); s.w = sample_sw(tc_dw, float2(+1, +1), tc.z); return dot(s, 1.h / 4.h); } ////////////////////////////////////////////////////////////////////////////////////////// // hardware + PCF ////////////////////////////////////////////////////////////////////////////////////////// float sample_hw_pcf(float4 tc, float4 shift) { static const float ts = KERNEL / float(SMAP_size); #ifndef SUNSHAFTS_DYNAMIC return tex2Dproj(s_smap, tc + tc.w * shift * ts).x; #else // SUNSHAFTS_DYNAMIC float4 tc2 = tc / tc.w + shift * ts; tc2.w = 0; return tex2Dlod(s_smap, tc2); #endif // SUNSHAFTS_DYNAMIC } float shadow_hw(float4 tc) { float s0 = sample_hw_pcf(tc, float4(-1.0f, -1.0f, 0.0f, 0.0f)); float s1 = sample_hw_pcf(tc, float4(+1.0f, -1.0f, 0.0f, 0.0f)); float s2 = sample_hw_pcf(tc, float4(-1.0f, +1.0f, 0.0f, 0.0f)); float s3 = sample_hw_pcf(tc, float4(+1.0f, +1.0f, 0.0f, 0.0f)); return (s0 + s1 + s2 + s3) / (4.h); } ////////////////////////////////////////////////////////////////////////////////////////// // hardware (ATI) + DF24/Fetch4 ////////////////////////////////////////////////////////////////////////////////////////// /* float sample_hw_f4 (float4 tc,float4 shift){ static const float ts = KERNEL / float(SMAP_size); float4 D4 = tex2Dproj (s_smap,tc + tc.w*shift*ts); float4 dcmp = tc.z/tc.w ; float4 cmp = dcmp