Advertisement
Guest User

sharp-scanline.cg

a guest
Mar 7th, 2015
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. /* COMPATIBILITY
  2. - HLSL compilers
  3. - Cg compilers
  4. */
  5.  
  6. /*
  7. Author: Themaister
  8. License: Public domain
  9. */
  10.  
  11. struct sine_coord
  12. {
  13. float2 texel;
  14. float2 offset;
  15. float2 omega;
  16. };
  17.  
  18. struct input
  19. {
  20. float2 video_size;
  21. float2 texture_size;
  22. float2 output_size;
  23. float frame_count;
  24. float frame_direction;
  25. float frame_rotation;
  26. };
  27.  
  28. void main_vertex
  29. (
  30. float4 position : POSITION,
  31. out float4 oPosition : POSITION,
  32. uniform float4x4 modelViewProj,
  33.  
  34. float4 color : COLOR,
  35. out float4 oColor : COLOR,
  36.  
  37. float2 tex : TEXCOORD,
  38. out float2 oTex : TEXCOORD,
  39.  
  40. uniform input IN,
  41. out sine_coord coords : TEXCOORD2
  42. )
  43. {
  44. oPosition = mul(modelViewProj, position);
  45. oColor = color;
  46. oTex = tex;
  47.  
  48. coords.texel = tex * IN.texture_size;
  49. coords.offset = tex - float2(0.0, 0.25 / IN.texture_size.y);
  50. coords.omega = float2(3.1415 * IN.output_size.x * IN.texture_size.x / IN.video_size.x, 2.0 * 3.1415 * IN.texture_size.y);
  51. }
  52.  
  53. #pragma parameter SCANLINE_BASE_BRIGHTNESS "Scanline Base Brightness" 1.0 0.0 1.0 0.01
  54. #pragma parameter SCANLINE_SINE_COMP_A "Scanline Sine Comp A" 0.1 0.0 0.10 0.01
  55. #pragma parameter SCANLINE_SINE_COMP_B "Scanline Sine Comp B" 0.15 0.0 1.0 0.05
  56. #pragma parameter SHARP_BILINEAR_PRE_SCALE "Sharp Bilinear Prescale" 1.25 1.0 10.0 0.05
  57.  
  58. #ifdef PARAMETER_UNIFORM
  59. uniform float SCANLINE_BASE_BRIGHTNESS;
  60. uniform float SCANLINE_SINE_COMP_A;
  61. uniform float SCANLINE_SINE_COMP_B;
  62. uniform float SHARP_BILINEAR_PRE_SCALE;
  63. #else
  64. #define SCANLINE_BASE_BRIGHTNESS 1.0
  65. #define SCANLINE_SINE_COMP_A 0.1
  66. #define SCANLINE_SINE_COMP_B 0.15
  67. #define SHARP_BILINEAR_PRE_SCALE 1.25
  68. #endif
  69.  
  70.  
  71. float4 main_fragment (in sine_coord co : TEXCOORD2, uniform sampler2D s0 : TEXUNIT0, uniform input IN) : COLOR
  72. {
  73. float2 texel_floored = floor(co.texel);
  74. float2 s = fract(co.texel);
  75. float region_range = 0.5 - 0.5 / SHARP_BILINEAR_PRE_SCALE;
  76.  
  77. // Figure out where in the texel to sample to get correct pre-scaled bilinear.
  78. // Uses the hardware bilinear interpolator to avoid having to sample 4 times manually.
  79.  
  80. float2 center_dist = s - 0.5;
  81. float2 f = (center_dist - clamp(center_dist, -region_range, region_range)) * SHARP_BILINEAR_PRE_SCALE + 0.5;
  82. float2 mod_texel = texel_floored + f;
  83. float3 res = tex2D(s0, mod_texel / IN.texture_size).rgb;
  84.  
  85. float2 sine_comp = float2(SCANLINE_SINE_COMP_A, SCANLINE_SINE_COMP_B);
  86. float3 scanline = res * (SCANLINE_BASE_BRIGHTNESS + dot(sine_comp * sin(co.offset * co.omega), float2(1.0)));
  87.  
  88. return float4(scanline, 1.0);
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement