title: How to implement a Color Matrix Filter in a GLSL shader
body: <p>I would like to implement a Color Matrix Filter in a GLSL shader but couldn't find any documentation regarding this matter. I'm totaly new to the world of shaders (never coded one myself) so please forgive me if my explanation/vocabulary doesn't make mush sense.</p>
  
  <p><strong>Informations I could gather so far</strong>:</p>
  
  <ul>
  <li>A color matrix is composed of 5 columns (RGBA + offset) and 4 rows</li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/wV1RU.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wV1RU.gif" alt="enter image description here"></a></p>
  
  <p>The values in the first four columns are <em>multiplied</em> with the source red, green, blue, and alpha values respectively. The fifth column value is <em>added</em> (offset)</p>
  
  <ul>
  <li><p>I believe the <em>largest</em> matrices in GLSL are 4×4 <code>mat4</code> matrices (excluding the 'offset' column)</p></li>
  <li><p>The only <code>mat4</code> I've seen implemented in a shader looks like this:</p></li>
  </ul>
  
  <blockquote>
  <pre><code>colorMatrix = (GPUMatrix4x4){{0.3588, 0.7044, 0.1368, 0.0},
                               {0.2990, 0.5870, 0.1140, 0.0},
                               {0.2392, 0.4696, 0.0912 ,0.0},
                               {0,0,0,1.0}
                };
  </code></pre>
  </blockquote>
  
  <p><strong>Question</strong>:</p>
  
  <ul>
  <li>How can implement one ? As stated above I've never coded a GLSL shader before and unfortunately I'm unable to provide an MCVE. I would love to see an example so I can learn from it.</li>
  </ul>
  
  <p>Thank you</p>
  
  <p>EDIT:</p>
  
  <p>I'm working with Processing and this is the only example I've found of vertex and fragment shaders for color rendering:</p>
  
  <p><strong>colorvert.glsl:</strong></p>
  
  <pre><code>uniform mat4 transform;
  
  attribute vec4 position;
  attribute vec4 color;
  
  varying vec4 vertColor;
  
  void main() {
    gl_Position = transform * position;
    vertColor = color;
  }
  </code></pre>
  
  <p><strong>colorfrag.glsl:</strong></p>
  
  <pre><code>#ifdef GL_ES
  precision mediump float;
  precision mediump int;
  #endif
  
  varying vec4 vertColor;
  
  void main() {
    gl_FragColor = vertColor;
  }
  </code></pre>