home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / Riza / source / displaydx9_ff.fxh < prev    next >
Encoding:
Text File  |  2009-09-14  |  10.2 KB  |  387 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    A/V interface library
  3. //    Copyright (C) 1998-2008 Avery Lee
  4. //
  5. //    This program is free software; you can redistribute it and/or modify
  6. //    it under the terms of the GNU General Public License as published by
  7. //    the Free Software Foundation; either version 2 of the License, or
  8. //    (at your option) any later version.
  9. //
  10. //    This program is distributed in the hope that it will be useful,
  11. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. //    GNU General Public License for more details.
  14. //
  15. //    You should have received a copy of the GNU General Public License
  16. //    along with this program; if not, write to the Free Software
  17. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. #ifndef DISPLAYDX9_FF_FXH
  20. #define DISPLAYDX9_FF_FXH
  21.  
  22. #define FF_STAGE(n, ca1, cop, ca2, aa1, aop, aa2)    \
  23.     ColorOp[n] = cop;    \
  24.     ColorArg1[n] = ca1;    \
  25.     ColorArg2[n] = ca2;    \
  26.     AlphaOp[n] = aop;    \
  27.     AlphaArg1[n] = aa1;    \
  28.     AlphaArg2[n] = aa2
  29.  
  30. #define FF_STAGE_DISABLE(n)    \
  31.     ColorOp[n] = Disable;    \
  32.     AlphaOp[n] = Disable
  33.  
  34. ////////////////////////////////////////////////////////////////////////////////
  35. technique point {
  36.     pass p0 <
  37.         bool vd_clippos = true;
  38.     > {
  39.         FF_STAGE(0, Texture, SelectArg1, Diffuse, Texture, SelectArg1, Diffuse);
  40.         FF_STAGE_DISABLE(1);
  41.         FF_STAGE_DISABLE(2);
  42.         MinFilter[0] = Point;
  43.         MagFilter[0] = Point;
  44.         MipFilter[0] = Point;
  45.         AddressU[0] = Clamp;
  46.         AddressV[0] = Clamp;
  47.         Texture[0] = <vd_srctexture>;
  48.         AlphaBlendEnable = false;
  49.     }
  50. }
  51.  
  52. ////////////////////////////////////////////////////////////////////////////////
  53. technique bilinear {
  54.     pass p0 <
  55.         bool vd_clippos = true;
  56.     > {
  57.         FF_STAGE(0, Texture, SelectArg1, Diffuse, Texture, SelectArg1, Diffuse);
  58.         FF_STAGE_DISABLE(1);
  59.         FF_STAGE_DISABLE(2);
  60.         MinFilter[0] = Linear;
  61.         MagFilter[0] = Linear;
  62.         MipFilter[0] = Linear;
  63.         AddressU[0] = Clamp;
  64.         AddressV[0] = Clamp;
  65.         Texture[0] = <vd_srctexture>;
  66.         AlphaBlendEnable = false;
  67.     }
  68. }
  69.  
  70. ////////////////////////////////////////////////////////////////////////////////
  71.  
  72. struct VertexOutputBicubicFF2 {
  73.     float4    pos        : POSITION;
  74.     float4    diffuse    : COLOR0;
  75.     float2    uvsrc    : TEXCOORD0;
  76.     float2    uvfilt    : TEXCOORD1;
  77. };
  78.  
  79. VertexOutputBicubicFF2 VertexShaderBicubicFF2A(VertexInput IN, uniform float srcu, uniform float filtv) {
  80.     VertexOutputBicubicFF2 OUT;
  81.     
  82.     OUT.pos = IN.pos;
  83.     OUT.diffuse = float4(0.5f, 0.5f, 0.5f, 0.25f);
  84.     OUT.uvfilt.x = -0.125f + IN.uv2.x * vd_srcsize.x * 0.25f;
  85.     OUT.uvfilt.y = filtv;
  86.     OUT.uvsrc = IN.uv + float2(srcu, vd_fieldinfo.y)*vd_texsize.wz;
  87.  
  88.     return OUT;
  89. }
  90.  
  91. VertexOutputBicubicFF2 VertexShaderBicubicFF2B(VertexInput IN, uniform float srcv, uniform float filtv) {
  92.     VertexOutputBicubicFF2 OUT;
  93.     
  94.     OUT.pos = IN.pos;
  95.     OUT.diffuse = float4(1, 1, 1, 1);
  96.     OUT.uvfilt.x = -0.125f + IN.uv2.y * vd_srcsize.y * 0.25f;
  97.     OUT.uvfilt.y = filtv;
  98.     OUT.uvsrc = (IN.uv2*float2(vd_vpsize.x, vd_srcsize.y) + float2(0, srcv))*vd_tempsize.wz;
  99.  
  100.     return OUT;
  101. }
  102.  
  103. struct VertexOutputBicubicFF2C {
  104.     float4    pos        : POSITION;
  105.     float4    diffuse    : COLOR0;
  106.     float2    uvsrc    : TEXCOORD0;
  107. };
  108.  
  109. VertexOutputBicubicFF2C VertexShaderBicubicFF2C(VertexInput IN) {
  110.     VertexOutputBicubicFF2C OUT;
  111.     
  112.     OUT.pos = IN.pos;
  113.     OUT.diffuse = float4(0.25f, 0.25f, 0.25f, 0.25f);
  114.     OUT.uvsrc = IN.uv2 * vd_vpsize.xy * vd_temp2size.wz;
  115.  
  116.     return OUT;
  117. }
  118.  
  119. technique bicubicFF2 {
  120.     pass h0 <
  121.         string vd_target = "temp";
  122.         string vd_viewport = "out, src";
  123.     > {
  124.         VertexShader = compile vs_1_1 VertexShaderBicubicFF2A(-0.5f, 0.375f);
  125.  
  126.         Texture[0] = <vd_srctexture>;
  127.         TexCoordIndex[0] = 0;
  128.         AddressU[0] = Clamp;
  129.         AddressV[0] = Clamp;
  130.         MagFilter[0] = Point;
  131.         MinFilter[0] = Point;
  132.         MipFilter[0] = Point;
  133.         
  134.         Texture[1] = <vd_cubictexture>;
  135.         TexCoordIndex[1] = 1;
  136.         AddressU[1] = Wrap;
  137.         AddressV[1] = Wrap;
  138.         MagFilter[1] = Point;
  139.         MinFilter[1] = Point;
  140.         MipFilter[1] = Point;
  141.         
  142.         FF_STAGE(0, Texture, MultiplyAdd, Diffuse, Texture, Modulate, Diffuse);
  143.         ColorArg0[0] = Diffuse | AlphaReplicate;
  144.         
  145.         FF_STAGE(1, Current, Modulate, Texture, Current, Modulate, Texture);
  146.         
  147.         FF_STAGE_DISABLE(2);
  148.         
  149.         AlphaBlendEnable = false;
  150.         DitherEnable = false;
  151.     }
  152.     
  153.     pass h1 {
  154.         VertexShader = compile vs_1_1 VertexShaderBicubicFF2A(+0.5f, 0.625f);
  155.         
  156.         AlphaBlendEnable = true;
  157.         SrcBlend = One;
  158.         DestBlend = One;
  159.         BlendOp = Add;
  160.     }
  161.     
  162.     pass h2 {
  163.         VertexShader = compile vs_1_1 VertexShaderBicubicFF2A(-1.5f, 0.125f);
  164.         
  165.         BlendOp = RevSubtract;
  166.     }
  167.     
  168.     pass h3 {
  169.         VertexShader = compile vs_1_1 VertexShaderBicubicFF2A(+1.5f, 0.875f);
  170.     }
  171.     
  172.     pass v0 <
  173.         string vd_target = "temp2";
  174.         string vd_viewport = "out, out";
  175.     > {
  176.         VertexShader = compile vs_1_1 VertexShaderBicubicFF2B(-0.5f, 0.375f);
  177.         
  178.         FF_STAGE(0, Texture, SelectArg1, Diffuse, Texture, Add, Texture);
  179.         FF_STAGE(1, Texture, Modulate, Current, Texture, Modulate, Current);
  180.         
  181.         Texture[0] = <vd_temptexture>;
  182.         
  183.         AlphaBlendEnable = false;
  184.     }
  185.     
  186.     pass v1 {
  187.         VertexShader = compile vs_1_1 VertexShaderBicubicFF2B(+0.5f, 0.625f);
  188.                 
  189.         AlphaBlendEnable = true;
  190.         BlendOp = Add;
  191.     }
  192.     
  193.     pass v2 {
  194.         VertexShader = compile vs_1_1 VertexShaderBicubicFF2B(-1.5f, 0.125f);
  195.         BlendOp = RevSubtract;
  196.     }
  197.     
  198.     pass v3 {
  199.         VertexShader = compile vs_1_1 VertexShaderBicubicFF2B(+1.5f, 0.875f);
  200.     }
  201.     
  202.     pass final <
  203.         string vd_target = "";
  204.     > {
  205.         VertexShader = compile vs_1_1 VertexShaderBicubicFF2C();
  206.         
  207.         FF_STAGE(0, Texture, AddSigned2x, Current, Texture, AddSigned2x, Current);
  208.         FF_STAGE_DISABLE(1);
  209.             
  210.         Texture[0] = <vd_temp2texture>;
  211.         
  212.         AlphaBlendEnable = false;
  213.         DitherEnable = true;
  214.     }
  215. }
  216.  
  217. ////////////////////////////////////////////////////////////////////////////////////////////////////
  218. //
  219. //    Fixed function bicubic path - 3 texture stages, 5 passes (ATI RADEON 7xxx)
  220. //
  221. ////////////////////////////////////////////////////////////////////////////////////////////////////
  222.  
  223. struct VertexOutputBicubicFF3 {
  224.     float4    pos        : POSITION;
  225.     float2    uvsrc0    : TEXCOORD0;
  226.     float2    uvfilt    : TEXCOORD1;
  227.     float2    uvsrc1    : TEXCOORD2;
  228. };
  229.  
  230. VertexOutputBicubicFF3 VertexShaderBicubicFF3A(VertexInput IN) {
  231.     VertexOutputBicubicFF3 OUT;
  232.     
  233.     OUT.pos = IN.pos;
  234.     OUT.uvfilt.x = -0.125f + IN.uv2.x * vd_srcsize.x * 0.25f;
  235.     OUT.uvfilt.y = 0.625f;
  236.     OUT.uvsrc0 = IN.uv + float2(-1.5f, vd_fieldinfo.y)*vd_texsize.wz;
  237.     OUT.uvsrc1 = IN.uv + float2(+1.5f, vd_fieldinfo.y)*vd_texsize.wz;
  238.  
  239.     return OUT;
  240. }
  241.  
  242. VertexOutputBicubicFF3 VertexShaderBicubicFF3B(VertexInput IN) {
  243.     VertexOutputBicubicFF3 OUT;
  244.     
  245.     OUT.pos = IN.pos;
  246.     OUT.uvfilt.x = -0.125f + IN.uv2.x * vd_srcsize.x * 0.25f;
  247.     OUT.uvfilt.y = 0.875f;
  248.     OUT.uvsrc0 = IN.uv + float2(-0.5f, vd_fieldinfo.y)*vd_texsize.wz;
  249.     OUT.uvsrc1 = IN.uv + float2(+0.5f, vd_fieldinfo.y)*vd_texsize.wz;
  250.     
  251.     return OUT;
  252. }
  253.  
  254. VertexOutputBicubicFF3 VertexShaderBicubicFF3C(VertexInput IN) {
  255.     VertexOutputBicubicFF3 OUT;
  256.     
  257.     OUT.pos = IN.pos;
  258.     OUT.uvfilt.x = -0.125f + IN.uv2.y * vd_srcsize.y * 0.25f;
  259.     OUT.uvfilt.y = 0.125f;
  260.     
  261.     float2 uv = IN.uv2 * float2(vd_vpsize.x, vd_srcsize.y) * vd_tempsize.wz;
  262.     OUT.uvsrc0 = uv + float2(0, -1.5f)*vd_tempsize.wz;
  263.     OUT.uvsrc1 = uv + float2(0, +1.5f)*vd_tempsize.wz;
  264.     
  265.     return OUT;
  266. }
  267.  
  268. VertexOutputBicubicFF3 VertexShaderBicubicFF3D(VertexInput IN) {
  269.     VertexOutputBicubicFF3 OUT;
  270.     
  271.     OUT.pos = IN.pos;
  272.     OUT.uvfilt.x = -0.125f + IN.uv2.y * vd_srcsize.y * 0.25f;
  273.     OUT.uvfilt.y = 0.375f;
  274.     
  275.     float2 uv = IN.uv2 * float2(vd_vpsize.x, vd_srcsize.y) * vd_tempsize.wz;
  276.     OUT.uvsrc0 = uv + float2(0, -0.5f)*vd_tempsize.wz;
  277.     OUT.uvsrc1 = uv + float2(0,  0.5f)*vd_tempsize.wz;
  278.     
  279.     return OUT;
  280. }
  281.  
  282. struct VertexOutputBicubicFF3E {
  283.     float4    pos        : POSITION;
  284.     float2    uv        : TEXCOORD0;
  285. };
  286.  
  287. VertexOutputBicubicFF3E VertexShaderBicubicFF3E(VertexInput IN) {
  288.     VertexOutputBicubicFF3E OUT;
  289.     
  290.     OUT.pos = IN.pos;
  291.     OUT.uv = IN.uv*vd_vpsize.xy*vd_temp2size.wz;
  292.     
  293.     return OUT;
  294. }
  295.  
  296. technique bicubicFF3 {
  297.     pass horiz1 <
  298.         string vd_target = "temp";
  299.         string vd_viewport = "out, src";
  300.         float4 vd_clear = float4(0.5f, 0.5f, 0.5f, 0.5f);
  301.     > {
  302.         VertexShader = compile vs_1_1 VertexShaderBicubicFF3A();
  303.         
  304.         Texture[0] = <vd_srctexture>;
  305.         AddressU[0] = Clamp;
  306.         AddressV[0] = Clamp;
  307.         MagFilter[0] = Point;
  308.         MinFilter[0] = Point;
  309.         MipFilter[0] = Point;
  310.  
  311.         Texture[1] = <vd_cubictexture>;
  312.         AddressU[1] = Wrap;
  313.         AddressV[1] = Wrap;
  314.         MagFilter[1] = Point;
  315.         MinFilter[1] = Point;
  316.         MipFilter[1] = Point;
  317.  
  318.         Texture[2] = <vd_srctexture>;
  319.         AddressU[2] = Clamp;
  320.         AddressV[2] = Clamp;
  321.         MagFilter[2] = Point;
  322.         MinFilter[2] = Point;
  323.         MipFilter[2] = Point;
  324.  
  325.         FF_STAGE(0, Texture, SelectArg1, Current, Texture, SelectArg1, Current);
  326.         FF_STAGE(1, Texture, Modulate, Current, Texture, SelectArg1, Current);
  327.         FF_STAGE(2, Current, ModulateAlpha_AddColor, Texture, Current, SelectArg1, Current);
  328.  
  329.         AlphaBlendEnable    = True;
  330.         DitherEnable        = False;
  331.         SrcBlend            = Zero;
  332.         DestBlend            = InvSrcColor;
  333.         BlendOp                = Add;
  334.     }
  335.     
  336.     pass horiz2 {
  337.         VertexShader = compile vs_1_1 VertexShaderBicubicFF3B();
  338.                 
  339.         SrcBlend = One;
  340.         DestBlend = One;
  341.     }
  342.     
  343.     pass vert1 <
  344.         string vd_target = "temp2";
  345.         string vd_viewport = "out, out";
  346.         float4 vd_clear = float4(0.5f, 0.5f, 0.5f, 0.5f);
  347.     > {
  348.         VertexShader = compile vs_1_1 VertexShaderBicubicFF3C();
  349.         
  350.         FF_STAGE(0, Texture | Complement, SelectArg1, Current, Texture, SelectArg1, Current);
  351.         FF_STAGE(1, Texture, Modulate, Current, Texture, SelectArg1, Current);
  352.         FF_STAGE(2, Current, ModulateAlpha_AddColor, Texture | Complement, Current, SelectArg1, Current);
  353.         
  354.         Texture[0] = <vd_temptexture>;
  355.         Texture[2] = <vd_temptexture>;        
  356.  
  357.         AlphaBlendEnable = True;
  358.         SrcBlend = Zero;
  359.         DestBlend = InvSrcColor;
  360.     }
  361.     
  362.     pass vert2 {
  363.         VertexShader = compile vs_1_1 VertexShaderBicubicFF3D();
  364.                 
  365.         SrcBlend = One;
  366.         DestBlend = One;
  367.     }
  368.     
  369.     pass final <
  370.         string vd_target = "";
  371.         string vd_viewport = "out, out";
  372.     > {
  373.         VertexShader = compile vs_1_1 VertexShaderBicubicFF3E();
  374.         
  375.         FF_STAGE(0, Texture | Complement, Add, Texture | Complement, Texture | Complement, Add, Texture | Complement);
  376.         FF_STAGE_DISABLE(1);
  377.         FF_STAGE_DISABLE(2);
  378.         
  379.         Texture[0] = <vd_temp2texture>;
  380.         
  381.         AlphaBlendEnable = False;
  382.         DitherEnable = True;
  383.     }
  384. }
  385.  
  386. #endif
  387.