1
Graphics / Problem with using NTSC shader
« on: September 01, 2013, 03:33:47 pm »
I'm trying to use this shader in SFML: http://www.mediafire.com/download.php?touakpcbs2ujqcp
Here's the 1st pass vertex:
1st pass fragment:
Looking at the examples in SFML I think I need to somehow modify these to get them to work in SFML, but I have some trouble. What should I put in place of rubyMVPMatrix, rubyTexCoord and rubyVertexCoord? I tried replacing rubyTexCoord with gl_TexCoord[0] but that gave me errors.
Here's the 1st pass vertex:
Code: [Select]
uniform mat4 rubyMVPMatrix;
attribute vec2 rubyVertexCoord;
attribute vec2 rubyTexCoord;
varying vec2 tex_coord;
varying vec2 pix_no;
uniform vec2 rubyTextureSize;
uniform vec2 rubyInputSize;
uniform vec2 rubyOutputSize;
void main()
{
gl_Position = rubyMVPMatrix * vec4(rubyVertexCoord, 0.0, 1.0);
tex_coord = rubyTexCoord;
pix_no = rubyTexCoord * rubyTextureSize * (rubyOutputSize / rubyInputSize);
}
1st pass fragment:
Code: [Select]
varying vec2 tex_coord;
uniform sampler2D rubyTexture;
uniform int rubyFrameCount;
varying vec2 pix_no;
#define PI 3.14159265
#define CHROMA_MOD_FREQ (0.4 * PI)
#define CHROMA_AMP 1.0
#define ENCODE_GAMMA (1.0 / 2.2)
const mat3 yiq_mat = mat3(
0.2989, 0.5959, 0.2115,
0.5870, -0.2744, -0.5229,
0.1140, -0.3216, 0.3114);
vec3 rgb2yiq(vec3 col)
{
return yiq_mat * col;
}
void main()
{
vec3 col = texture2D(rubyTexture, tex_coord).rgb;
vec3 yiq = rgb2yiq(pow(col, vec3(ENCODE_GAMMA)));
float chroma_phase = PI * 0.6667 * (mod(pix_no.y, 3.0) + float(rubyFrameCount));
float mod_phase = chroma_phase + pix_no.x * CHROMA_MOD_FREQ;
float i_mod = CHROMA_AMP * cos(mod_phase);
float q_mod = CHROMA_AMP * sin(mod_phase);
yiq = vec3(yiq.x, yiq.y * i_mod, yiq.z * q_mod);
gl_FragColor = vec4(yiq, 1.0);
}
Looking at the examples in SFML I think I need to somehow modify these to get them to work in SFML, but I have some trouble. What should I put in place of rubyMVPMatrix, rubyTexCoord and rubyVertexCoord? I tried replacing rubyTexCoord with gl_TexCoord[0] but that gave me errors.