#include "Defs.fxh" #ifdef _XBOX #undef _ZTEST_HW #endif float4 ScreenSize; float4 NearFarZRange; float4 Viewport; sampler2D TexDepth; sampler2D TexFlares; float SampleDepth_Wrapper(sampler2D tex_depth, float2 tc, float test_depth, float4 z_info) { // BORDER mi nie dziaƂa :( if(tc.x < 0 || tc.y < 0 || tc.x > 1 || tc.y > 1) return 0; else { #ifdef _ZTEST_HW test_depth = EncodeNativeDepth(test_depth, z_info); // test_depth = (test_depth + 1.) / 2.; #ifdef _PS3 return tex2D(tex_depth, float3(tc * Viewport.xy + Viewport.zw, test_depth)).x; #else return tex2Dlod(tex_depth, float4(tc * Viewport.xy + Viewport.zw, test_depth, 0)).x; #endif #else float fDepth = tex2Dlod(tex_depth, float4(tc * Viewport.xy + Viewport.zw,0,0)).x; #ifdef _NATIVEDEPTH fDepth = DecodeNativeDepth(fDepth, z_info); #endif return fDepth; #endif } } /* . . . . o . . . . . . . . . . . . . . . . o . o . . . . . o . o . o . . . . . o X o . . . . . o . o . o . . . . . o . o . . . . o . . . . . o . . . . . . . . . . */ float ComputeOcclusion(float2 uv, float test_z) { #ifdef _ZTEST_PRECOMPUTED return tex2Dlod(TexFlares, float4(uv,0,0)); #else float2 offsets[] = { float2( 0, 0), float2( 1, 0), float2(-1, 0), float2( 0, 1), float2( 0,-1), float2( 1,-2), float2( 1, 2), float2(-1,-2), float2(-1, 2), float2(-2, 1), float2( 2, 1), float2(-2,-1), float2( 2,-1), float2( 3, 3), float2( 3,-3), float2(-3, 0), }; float occlusion = 0; for(int i=0;i<16;i+=4) { float4 screen_z; screen_z.r = SampleDepth_Wrapper(TexDepth, uv + ScreenSize.zw * offsets[i+0]*2, test_z, NearFarZRange); screen_z.g = SampleDepth_Wrapper(TexDepth, uv + ScreenSize.zw * offsets[i+1]*2, test_z, NearFarZRange); screen_z.b = SampleDepth_Wrapper(TexDepth, uv + ScreenSize.zw * offsets[i+2]*2, test_z, NearFarZRange); screen_z.a = SampleDepth_Wrapper(TexDepth, uv + ScreenSize.zw * offsets[i+3]*2, test_z, NearFarZRange); #ifndef _ZTEST_HW screen_z = screen_z > test_z; #endif occlusion += dot(screen_z, 1./16.); } return occlusion; #endif } void VShader_flare(in float4 pos: POSITION, out float4 opos: POSITION, out float3 z_test: TEXCOORD0) { opos = float4(pos.x * 2. - 1., 0, 0, 1); z_test = pos.yzw; } float4 PShader_flare(in float3 z_test: TEXCOORD0): COLOR { return ComputeOcclusion(z_test.xy, z_test.z - 0.1); }