Blame ext/gl/effects/gstgleffectssources.c

Packit 971217
/*
Packit 971217
 * GStreamer
Packit 971217
 * Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
Packit 971217
 *
Packit 971217
 * This library is free software; you can redistribute it and/or
Packit 971217
 * modify it under the terms of the GNU Library General Public
Packit 971217
 * License as published by the Free Software Foundation; either
Packit 971217
 * version 2 of the License, or (at your option) any later version.
Packit 971217
 *
Packit 971217
 * This library is distributed in the hope that it will be useful,
Packit 971217
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 971217
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 971217
 * Library General Public License for more details.
Packit 971217
 *
Packit 971217
 * You should have received a copy of the GNU Library General Public
Packit 971217
 * License along with this library; if not, write to the
Packit 971217
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Packit 971217
 * Boston, MA 02110-1301, USA.
Packit 971217
 */
Packit 971217
Packit 971217
#ifdef HAVE_CONFIG_H
Packit 971217
#include "config.h"
Packit 971217
#endif
Packit 971217
Packit 971217
#include <gst/gl/gstglconfig.h>
Packit 971217
Packit 971217
#include "../gstgleffects.h"
Packit 971217
#include "gstgleffectssources.h"
Packit 971217
#include <math.h>
Packit 971217
Packit 971217
/* A common file for sources is needed since shader sources can be
Packit 971217
 * generic and reused by several effects */
Packit 971217
Packit 971217
/* FIXME */
Packit 971217
/* Move sooner or later into single .frag .vert files and either bake
Packit 971217
 * them into a c file at compile time or load them at run time */
Packit 971217
Packit 971217
Packit 971217
/* fill a normalized and zero centered gaussian vector for separable
Packit 971217
 * gaussian convolution */
Packit 971217
Packit 971217
void
Packit 971217
fill_gaussian_kernel (float *kernel, int size, float sigma)
Packit 971217
{
Packit 971217
  int i;
Packit 971217
  float sum;
Packit 971217
  int l;
Packit 971217
Packit 971217
  /* need an odd sized vector to center it at zero */
Packit 971217
  g_return_if_fail ((size % 2) != 0);
Packit 971217
Packit 971217
  sum = 0.0;
Packit 971217
  l = (size - 1) / 2;
Packit 971217
Packit 971217
  for (i = 0; i < size; i++) {
Packit 971217
    kernel[i] = expf (-0.5 * pow ((i - l) / sigma, 2.0));
Packit 971217
    sum += kernel[i];
Packit 971217
  }
Packit 971217
Packit 971217
  for (i = 0; i < size; i++) {
Packit 971217
    kernel[i] /= sum;
Packit 971217
  }
Packit 971217
}
Packit 971217
Packit 971217
/* *INDENT-OFF* */
Packit 971217
Packit 971217
/* Mirror effect */
Packit 971217
const gchar *mirror_fragment_source_opengl =
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec2 texturecoord = gl_TexCoord[0].xy;"
Packit 971217
  "  vec2 normcoord;"
Packit 971217
  "  normcoord = texturecoord - 0.5;"
Packit 971217
  "  normcoord.x *= sign (normcoord.x);"
Packit 971217
  "  texturecoord = normcoord + 0.5;"
Packit 971217
  "  vec4 color = texture2D (tex, texturecoord);"
Packit 971217
  "  gl_FragColor = color * gl_Color;"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *mirror_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec2 texturecoord = v_texcoord.xy;"
Packit 971217
  "  float normcoord = texturecoord.x - 0.5;"
Packit 971217
  "  normcoord *= sign (normcoord);"
Packit 971217
  "  texturecoord.x = normcoord + 0.5;"
Packit 971217
  "  gl_FragColor = texture2D (tex, texturecoord);"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *squeeze_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec2 texturecoord = v_texcoord.xy;"
Packit 971217
  "  vec2 normcoord = texturecoord - 0.5;"
Packit 971217
  /* Add a very small value to length otherwise it could be 0 */
Packit 971217
  "  float r = length (normcoord)+0.01;"
Packit 971217
  "  r = pow(r, 0.40)*1.3;"
Packit 971217
  "  normcoord = normcoord / r;"
Packit 971217
  "  texturecoord = (normcoord + 0.5);"
Packit 971217
  "  gl_FragColor = texture2D (tex, texturecoord);"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *stretch_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "void main () {"
Packit 971217
	"  vec2 texturecoord = v_texcoord.xy;"
Packit 971217
  "  vec2 normcoord;"
Packit 971217
  "  normcoord = texturecoord - 0.5;"
Packit 971217
  "  float r = length (normcoord);"
Packit 971217
  "  normcoord *= 2.0 - smoothstep(0.0, 0.35, r);"
Packit 971217
  "  texturecoord = normcoord + 0.5;"
Packit 971217
  "  gl_FragColor = texture2D (tex, texturecoord);"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *tunnel_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec2 texturecoord = v_texcoord.xy;"
Packit 971217
  "  vec2 normcoord;"
Packit 971217
  /* little trick with normalized coords to obtain a circle with
Packit 971217
   * rect textures */
Packit 971217
  "  normcoord = (texturecoord - 0.5);"
Packit 971217
  "  float r = length(normcoord);"
Packit 971217
  "  if (r > 0.0)"
Packit 971217
  "    normcoord *= clamp (r, 0.0, 0.275) / r;"
Packit 971217
  "  texturecoord = normcoord + 0.5;"
Packit 971217
  "  gl_FragColor = texture2D (tex, texturecoord);"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *fisheye_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec2 texturecoord = v_texcoord.xy;"
Packit 971217
  "  vec2 normcoord;"
Packit 971217
  "  normcoord = texturecoord - 0.5;"
Packit 971217
  "  float r = length (normcoord);"
Packit 971217
  "  normcoord *= r * 1.41421;" /* sqrt (2) */
Packit 971217
  "  texturecoord = normcoord + 0.5;"
Packit 971217
  "  gl_FragColor = texture2D (tex, texturecoord);"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *twirl_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
	"uniform sampler2D tex;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec2 texturecoord = v_texcoord.xy;"
Packit 971217
  "  vec2 normcoord;"
Packit 971217
  "  normcoord = texturecoord - 0.5;"
Packit 971217
  "  float r = length (normcoord);"
Packit 971217
  /* calculate rotation angle: maximum (about pi/2) at the origin and
Packit 971217
   * gradually decrease it up to 0.6 of each quadrant */
Packit 971217
  "  float phi = (1.0 - smoothstep (0.0, 0.3, r)) * 1.6;"
Packit 971217
  /* precalculate sin phi and cos phi, save some alu */
Packit 971217
  "  float s = sin(phi);"
Packit 971217
  "  float c = cos(phi);"
Packit 971217
  /* rotate */
Packit 971217
  "  normcoord *= mat2(c, s, -s, c);"
Packit 971217
  "  texturecoord = normcoord + 0.5;"
Packit 971217
  "  gl_FragColor = texture2D (tex, texturecoord);"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *bulge_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec2 texturecoord = v_texcoord.xy;"
Packit 971217
  "  vec2 normcoord;"
Packit 971217
  "  normcoord = texturecoord - 0.5;"
Packit 971217
  "  float r =  length (normcoord);"
Packit 971217
  "  normcoord *= smoothstep (-0.05, 0.25, r);"
Packit 971217
  "  texturecoord = normcoord + 0.5;"
Packit 971217
  "  gl_FragColor = texture2D (tex, texturecoord);"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *square_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec2 texturecoord = v_texcoord.xy;"
Packit 971217
  "  vec2 normcoord;"
Packit 971217
  "  normcoord = texturecoord - 0.5;"
Packit 971217
  "  float r = length (normcoord);"
