// Warpedge video shader for VirtualDub, ps_1_1 version // Copyright (C) 2005 Avery Lee. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // desc x y z w float4 vd_vpsize; // viewport w h 1/h 1/w float4 vd_srcsize; // source size w h 1/h 1/w float4 vd_texsize; // source texture size w h 1/h 1/w float4 vd_tempsize; // temp texture size w h 1/h 1/w float4 vd_temp2size; // temp2 texture size w h 1/h 1/w float4 vd_vpcorrect2; // target screenspace xscale yscale yadd xadd float4 vd_tvpcorrect2; // temp screenspace xscale yscale yadd xadd float4 vd_t2vpcorrect2; // temp2 screenspace xscale yscale yadd xadd ////////////////////////////////////////////////////////////////////////// texture vd_srctexture; texture vd_temptexture; texture vd_temptexture2; ////////////////////////////////////////////////////////////////////////// texture disttexture < string function = "gendist"; int width = 64; int height = 64; >; float4 gendist(float2 texcoord : POSITION, float2 texelSize : PSIZE) : color0 { return length(texcoord - 0.5) * 2; } texture nrmtexture < string function = "gennrm"; int width = 64; int height = 64; >; float4 gennrm(float2 texcoord : POSITION, float2 texelSize : PSIZE) : color0 { float len = length(texcoord - 0.49999); return float4(1, (texcoord - 0.5) * min(1.0, 5.0 / len) + 0.5, 0); } ////////////////////////////////////////////////////////////////////////// struct VertexInput { float4 pos : POSITION; float2 uv : TEXCOORD0; float2 uv2 : TEXCOORD1; }; struct VertexGrad { float4 pos : POSITION; float2 uv0 : TEXCOORD0; float2 uv1 : TEXCOORD1; float2 uv2 : TEXCOORD2; float2 uv3 : TEXCOORD3; }; struct VertexNorm { float4 pos : POSITION; float2 uv : TEXCOORD0; }; VertexGrad VSgrad1(VertexInput IN) { VertexGrad OUT; float2 pos = IN.uv2 * vd_vpsize.xy; OUT.pos.xy = pos * -vd_tvpcorrect2.yx - vd_tvpcorrect2.zw; OUT.pos.zw = float2(0, 1); float2 uv = IN.uv2 * vd_srcsize.xy * vd_texsize.wz; OUT.uv0.x = uv.x - vd_texsize.w * 0.5; OUT.uv0.y = uv.y - vd_texsize.z * 0.5; OUT.uv1.x = uv.x + vd_texsize.w * 0.5; OUT.uv1.y = uv.y - vd_texsize.z * 0.5; OUT.uv2.x = uv.x - vd_texsize.w * 0.5; OUT.uv2.y = uv.y + vd_texsize.z * 0.5; OUT.uv3.x = uv.x + vd_texsize.w * 0.5; OUT.uv3.y = uv.y + vd_texsize.z * 0.5; return OUT; } VertexNorm VSnorm1(VertexInput IN) { VertexNorm OUT; float2 pos = IN.uv2 * vd_vpsize.xy; OUT.pos.xy = pos * -vd_t2vpcorrect2.yx - vd_t2vpcorrect2.zw; OUT.pos.zw = float2(0, 1); float2 uv = pos * vd_tempsize.wz; OUT.uv = uv; return OUT; } struct VertexBlur { float4 pos : POSITION; float2 uv0 : TEXCOORD0; float2 uv1 : TEXCOORD1; float2 uv2 : TEXCOORD2; float2 uv3 : TEXCOORD3; }; VertexBlur VSblur(VertexInput IN) { VertexBlur OUT; OUT.pos.xy = IN.uv2 * vd_vpsize.xy * -vd_tvpcorrect2.yx - vd_tvpcorrect2.zw; OUT.pos.zw = float2(0, 1); float2 uv = IN.uv2 * vd_vpsize.xy * vd_temp2size.wz; OUT.uv0 = uv + float2(-0.5, -0.5) * vd_temp2size.wz; OUT.uv1 = uv + float2(+0.5, -0.5) * vd_temp2size.wz; OUT.uv2 = uv + float2(-0.5, +0.5) * vd_temp2size.wz; OUT.uv3 = uv + float2(+0.5, +0.5) * vd_temp2size.wz; return OUT; } VertexGrad VSgrad2(VertexInput IN) { VertexGrad OUT; float2 pos = IN.uv2 * vd_vpsize.xy; OUT.pos.xy = pos * -vd_t2vpcorrect2.yx - vd_t2vpcorrect2.zw; OUT.pos.zw = float2(0, 1); float2 uv = pos * vd_tempsize.wz; OUT.uv0.x = uv.x - vd_tempsize.w * 0.5; OUT.uv0.y = uv.y; OUT.uv1.x = uv.x + vd_tempsize.w * 0.5; OUT.uv1.y = uv.y; OUT.uv2.x = uv.x; OUT.uv2.y = uv.y - vd_tempsize.z * 0.5; OUT.uv3.x = uv.x; OUT.uv3.y = uv.y + vd_tempsize.z * 0.5; return OUT; } VertexNorm VSnorm2(VertexInput IN) { VertexNorm OUT; float2 pos = IN.uv2 * vd_vpsize.xy; OUT.pos.xy = pos * -vd_tvpcorrect2.yx - vd_tvpcorrect2.zw; OUT.pos.zw = float2(0, 1); float2 uv = pos * vd_temp2size.wz; OUT.uv = uv; return OUT; } struct VertexFinal { float4 pos : POSITION; float2 uv0 : TEXCOORD0; float3 uv1 : TEXCOORD1; float3 uv2 : TEXCOORD2; float2 uv3 : TEXCOORD3; }; static const float xfactor = -0.5; static const float yfactor = -0.5; VertexFinal VSfinal(VertexInput IN) { VertexFinal OUT; OUT.pos.xy = IN.uv2 * vd_vpsize.xy * vd_vpcorrect2.xy + vd_vpcorrect2.wz; OUT.pos.zw = float2(0, 1); float2 uv = (IN.uv2 * vd_vpsize.xy) * vd_tempsize.wz; OUT.uv0 = uv; OUT.uv1 = float3(IN.uv.x - 0.5 * xfactor*vd_texsize.w, vd_texsize.w*xfactor, 0); OUT.uv2 = float3(IN.uv.y - 0.5 * yfactor*vd_texsize.z, 0, vd_texsize.z*yfactor); OUT.uv3 = IN.uv; return OUT; } struct VertexDirect { float4 pos : POSITION; float2 uv : TEXCOORD0; }; VertexDirect VSdirect(VertexInput IN) { VertexDirect OUT; OUT.pos.xy = IN.uv2 * vd_vpsize.xy * vd_vpcorrect2.xy + vd_vpcorrect2.wz; OUT.pos.zw = float2(0, 1); OUT.uv = IN.uv; return OUT; } /////////////////////////////////////////////////////////////////////////// technique point { pass p0 { VertexShader = compile vs_1_1 VSdirect(); PixelShader = asm { ps_1_1 tex t0 mov r0, t0 }; Texture[0] = ; AddressU[0] = clamp; AddressV[0] = clamp; Minfilter[0] = point; Magfilter[0] = point; } } technique bilinear { pass p0 { VertexShader = compile vs_1_1 VSdirect(); PixelShader = asm { ps_1_1 tex t0 mov r0, t0 }; Texture[0] = ; AddressU[0] = clamp; AddressV[0] = clamp; Minfilter[0] = linear; Magfilter[0] = linear; } } technique bicubic { pass p0 < string vd_target = "temp"; > { VertexShader = compile vs_1_1 VSgrad1(); PixelShader = asm { ps_1_1 def c0, 0.30, 0.59, 0.11, 0 def c1, 0, 0, 1, 0.5 def c2, 0, 1, 0, 0 tex t0 tex t1 tex t2 tex t3 add r0, -t0, t3 add r1, -t1, t2 dp3 r0, r0, c0 dp3 r1, r1, c0 add r0.rgb, r0.a, r1.a add r1.rgb, r0.a, -r1.a mad r0, r0, c1, c1.a mad r0, r1, c2, r0 }; Texture[0] = ; AddressU[0] = clamp; AddressV[0] = clamp; MinFilter[0] = linear; MagFilter[0] = linear; Texture[1] = ; AddressU[1] = clamp; AddressV[1] = clamp; MinFilter[1] = linear; MagFilter[1] = linear; Texture[2] = ; AddressU[2] = clamp; AddressV[2] = clamp; MinFilter[2] = linear; MagFilter[2] = linear; Texture[3] = ; AddressU[3] = clamp; AddressV[3] = clamp; MinFilter[3] = linear; MagFilter[3] = linear; } pass p1 < string vd_target = "temp2"; > { VertexShader = compile vs_1_1 VSnorm1(); PixelShader = asm { ps_1_1 tex t0 texreg2gb t1, t0 mov r0, t1 }; Texture[0] = ; MinFilter[0] = point; MagFilter[0] = point; Texture[1] = ; } pass p2 < string vd_target = "temp"; > { VertexShader = compile vs_1_1 VSblur(); PixelShader = asm { ps_1_1 tex t0 tex t1 tex t2 tex t3 add_d2 r0, t0, t1 add_d2 r1, t2, t3 add_d2 r0, r0, r1 }; Texture[0] = ; MinFilter[0] = linear; MagFilter[0] = linear; Texture[1] = ; Texture[2] = ; Texture[3] = ; } pass p3 < string vd_target = "temp2"; > { VertexShader = compile vs_1_1 VSgrad2(); PixelShader = asm { ps_1_1 def c1, 0, 1, 0, 0 def c2, 0, 0, 1, 0 def c3, 1, 0.5, 0.5, 0 tex t0 tex t1 tex t2 tex t3 add_x2 r0, t1, -t0 add_x2 r1, t3, -t2 mad r0, r0, c1, c3 mad r0, r1, c2, r0 }; Texture[0] = ; Texture[1] = ; Texture[2] = ; Texture[3] = ; } pass p4 < string vd_target = "temp"; > { VertexShader = compile vs_1_1 VSnorm2(); PixelShader = asm { ps_1_1 tex t0 texreg2gb t1, t0 mov r0, t1 }; Texture[0] = ; MinFilter[0] = point; MagFilter[0] = point; Texture[1] = ; } pass p5 < string vd_target = ""; > { VertexShader = compile vs_1_1 VSfinal(); PixelShader = asm { ps_1_1 tex t0 texm3x2pad t1, t0 texm3x2tex t2, t0 tex t3 add r0, t2, -t3 add r0, r0, t2 }; Texture[0] = ; MinFilter[0] = linear; MagFilter[0] = linear; Texture[1] = ; MinFilter[1] = linear; MagFilter[1] = linear; Texture[2] = ; MinFilter[2] = linear; MagFilter[2] = linear; Texture[3] = ; MinFilter[3] = linear; MagFilter[3] = linear; } }