Guest User

Untitled

a guest
Sep 25th, 2020
61
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // (C) 2011 Jan-Willem Krans (janwillem32 <at> hotmail.com)
  2. // This file is part of Video pixel shader pack.
  3. // 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, version 2.
  4. // 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.
  5. // 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  6.  
  7. // 3LCD panel horizontal software alignment, Catmull-Rom spline6 interpolated
  8. // This shader should be run as a screen space pixel shader.
  9. // This shader requires compiling with ps_2_a, but higher is better, see http://en.wikipedia.org/wiki/Pixel_shader to look up what PS version your video card supports.
  10. // If possible, avoid compiling with the software emulation modes (ps_?_sw). Pixel shaders require a lot of processing power to run in real-time software mode.
  11. // This shader is meant to work with linear RGB input and output. Regular R'G'B' with a video gamma encoding will have to be converted with the linear gamma shaders to work properly.
  12. // This shader can only work when the display device receives input in its native display resolution, with over- and underscan disabled. This is to facilitate 1:1 pixel mapping.
  13. // This shader can perform software alignment by Catmull-Rom spline6 interpolation for a 3LCD projector's red and blue panels.
  14.  
  15. // fractions, either decimal or not, are allowed
  16. // set the horizontal resolution
  17. #define HorizontalResolution 1920.
  18. // RedControls and BlueControls, 0 is disabled, 1 is enabled
  19. #define RedControls 1
  20. #define BlueControls 1
  21. // RedShiftLeftToRight and BlueShiftLeftToRight, a value of 3. will shift three pixels to the right, 0 is disabled
  22. #define RedShiftLeftToRight 64.
  23. #define BlueShiftLeftToRight -64.
  24. // RedScaleHorizontal and BlueScaleHorizontal, the centered horizontal magnification factor, a value of HorizontalResolution-3. will scale the output to 3 pixels larger, a value of HorizontalResolution means disabled
  25. #define RedScaleHorizontal HorizontalResolution-128.
  26. #define BlueScaleHorizontal HorizontalResolution+128.
  27. // RedParallelogram and BlueParallelogram, the centered horizontal offset factor on the bottom, a value of 3. will shift 0 pixels to the left on the top, and 3 pixels to the left on the bottom, 0 is disabled
  28. #define RedParallelogram 256.
  29. #define BlueParallelogram -256.
  30. // RedKeystone and BlueKeystone, the centered horizontal magnification factor on the bottom, a value of -3. will scale the output to 0 pixels larger on the top, and 3 pixels larger on the bottom, 0 is disabled
  31. #define RedKeystone -192.
  32. #define BlueKeystone 192.
  33.  
  34. sampler s0;
  35. #define spR(a, o) float a = tex2D(s0, float2(coordR+o*fxR/HorizontalResolution, tex.y)).r;
  36. #define spB(a, o) float a = tex2D(s0, float2(coordB+o*fxB/HorizontalResolution, tex.y)).b;
  37.  
  38. float4 main(float2 tex : TEXCOORD0) : COLOR
  39. {
  40. float4 s1 = tex2D(s0, tex);// base pixel
  41. #if RedControls == 1
  42. float coordR = (tex.x-.5)*(RedScaleHorizontal+tex.y*RedKeystone)+.5*HorizontalResolution-RedShiftLeftToRight+tex.y*RedParallelogram;// assign the output position, normalized to texture width in pixels
  43. float tR = frac(coordR);// calculate the difference between the output pixel and the original surrounding two pixels
  44. // adjust sampling matrix to put the ouput pixel in the interval [R2, R2+.5]
  45. float fxR;
  46. if(tR > .5) {coordR = (coordR-tR+1.5)/HorizontalResolution; tR = 1.-tR; fxR = -1;}
  47. else {coordR = (coordR-tR+.5)/HorizontalResolution; fxR = 1;}
  48. tR *= 4;// compensate for the two iterations
  49.  
  50. spR(R0, -2) spR(R1, -1) spR(R2, 0) spR(R3, 1) spR(R4, 2)// original pixels
  51. if(tR <= 1) s1.r = (((R0*3/256.-R1*7/128.+R2*3/32.-R3*9/128.+R4*5/256.)*tR+R1*19/128.+R3*21/128.-R0*7/256.-R2/4.-R4*9/256.)*tR+(R3-R1)*21/128.+(R0-R4)*5/256.)*tR+R2;// insert interpolated value for the interval [R2, R2+.25]
  52. else {
  53. spR(R5, 3)// sample an additional pixel
  54. tR -= 1.;
  55. s1.r = (((((R0+R4)*3+R2*26+R5-R1*15-R3*18)*tR+R1*35+R3*30-R0*5-R2*58-R4-R5)*tR+R3*144-(R1+R4)*16-R2*112)*tR+R0*2+R2*432+R3*132-R1*36-R4*18)/512.;}// insert interpolated value for the interval (R2+.25, R2+.5]
  56. #endif
  57. #if BlueControls == 1
  58. float coordB = (tex.x-.5)*(BlueScaleHorizontal+tex.y*BlueKeystone)+.5*HorizontalResolution-BlueShiftLeftToRight+tex.y*BlueParallelogram;// assign the output position, normalized to texture width in pixels
  59. float tB = frac(coordB);// calculate the difference between the output pixel and the original surrounding two pixels
  60. // adjust sampling matrix to put the ouput pixel in the interval [B2, B2+.5]
  61. float fxB;
  62. if(tB > .5) {coordB = (coordB-tB+1.5)/HorizontalResolution; tB = 1.-tB; fxB = -1;}
  63. else {coordB = (coordB-tB+.5)/HorizontalResolution; fxB = 1;}
  64. tB *= 4;// compensate for the two iterations
  65.  
  66. spB(B0, -2) spB(B1, -1) spB(B2, 0) spB(B3, 1) spB(B4, 2)// original pixels
  67. if(tB <= 1) s1.b = (((B0*3/256.-B1*7/128.+B2*3/32.-B3*9/128.+B4*5/256.)*tB+B1*19/128.+B3*21/128.-B0*7/256.-B2/4.-B4*9/256.)*tB+(B3-B1)*21/128.+(B0-B4)*5/256.)*tB+B2;// insert interpolated value for the interval [B2, B2+.25]
  68. else {
  69. spB(B5, 3)// sample an additional pixel
  70. tB -= 1.;
  71. s1.b = (((((B0+B4)*3+B2*26+B5-B1*15-B3*18)*tB+B1*35+B3*30-B0*5-B2*58-B4-B5)*tB+B3*144-(B1+B4)*16-B2*112)*tB+B0*2+B2*432+B3*132-B1*36-B4*18)/512.;}// insert interpolated value for the interval (B2+.25, B2+.5]
  72. #endif
  73. return s1;
  74. }
RAW Paste Data