#include "Defs.fxh" sampler2D TexSrc; sampler2D TexDepth; float4 BlurParams; row_major float3x4 ViewMatrix; row_major float4x4 ProjMatrix; row_major float4x4 OldViewProj; float4 NearFarZRange; float4 ScreenSize; float3 CameraPos; struct VSIn { float4 vPos : POSITION; float2 vTex0 : TEXCOORD0; }; struct VSOut { float4 vHPos : POSITION; float2 vTex0 : TEXCOORD0; float3 vViewRayWS : TEXCOORD1; // CS == camera space }; VSOut VShader(in VSIn IN) { VSOut OUT = (VSOut)0; IN.vPos.z=0; OUT.vHPos = IN.vPos; OUT.vTex0 = IN.vTex0; // fullscreen quad2d - liczymy w vs float3 view_ray = compute_view_ray(ProjMatrix, OUT.vHPos); float3 vWorldViewRay = mul(view_ray, (float3x3)ViewMatrix); OUT.vViewRayWS = vWorldViewRay; return OUT; } float4 PShader(in VSOut IN, float2 vPos: VPOS) : COLOR0 { float2 vScreenPos = get_screen_texcoord(vPos, ScreenSize); float fRefDepth; SampleDepth(TexDepth, vScreenPos, NearFarZRange, fRefDepth); float3 vWorldSpacePos = CameraPos.xyz + fRefDepth * IN.vViewRayWS; //return sin(vWorldSpacePos.xyzz*3.1415); float4 tc = mul(OldViewProj, float4(vWorldSpacePos, 1)); tc.xy /= tc.w; tc.x = 0.5 + 0.5 * tc.x; tc.y = 0.5 - 0.5 * tc.y; tc.xy += 0.5 * ScreenSize.zw; /* DEBUG float4 rv; rv.xy = sin(tc.xy*40); rv.z = Luminance(InputColor(tex2D(TexSrc, vScreenPos))); rv.w = 1; return rv; */ float4 ret=0; float2 v = tc - vScreenPos; float l = length(v) + 0.00001; float l_min = BlurParams.x; float l_max = BlurParams.y; float scale = BlurParams.z; // l_min=0.05; // l_max=0.5; float l_new = l - l_min; clip(l_new); if(l_new > l_max) l_new = l_max; v = v * (l_new / l * scale); float wgt=0; float wgts[3] = { 0, 3, 1 }; for(int i=1;i<3;i++) { ret += (tex2D(TexSrc, vScreenPos - v * i)) * wgts[i]; ret += (tex2D(TexSrc, vScreenPos + v * i)) * wgts[i]; wgt += 2*wgts[i]; } ret /= wgt; return (ret); } //DEVTEST_T(VShader, PShader)