// Advanced Scanlines (CRT) shader, created to use in PPSSPP.


precision mediump float; //probably useless
precision mediump int; //probably useless

uniform sampler2D sampler0;
varying vec2 v_texcoord0; //probably useless

float amount = 0.65; // suitable range = 0.0 - 1.0
float jen_res = 320; // can be: 256, 320, 512 etc. otherwise may flutters
float intensity = 0.5; // suitable range = 0.0 - 1.0
float lightness = 1.1; // overall lightness

void main()
{
  vec3 color = texture2DProj(sampler0, gl_TexCoord[0]).rgb;

  // scanlines
//float pos0 = ((gl_TexCoord[0].y + 1.0) * 480.0 * amount);
  float pos0 = ((gl_TexCoord[0].y + 1.0) * jen_res);
  float pos1 = cos((fract( pos0 ) - 0.5)*3.1415926*intensity)*1.5;
  
  // slight contrast curve
  color = color*0.5+0.5*color*color*1.2;

  // color tint
  color *= vec3(0.9,1.0,0.7);

  // vignette (don't work :(, blinking if enabled)
  //color *= 1.1 - 0.6 * (dot(gl_TexCoord[0] - 0.5, gl_TexCoord[0] - 0.5) * 2.0);

  gl_FragColor.rgb = mix(vec3(0,0,0), color, pos1*lightness);
}