Packit 971217
  "  normcoord *= 1.0 + smoothstep(0.125, 0.25, abs(normcoord));"
Packit 971217
  "  normcoord /= 2.0; /* zoom amount */"
Packit 971217
  "  texturecoord = normcoord + 0.5;"
Packit 971217
  "  gl_FragColor = texture2D (tex, texturecoord);"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *luma_threshold_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec2 texturecoord = v_texcoord.xy;"
Packit 971217
  "  vec4 color = texture2D(tex, texturecoord);"
Packit 971217
  "  float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"    /* BT.709 (from orange book) */
Packit 971217
  "  gl_FragColor = vec4 (vec3 (smoothstep (0.30, 0.50, luma)), color.a);"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *sep_sobel_length_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "uniform bool invert;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec4 g = texture2D (tex, v_texcoord.xy);"
Packit 971217
  /* restore black background with grey edges */
Packit 971217
  "  g -= vec4(0.5, 0.5, 0.0, 0.0);"
Packit 971217
  "  float len = length (g);"
Packit 971217
  /* little trick to avoid IF operator */
Packit 971217
  /* TODO: test if a standalone inverting pass is worth */
Packit 971217
  "  gl_FragColor = abs(vec4(vec3(float(invert) - len), 1.0));"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *desaturate_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec4 color = texture2D (tex, v_texcoord.xy);"
Packit 971217
  "  float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"
Packit 971217
  "  gl_FragColor = vec4(vec3(luma), color.a);"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *sep_sobel_hconv3_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "uniform float width;"
Packit 971217
  "void main () {"
Packit 971217
  "  float w = 1.0 / width;"
Packit 971217
  "  vec2 texturecoord[3];"
Packit 971217
  "  texturecoord[1] = v_texcoord.xy;"
Packit 971217
  "  texturecoord[0] = texturecoord[1] - vec2(w, 0.0);"
Packit 971217
  "  texturecoord[2] = texturecoord[1] + vec2(w, 0.0);"
Packit 971217
  "  float grad_kern[3];"
Packit 971217
  "  grad_kern[0] = 1.0;"
Packit 971217
  "  grad_kern[1] = 0.0;"
Packit 971217
  "  grad_kern[2] = -1.0;"
Packit 971217
  "  float blur_kern[3];"
Packit 971217
  "  blur_kern[0] = 0.25;"
Packit 971217
  "  blur_kern[1] = 0.5;"
Packit 971217
  "  blur_kern[2] = 0.25;"
Packit 971217
  "  int i;"
Packit 971217
  "  vec4 sum = vec4 (0.0);"
Packit 971217
  "  for (i = 0; i < 3; i++) { "
Packit 971217
  "    vec4 neighbor = texture2D(tex, texturecoord[i]); "
Packit 971217
  "    sum.r = neighbor.r * blur_kern[i] + sum.r;"
Packit 971217
  "    sum.g = neighbor.g * grad_kern[i] + sum.g;"
Packit 971217
  "  }"
Packit 971217
  "  gl_FragColor = sum + vec4(0.0, 0.5, 0.0, 0.0);"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *sep_sobel_vconv3_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "uniform float height;"
Packit 971217
  "void main () {"
Packit 971217
  "  float h = 1.0 / height;"
Packit 971217
  "  vec2 texturecoord[3];"
Packit 971217
  "  texturecoord[1] = v_texcoord.xy;"
Packit 971217
  "  texturecoord[0] = texturecoord[1] - vec2(0.0, h);"
Packit 971217
  "  texturecoord[2] = texturecoord[1] + vec2(0.0, h);"
Packit 971217
  "  float grad_kern[3];"
Packit 971217
  "  grad_kern[0] = 1.0;"
Packit 971217
  "  grad_kern[1] = 0.0;"
Packit 971217
  "  grad_kern[2] = -1.0;"
Packit 971217
  "  float blur_kern[3];"
Packit 971217
  "  blur_kern[0] = 0.25;"
Packit 971217
  "  blur_kern[1] = 0.5;"
