Guest User

crt-easymode-blueblack-pow (for testing)

a guest
Jul 17th, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.32 KB | None | 0 0
  1. #pragma parameter H_SHARPNESS "H. Sharpness" 0.5 0.0 1.0 0.05
  2. #pragma parameter V_SHARPNESS "V. Sharpness" 1.0 0.0 1.0 0.05
  3. #pragma parameter SCANLINE_STRENGTH "Scanline Strength" 0.5 0.0 1.0 0.05
  4. #pragma parameter BEAM_WIDTH "Beam Width" 1.5 1.0 5.0 0.5
  5. #pragma parameter BRIGHT_BOOST_MIN "Bright Boost Min." 0.25 0.0 1.0 0.05
  6. #pragma parameter BRIGHT_BOOST_MAX "Bright Boost Max." 0.5 0.0 1.0 0.05
  7. #pragma parameter DOTMASK_STRENGTH "Dot Mask Strength" 0.0 0.0 1.0 0.01
  8. #pragma parameter INPUT_GAMMA "Input Gamma" 2.0 1.0 3.0 0.1
  9. #pragma parameter OUTPUT_GAMMA "Output Gamma" 1.8 1.0 3.0 0.1
  10.  
  11. #ifdef PARAMETER_UNIFORM
  12. uniform float H_SHARPNESS;
  13. uniform float V_SHARPNESS;
  14. uniform float SCANLINE_STRENGTH;
  15. uniform float BEAM_WIDTH;
  16. uniform float BRIGHT_BOOST_MIN;
  17. uniform float BRIGHT_BOOST_MAX;
  18. uniform float DOTMASK_STRENGTH;
  19. uniform float INPUT_GAMMA;
  20. uniform float OUTPUT_GAMMA;
  21. #else
  22. #define H_SHARPNESS 0.45
  23. #define V_SHARPNESS 1.2
  24. #define SCANLINE_STRENGTH 1.2
  25. #define BEAM_WIDTH 2.0
  26. #define BRIGHT_BOOST_MIN 0.1
  27. #define BRIGHT_BOOST_MAX 0.5
  28. #define DOTMASK_STRENGTH 0.35
  29. #define INPUT_GAMMA 2.0
  30. #define OUTPUT_GAMMA 2.0
  31. #endif
  32.  
  33. #define PI 3.141592653589
  34. #define LINEAR_PROCESSING
  35.  
  36. #ifdef LINEAR_PROCESSING
  37. #define TEX2D(c) pow(tex2D(tex, c).rgb, float3(INPUT_GAMMA, INPUT_GAMMA, INPUT_GAMMA))
  38. #else
  39. #define TEX2D(c) tex2D(tex, c).rgb
  40. #endif
  41.  
  42. /*
  43.  
  44. CRT Shader by EasyMode
  45.  
  46. Copyright (C) 2014 EasyMode
  47.  
  48. This program is free software; you can redistribute it and/or modify it under the terms
  49. of the GNU General Public License as published by the Free Software Foundation; either
  50. version 2 of the License, or (at your option) any later version.
  51.  
  52. */
  53.  
  54. void main_vertex
  55. (
  56. float4 position : POSITION,
  57. out float4 oPosition : POSITION,
  58. uniform float4x4 modelViewProj,
  59.  
  60. float2 tex : TEXCOORD,
  61. out float2 oTex : TEXCOORD
  62. )
  63. {
  64. oPosition = mul(modelViewProj, position);
  65. oTex = tex;
  66. }
  67.  
  68. struct input
  69. {
  70. float2 video_size;
  71. float2 texture_size;
  72. float2 output_size;
  73. float frame_count;
  74. float frame_direction;
  75. float frame_rotation;
  76. };
  77.  
  78. float curve_distance(float x, float sharp)
  79. {
  80. // apply half-circle s-curve to distance for sharper (more pixelated) interpolation
  81. // single line formula for Graph Toy:
  82. // 0.5 - sqrt(0.25 - (x - step(0.5, x)) * (x - step(0.5, x))) * sign(0.5 - x)
  83.  
  84. float x_step = step(0.5, x);
  85. float curve = 0.5 - sqrt(0.25 - (x - x_step) * (x - x_step)) * sign(0.5 - x);
  86.  
  87. return lerp(x, curve, sharp);
  88. }
  89.  
  90. float4 main_fragment(uniform sampler2D tex : TEXUNIT0, float2 coords : TEXCOORD0, uniform input IN) : COLOR
  91. {
  92. float2 one = 1.0 / IN.texture_size;
  93. float2 one_half = one / 2.0;
  94. float2 c1 = floor((coords - one_half) / one) * one + one_half;
  95. float2 c2 = float2(c1.x + one.x, c1.y);
  96. float2 c3 = float2(c1.x, c1.y + one.y);
  97. float2 c4 = float2(c2.x, c3.y);
  98. float2 dist = (coords - c1) / (c4 - c1);
  99. float x_curve = curve_distance(dist.x, H_SHARPNESS);
  100. float3 col = lerp(TEX2D(c1), TEX2D(c2), x_curve);
  101. float3 col2 = lerp(TEX2D(c3), TEX2D(c4), x_curve);
  102.  
  103. col = lerp(col, col2, curve_distance(dist.y, V_SHARPNESS));
  104.  
  105. #ifndef LINEAR_PROCESSING
  106. col = pow(col, float3(INPUT_GAMMA, INPUT_GAMMA, INPUT_GAMMA));
  107. #endif
  108.  
  109. float luma = dot(float3(0.2126, 0.7152, 0.0722), col);
  110. float bright = (max(col.r, max(col.g, col.b)) + luma) / 2.0;
  111. float boost = clamp(bright, BRIGHT_BOOST_MIN, BRIGHT_BOOST_MAX);
  112. float scan_weight = 1.0 - pow(cos(coords.y * 2.0 * PI * IN.texture_size.y) * 0.5 + 0.5, BEAM_WIDTH) * SCANLINE_STRENGTH;
  113. float mod_factor = coords.x * IN.output_size.x * IN.texture_size.x / IN.video_size.x;
  114. float mask = 1.0 - DOTMASK_STRENGTH;
  115. float3 mask_weight = lerp(float3(1.0, mask, 1.0), float3(mask, 1.0, mask), floor(mod(mod_factor, 2.0)));
  116.  
  117. // color modification
  118. col.r *= 0.9 ;
  119. col.g *= 0.9 ;
  120. col.b *= 1.2 ;
  121. col.r += 0.001 ;
  122. col.g += 0.001 ;
  123. col.b += 0.011 * pow(col.b/0.3 - 1, 2);
  124.  
  125. col2 = float3(col.r, col.g, col.b);
  126. col *= float3(scan_weight, scan_weight, scan_weight);
  127. col = lerp(col, col2, boost);
  128.  
  129. // color boost
  130. col *= 1.35 ;
  131.  
  132. col *= mask_weight;
  133. col = pow(col, float3(1.0 / OUTPUT_GAMMA, 1.0 / OUTPUT_GAMMA, 1.0 / OUTPUT_GAMMA));
  134.  
  135. return float4(col, 1.0);
  136. }
Advertisement
Add Comment
Please, Sign In to add comment