Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Problem with using NTSC shader  (Read 1588 times)

0 Members and 1 Guest are viewing this topic.

cmbrgames

  • Newbie
  • *
  • Posts: 7
    • View Profile
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:
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.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Problem with using NTSC shader
« Reply #1 on: September 01, 2013, 08:07:50 pm »
I'm no expert on GLSL so a lot of this will be guesswork, but here goes.

Regarding rubyTexCoord, personally I've never had problems putting something like this in my fragment shader:
uniform sampler2D texture;
...
vec4 texel = texture2D(texture, gl_TexCoord[0].xy);

Did you put gl_TexCoord in the vertex shader?  Because I know that would produce errors.

rubyVertexCoord I think might just be gl_Vertex.

rubyMVPMatrix is just a parameter being passed to the vertex shader so its name is irrelevant, you need to set a value for it, or else use something like:
gl_Position = ftransform();
or
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

 

anything