Packit 971217
  "  blur_kern[2] = 0.25;"
Packit 971217
  "  int i;"
Packit 971217
  "  vec4 sum = vec4 (0.0);"
Packit 971217
  "  for (i = 0; i < 3; i++) { "
Packit 971217
  "    vec4 neighbor = texture2D(tex, texturecoord[i]); "
Packit 971217
  "    sum.r = neighbor.r * grad_kern[i] + sum.r;"
Packit 971217
  "    sum.g = neighbor.g * blur_kern[i] + sum.g;"
Packit 971217
  "  }"
Packit 971217
  "  gl_FragColor = sum + vec4(0.5, 0.0, 0.0, 0.0);"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *hconv7_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "uniform float kernel[7];"
Packit 971217
  "uniform float gauss_width;"
Packit 971217
  "void main () {"
Packit 971217
  "  float w = 1.0 / gauss_width;"
Packit 971217
  "  vec2 texturecoord[7];"
Packit 971217
  "  texturecoord[3] = v_texcoord.xy;"
Packit 971217
  "  texturecoord[2] = texturecoord[3] - vec2(w, 0.0);"
Packit 971217
  "  texturecoord[1] = texturecoord[2] - vec2(w, 0.0);"
Packit 971217
  "  texturecoord[0] = texturecoord[1] - vec2(w, 0.0);"
Packit 971217
  "  texturecoord[4] = texturecoord[3] + vec2(w, 0.0);"
Packit 971217
  "  texturecoord[5] = texturecoord[4] + vec2(w, 0.0);"
Packit 971217
  "  texturecoord[6] = texturecoord[5] + vec2(w, 0.0);"
Packit 971217
  "  int i;"
Packit 971217
  "  vec4 sum = vec4 (0.0);"
Packit 971217
  "  for (i = 0; i < 7; i++) { "
Packit 971217
  "    vec4 neighbor = texture2D(tex, texturecoord[i]); "
Packit 971217
  "    sum += neighbor * kernel[i];"
Packit 971217
  "  }"
Packit 971217
  "  gl_FragColor = sum;"
Packit 971217
  "}";
Packit 971217
Packit 971217
/* vertical convolution 7x7 */
Packit 971217
const gchar *vconv7_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "uniform float kernel[7];"
Packit 971217
  "uniform float gauss_height;"
Packit 971217
  "void main () {"
Packit 971217
  "  float h = 1.0 / gauss_height;"
Packit 971217
  "  vec2 texturecoord[7];"
Packit 971217
  "  texturecoord[3] = v_texcoord.xy;"
Packit 971217
  "  texturecoord[2] = texturecoord[3] - vec2(0.0, h);"
Packit 971217
  "  texturecoord[1] = texturecoord[2] - vec2(0.0, h);"
Packit 971217
  "  texturecoord[0] = texturecoord[1] - vec2(0.0, h);"
Packit 971217
  "  texturecoord[4] = texturecoord[3] + vec2(0.0, h);"
Packit 971217
  "  texturecoord[5] = texturecoord[4] + vec2(0.0, h);"
Packit 971217
  "  texturecoord[6] = texturecoord[5] + vec2(0.0, h);"
Packit 971217
  "  int i;"
Packit 971217
  "  vec4 sum = vec4 (0.0);"
Packit 971217
  "  for (i = 0; i < 7; i++) { "
Packit 971217
  "    vec4 neighbor = texture2D(tex, texturecoord[i]);"
Packit 971217
  "    sum += neighbor * kernel[i];"
Packit 971217
  "  }"
Packit 971217
  "  gl_FragColor = sum;"
Packit 971217
  "}";
Packit 971217
Packit 971217
/* TODO: support several blend modes */
Packit 971217
const gchar *sum_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D base;"
Packit 971217
  "uniform sampler2D blend;"
Packit 971217
  "uniform float alpha;"
Packit 971217
  "uniform float beta;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec4 basecolor = texture2D (base, v_texcoord.xy);"
Packit 971217
  "  vec4 blendcolor = texture2D (blend, v_texcoord.xy);"
Packit 971217
  "  gl_FragColor = alpha * basecolor + beta * blendcolor;"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *multiply_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D base;"
Packit 971217
  "uniform sampler2D blend;"
Packit 971217
  "uniform float alpha;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec4 basecolor = texture2D (base, v_texcoord.xy);"
Packit 971217
  "  vec4 blendcolor = texture2D (blend, v_texcoord.xy);"
Packit 971217
  "  gl_FragColor = (1.0 - alpha) * basecolor + alpha * basecolor * blendcolor;"
Packit 971217
  "}";
Packit 971217
Packit 971217
/* lut operations, map luma to tex1d, see orange book (chapter 19) */
Packit 971217
const gchar *luma_to_curve_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "uniform sampler2D curve;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec2 texturecoord = v_texcoord.xy;"
Packit 971217
  "  vec4 color = texture2D (tex, texturecoord);"
Packit 971217
  "  float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"
Packit 971217
  "  color = texture2D (curve, vec2(luma, 0.0));"
Packit 971217
  "  gl_FragColor = color;"
Packit 971217
  "}";
Packit 971217
Packit 971217
/* lut operations, map rgb to tex1d, see orange book (chapter 19) */
Packit 971217
const gchar *rgb_to_curve_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "uniform sampler2D curve;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec4 color = texture2D (tex, v_texcoord.xy);"
Packit 971217
  "  vec4 outcolor;"
Packit 971217
  "  outcolor.r = texture2D (curve, vec2(color.r, 0.0)).r;"
Packit 971217
  "  outcolor.g = texture2D (curve, vec2(color.g, 0.0)).g;"
Packit 971217
  "  outcolor.b = texture2D (curve, vec2(color.b, 0.0)).b;"
Packit 971217
  "  outcolor.a = color.a;"
Packit 971217
  "  gl_FragColor = outcolor;"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *sin_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec4 color = texture2D (tex, vec2(v_texcoord.xy));"
Packit 971217
  "  float luma = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721));"
Packit 971217
/* calculate hue with the Preucil formula */
Packit 971217
  "  float cosh = color.r - 0.5*(color.g + color.b);"
Packit 971217
/* sqrt(3)/2 = 0.866 */
Packit 971217
  "  float sinh = 0.866*(color.g - color.b);"
Packit 971217
/* hue = atan2 h */
Packit 971217
  "  float sch = (1.0-sinh)*cosh;"
Packit 971217
/* ok this is a little trick I came up because I didn't find any
Packit 971217
 * detailed proof of the Preucil formula. The issue is that tan(h) is
Packit 971217
 * pi-periodic so the smoothstep thing gives both reds (h = 0) and
Packit 971217
 * cyans (h = 180). I don't want to use atan since it requires
Packit 971217
 * branching and doesn't work on i915. So take only the right half of
Packit 971217
 * the circle where cosine is positive */
Packit 971217
/* take a slightly purple color trying to get rid of human skin reds */
Packit 971217
/* tanh = +-1.0 for h = +-45, where yellow=60, magenta=-60 */
Packit 971217
  "  float a = smoothstep (0.3, 1.0, sch);"
Packit 971217
  "  float b = smoothstep (-0.4, -0.1, sinh);"
Packit 971217
  "  float mix = a * b;"
Packit 971217
  "  gl_FragColor = color * mix + luma * (1.0 - mix);"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *interpolate_fragment_source =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D base;"
Packit 971217
  "uniform sampler2D blend;"
Packit 971217
  "void main () {"
Packit 971217
  "vec4 basecolor = texture2D (base, v_texcoord);"
Packit 971217
  "vec4 blendcolor = texture2D (blend, v_texcoord);"
Packit 971217
  "vec4 white = vec4(1.0);"
Packit 971217
  "gl_FragColor = blendcolor + (1.0 - blendcolor.a) * basecolor;"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *texture_interp_fragment_source =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D base;"
Packit 971217
  "uniform sampler2D blend;"
Packit 971217
  "uniform sampler2D alpha;"
Packit 971217
  "void main () {"
Packit 971217
  "  vec4 basecolor = texture2D (base, v_texcoord);"
Packit 971217
  "  vec4 blendcolor = texture2D (blend, v_texcoord);"
Packit 971217
  "  vec4 alphacolor = texture2D (alpha, v_texcoord);"
Packit 971217
  "  gl_FragColor = (alphacolor * blendcolor) + (1.0 - alphacolor) * basecolor;"
Packit 971217
  "}";
Packit 971217
Packit 971217
const gchar *difference_fragment_source =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D saved;"
Packit 971217
  "uniform sampler2D current;"
Packit 971217
  "void main () {"
Packit 971217
  "vec4 savedcolor = texture2D (saved, v_texcoord);"
Packit 971217
  "vec4 currentcolor = texture2D (current, v_texcoord);"
Packit 971217
  "gl_FragColor = vec4 (step (0.12, length (savedcolor - currentcolor)));"
Packit 971217
  "}";
Packit 971217
Packit 971217
/* This filter is meant as a demo of gst-plugins-gl + glsl
Packit 971217
   capabilities. So I'm keeping this shader readable enough. If and
Packit 971217
   when this shader will be used in production be careful to hard code
Packit 971217
   kernel into the shader and remove unneeded zero multiplications in
Packit 971217
   the convolution */
Packit 971217
const gchar *conv9_fragment_source_gles2 =
Packit 971217
  "#ifdef GL_ES\n"
Packit 971217
  "precision mediump float;\n"
Packit 971217
  "#endif\n"
Packit 971217
  "varying vec2 v_texcoord;"
Packit 971217
  "uniform sampler2D tex;"
Packit 971217
  "uniform float kernel[9];"
Packit 971217
  "uniform float width, height;"
Packit 971217
  "uniform bool invert;"
Packit 971217
  "void main () {"
Packit 971217
  "  float w = 1.0 / width;"
Packit 971217
  "  float h = 1.0 / height;"
Packit 971217
  "  vec2 texturecoord[9];"
Packit 971217
  "  texturecoord[4] = v_texcoord.xy;"                    /*  0  0 */
Packit 971217
  "  texturecoord[5] = texturecoord[4] + vec2(w,   0.0);" /*  1  0 */
Packit 971217
  "  texturecoord[2] = texturecoord[5] - vec2(0.0, h);"   /*  1 -1 */
Packit 971217
  "  texturecoord[1] = texturecoord[2] - vec2(w,   0.0);" /*  0 -1 */
Packit 971217
  "  texturecoord[0] = texturecoord[1] - vec2(w,   0.0);" /* -1 -1 */
Packit 971217
  "  texturecoord[3] = texturecoord[0] + vec2(0.0, h);"   /* -1  0 */
Packit 971217
  "  texturecoord[6] = texturecoord[3] + vec2(0.0, h);"   /* -1  1 */
Packit 971217
  "  texturecoord[7] = texturecoord[6] + vec2(w,   0.0);" /*  0  1 */
Packit 971217
  "  texturecoord[8] = texturecoord[7] + vec2(w,   0.0);" /*  1  1 */
Packit 971217
  "  int i;"
Packit 971217
  "  vec3 sum = vec3 (0.0);"
Packit 971217
  "  for (i = 0; i < 9; i++) { "
Packit 971217
  "    vec4 neighbor = texture2D (tex, texturecoord[i]);"
Packit 971217
  "    sum += neighbor.xyz * kernel[i];"
Packit 971217
  "  }"
Packit 971217
  "  gl_FragColor = vec4 (abs(sum - vec3(float(invert))), 1.0);"
Packit 971217
  "}";
Packit 971217
Packit 971217
/* *INDENT-ON* */