Guest User

crt-hyllian - low end.

a guest
Apr 23rd, 2014
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.45 KB | None | 0 0
  1. /* COMPATIBILITY
  2. - HLSL compilers
  3. - Cg compilers
  4. */
  5.  
  6. /*
  7. Hyllian's CRT Shader
  8.  
  9. Copyright (C) 2011-2014 Hyllian/Jararaca - [email protected]
  10.  
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program; if not, write to the Free Software
  23. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24.  
  25. */
  26.  
  27. // Uncomment to increase the sharpness of the scanlines.
  28. //#define SHARPER
  29.  
  30. // Control the level of sharpness when SHARPER is enabled.
  31. #define SHARPNESS 2.0
  32.  
  33. // Constants used with gamma correction.
  34. #define InputGamma 2.4
  35. #define OutputGamma 2.2
  36.  
  37. #define GAMMA_IN(color) pow(color, float3(InputGamma, InputGamma, InputGamma))
  38. #define GAMMA_OUT(color) pow(color, float3(1.0 / OutputGamma, 1.0 / OutputGamma, 1.0 / OutputGamma))
  39.  
  40.  
  41. const static float4x4 invX = float4x4( -0.5, 1.0, -0.5, 0.0,
  42. 1.5, -2.5, 0.0, 1.0,
  43. -1.5, 2.0, 0.5, 0.0,
  44. 0.5, -0.5, 0.0, 0.0);
  45.  
  46.  
  47. struct input
  48. {
  49. float2 video_size;
  50. float2 texture_size;
  51. float2 output_size;
  52. float frame_count;
  53. float frame_direction;
  54. float frame_rotation;
  55. };
  56.  
  57.  
  58. struct out_vertex {
  59. float2 texCoord;
  60. };
  61.  
  62. /* VERTEX_SHADER */
  63. out_vertex main_vertex
  64. (
  65. float4 position : POSITION,
  66. out float4 oPosition : POSITION,
  67. float2 texCoord : TEXCOORD0,
  68.  
  69. uniform float4x4 modelViewProj,
  70. uniform input IN
  71. )
  72. {
  73. #ifdef SHARPER
  74. float2 TextureSize = float2(SHARPNESS*IN.texture_size.x, IN.texture_size.y);
  75. #else
  76. float2 TextureSize = IN.texture_size;
  77. #endif
  78. float2 ps = 1.0/TextureSize;
  79.  
  80. oPosition = mul(modelViewProj, position);
  81.  
  82. out_vertex OUT = {
  83. texCoord + ps*float2(-0.49, 0.0)
  84. };
  85.  
  86. return OUT;
  87. }
  88.  
  89.  
  90.  
  91. float4 main_fragment(in out_vertex VAR, uniform sampler2D s_p : TEXUNIT0, uniform input IN) : COLOR
  92. {
  93. #ifdef SHARPER
  94. float2 TextureSize = float2(SHARPNESS*IN.texture_size.x, IN.texture_size.y);
  95. #else
  96. float2 TextureSize = IN.texture_size;
  97. #endif
  98.  
  99. float2 dx = float2(1.0/TextureSize.x, 0.0);
  100. float2 dy = float2(0.0, 1.0/TextureSize.y);
  101.  
  102. float2 tc = (floor(VAR.texCoord*TextureSize)+float2(0.5,0.5))/TextureSize;
  103.  
  104. float2 fp = frac(VAR.texCoord*TextureSize);
  105.  
  106. float3 c10 = tex2D(s_p, tc - dx).xyz;
  107. float3 c11 = tex2D(s_p, tc ).xyz;
  108. float3 c12 = tex2D(s_p, tc + dx).xyz;
  109. float3 c13 = tex2D(s_p, tc + 2.0*dx).xyz;
  110.  
  111. float4x3 color_matrix = float4x3(c10, c11, c12, c13);
  112.  
  113. float4 invX_Px = mul(invX, float4(fp.x*fp.x*fp.x, fp.x*fp.x, fp.x, 1.0));
  114. float3 color = mul(invX_Px, color_matrix);
  115.  
  116. float d = abs(fp.y - 0.5);
  117.  
  118. d = smoothstep(0.0, 1.0, 1.0 - d);
  119.  
  120. color = GAMMA_IN(color*d);
  121.  
  122. return float4(GAMMA_OUT(color), 1.0);
  123. }
Advertisement
Add Comment
Please, Sign In to add comment