Advertisement
Guest User

crt-easymode-amd.cg

a guest
Sep 26th, 2014
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.79 KB | None | 0 0
  1. /*
  2. CRT Shader by EasyMode
  3. License: GPL
  4. */
  5.  
  6. #pragma parameter SHARPNESS_H "Sharpness Horizontal" 0.5 0.0 1.0 0.05
  7. #pragma parameter SHARPNESS_V "Sharpness Vertical" 1.0 0.0 1.0 0.05
  8. #pragma parameter MASK_STRENGTH "Mask Strength" 0.3 0.0 1.0 0.01
  9. #pragma parameter MASK_SUBPIXEL_WIDTH "Mask Subpixel Width" 1.0 1.0 100.0 1.0
  10. #pragma parameter MASK_SUBPIXEL_HEIGHT "Mask Subpixel Height" 1.0 1.0 100.0 1.0
  11. #pragma parameter MASK_STAGGER "Mask Stagger" 0.0 0.0 100.0 1.0
  12. #pragma parameter MASK_SIZE "Mask Size" 1.0 1.0 4.0 1.0
  13. #pragma parameter SCANLINE_STRENGTH "Scanline Strength" 1.0 0.0 1.0 0.05
  14. #pragma parameter SCANLINE_BEAM_WIDTH "Scanline Beam Width" 1.5 1.0 5.0 0.5
  15. #pragma parameter SCANLINE_BRIGHT_MIN "Scanline Brightness Min." 0.35 0.0 1.0 0.05
  16. #pragma parameter SCANLINE_BRIGHT_MAX "Scanline Brightness Max." 0.65 0.0 1.0 0.05
  17. #pragma parameter GAMMA_INPUT "Gamma Input" 2.0 1.0 3.0 0.1
  18. #pragma parameter GAMMA_OUTPUT "Gamma Output" 1.8 1.0 3.0 0.1
  19. #pragma parameter BRIGHT_BOOST "Brightness Boost" 1.2 1.0 2.0 0.01
  20.  
  21. #ifdef PARAMETER_UNIFORM
  22. uniform float BRIGHT_BOOST;
  23. uniform float GAMMA_INPUT;
  24. uniform float GAMMA_OUTPUT;
  25. uniform float MASK_SIZE;
  26. uniform float MASK_STAGGER;
  27. uniform float MASK_STRENGTH;
  28. uniform float MASK_SUBPIXEL_HEIGHT;
  29. uniform float MASK_SUBPIXEL_WIDTH;
  30. uniform float SCANLINE_BEAM_WIDTH;
  31. uniform float SCANLINE_BRIGHT_MAX;
  32. uniform float SCANLINE_BRIGHT_MIN;
  33. uniform float SCANLINE_STRENGTH;
  34. uniform float SHARPNESS_H;
  35. uniform float SHARPNESS_V;
  36. #else
  37. #define BRIGHT_BOOST 1.2
  38. #define GAMMA_INPUT 2.0
  39. #define GAMMA_OUTPUT 1.8
  40. #define MASK_SIZE 1.0
  41. #define MASK_STAGGER 0.0
  42. #define MASK_STRENGTH 0.3
  43. #define MASK_SUBPIXEL_HEIGHT 1.0
  44. #define MASK_SUBPIXEL_WIDTH 1.0
  45. #define SCANLINE_BEAM_WIDTH 1.5
  46. #define SCANLINE_BRIGHT_MAX 0.65
  47. #define SCANLINE_BRIGHT_MIN 0.35
  48. #define SCANLINE_STRENGTH 1.0
  49. #define SHARPNESS_H 0.5
  50. #define SHARPNESS_V 1.0
  51. #endif
  52.  
  53. #define PI 3.141592653589
  54. #define LINEAR_PROCESSING
  55.  
  56. #ifdef LINEAR_PROCESSING
  57. #define TEX2D(c) pow(tex2D(tex, c).rgb, float3(GAMMA_INPUT))
  58. #else
  59. #define TEX2D(c) tex2D(tex, c).rgb
  60. #endif
  61.  
  62. void main_vertex
  63. (
  64. float4 position : POSITION,
  65. out float4 oPosition : POSITION,
  66. uniform float4x4 modelViewProj,
  67.  
  68. float2 tex : TEXCOORD,
  69. out float2 oTex : TEXCOORD
  70. )
  71. {
  72. oPosition = mul(modelViewProj, position);
  73. oTex = tex;
  74. }
  75.  
  76. struct input
  77. {
  78. float2 video_size;
  79. float2 texture_size;
  80. float2 output_size;
  81. float frame_count;
  82. float frame_direction;
  83. float frame_rotation;
  84. };
  85.  
  86. float curve_distance(float x, float sharp)
  87. {
  88.  
  89. /*
  90. apply half-circle s-curve to distance for sharper (more pixelated) interpolation
  91. single line formula for Graph Toy:
  92. 0.5 - sqrt(0.25 - (x - step(0.5, x)) * (x - step(0.5, x))) * sign(0.5 - x)
  93. */
  94.  
  95. float x_step = step(0.5, x);
  96. float curve = 0.5 - sqrt(0.25 - (x - x_step) * (x - x_step)) * sign(0.5 - x);
  97.  
  98. return lerp(x, curve, sharp);
  99. }
  100.  
  101. float4 main_fragment(uniform sampler2D tex : TEXUNIT0, float2 coords : TEXCOORD0, uniform input IN) : COLOR
  102. {
  103. float2 one = 1.0 / IN.texture_size;
  104. float2 one_half = one / 2.0;
  105. float2 c1 = floor((coords - one_half) / one) * one + one_half;
  106. float2 c2 = float2(c1.x + one.x, c1.y);
  107. float2 c3 = float2(c1.x, c1.y + one.y);
  108. float2 c4 = float2(c2.x, c3.y);
  109. float2 dist = (coords - c1) / (c4 - c1);
  110. float x_curve = curve_distance(dist.x, SHARPNESS_H);
  111. float3 col = lerp(TEX2D(c1), TEX2D(c2), x_curve);
  112. float3 col2 = lerp(TEX2D(c3), TEX2D(c4), x_curve);
  113.  
  114. col = lerp(col, col2, curve_distance(dist.y, SHARPNESS_V));
  115.  
  116. #ifndef LINEAR_PROCESSING
  117. col = pow(col, float3(GAMMA_INPUT));
  118. #endif
  119.  
  120. float luma = dot(float3(0.2126, 0.7152, 0.0722), col);
  121. float bright = (max(col.r, max(col.g, col.b)) + luma) / 2.0;
  122. float scan_bright = clamp(bright, SCANLINE_BRIGHT_MIN, SCANLINE_BRIGHT_MAX);
  123. float scan_weight = 1.0 - pow(cos(coords.y * 2.0 * PI * IN.texture_size.y) * 0.5 + 0.5, SCANLINE_BEAM_WIDTH) * SCANLINE_STRENGTH;
  124.  
  125. float mask = 1.0 - (MASK_STRENGTH);
  126. float2 mod_fac = floor(coords * IN.output_size * IN.texture_size / (IN.video_size * float2(MASK_SIZE, MASK_SUBPIXEL_HEIGHT * MASK_SIZE)));
  127. int subpixel = int(mod((mod_fac.x + mod(mod_fac.y, 2.0) * MASK_STAGGER) / MASK_SUBPIXEL_WIDTH, 3.0));
  128. float3 mask_weight;
  129.  
  130. if (subpixel == 0) mask_weight = float3(1.0, mask, mask);
  131. else if (subpixel == 1) mask_weight = float3(mask, 1.0, mask);
  132. else mask_weight = float3(mask, mask, 1.0);
  133.  
  134. if (IN.output_size.y / IN.video_size.y < 3.0) { scan_weight = 1.0; }
  135.  
  136. col2 = col.rgb;
  137. col *= float3(scan_weight);
  138. col = lerp(col, col2, scan_bright);
  139. col *= mask_weight;
  140. col = pow(col, float3(1.0 / GAMMA_OUTPUT));
  141.  
  142. return float4(col * BRIGHT_BOOST, 1.0);
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement