2010-05-25 10:35:35 +04:00
|
|
|
// -*- Mode: glsl; c-basic-offset: 2; indent-tabs-mode: nil; tab-width: 40; -*-
|
|
|
|
// ***** BEGIN LICENSE BLOCK *****
|
|
|
|
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
//
|
|
|
|
// The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
// 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
// the License. You may obtain a copy of the License at
|
|
|
|
// http://www.mozilla.org/MPL/
|
|
|
|
//
|
|
|
|
// Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
// for the specific language governing rights and limitations under the
|
|
|
|
// License.
|
|
|
|
//
|
|
|
|
// The Original Code is Mozilla Foundation code.
|
|
|
|
//
|
|
|
|
// The Initial Developer of the Original Code is
|
|
|
|
// Mozilla Foundation.
|
|
|
|
// Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
// the Initial Developer. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Contributor(s):
|
|
|
|
// Bas Schouten <bschouten@mozilla.org>
|
|
|
|
// Vladimir Vukicevic <vladimir@pobox.com>
|
|
|
|
//
|
|
|
|
// Alternatively, the contents of this file may be used under the terms of
|
|
|
|
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
// in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
// of those above. If you wish to allow use of your version of this file only
|
|
|
|
// under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
// use your version of this file under the terms of the MPL, indicate your
|
|
|
|
// decision by deleting the provisions above and replace them with the notice
|
|
|
|
// and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
// the provisions above, a recipient may use your version of this file under
|
|
|
|
// the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
//
|
|
|
|
// ***** END LICENSE BLOCK *****
|
|
|
|
|
2012-03-19 00:07:25 +04:00
|
|
|
//
|
|
|
|
// This file is compiled by genshaders.py, use genshaders.sh, no arguments necessary.
|
|
|
|
// The compiled shaders will be in LayerManagerOGLShaders.h.
|
|
|
|
// This file must be compiled after editing, it is not compiled as part of the
|
|
|
|
// build process.
|
2010-05-25 10:35:35 +04:00
|
|
|
//
|
|
|
|
// Syntax:
|
|
|
|
//
|
|
|
|
// // comments (only at the start of a line)
|
|
|
|
//
|
|
|
|
// (@ is used because # is valid inside GLSL)
|
|
|
|
//
|
|
|
|
// multi-line:
|
|
|
|
// @define FOO
|
|
|
|
// ...
|
|
|
|
// @end
|
|
|
|
//
|
|
|
|
// single:
|
|
|
|
// @define FOO 123
|
|
|
|
//
|
|
|
|
// $FOO$ to paste
|
|
|
|
//
|
2012-03-19 00:07:25 +04:00
|
|
|
// To generate a constant string named ShaderName (shader name should not
|
|
|
|
// use '<', '>', ',', ':', except for parameters, see below):
|
2010-05-25 10:35:35 +04:00
|
|
|
// @shader ShaderName
|
|
|
|
// ...
|
|
|
|
// @end
|
|
|
|
//
|
2012-03-19 00:07:25 +04:00
|
|
|
// @shader may have a single parameter with multiple values using
|
|
|
|
// <param:val1,val2> an empty value is allowed. The shader is expanded for
|
|
|
|
// each value, <param> in the body of the shader will be expanded to
|
|
|
|
// the current value, as will the declaration of the parameter. The name of
|
|
|
|
// defines may include <...> and this should work as expected.
|
|
|
|
//
|
|
|
|
// For example:
|
|
|
|
//
|
|
|
|
// @Shader<name:Name1,Name2>
|
|
|
|
// string name = "<name>";
|
|
|
|
// @end
|
|
|
|
//
|
|
|
|
// will be expanded to
|
|
|
|
//
|
|
|
|
// @ShaderName1
|
|
|
|
// string name = "Name1";
|
|
|
|
// @end
|
|
|
|
// @ShaderName2
|
|
|
|
// string name = "Name2";
|
|
|
|
// @end
|
|
|
|
//
|
|
|
|
// This will be straightaway compiled to two constant strings named
|
|
|
|
// ShaderName1 and ShaderName2.
|
2010-05-25 10:35:35 +04:00
|
|
|
//
|
|
|
|
|
2012-03-19 00:07:25 +04:00
|
|
|
@define VERTEX_SHADER_HEADER<>
|
2010-05-25 10:35:35 +04:00
|
|
|
/* Vertex Shader */
|
|
|
|
|
|
|
|
uniform mat4 uMatrixProj;
|
|
|
|
uniform mat4 uLayerQuadTransform;
|
|
|
|
uniform mat4 uLayerTransform;
|
|
|
|
uniform vec4 uRenderTargetOffset;
|
|
|
|
|
|
|
|
attribute vec4 aVertexCoord;
|
|
|
|
attribute vec2 aTexCoord;
|
|
|
|
|
2011-05-19 14:53:02 +04:00
|
|
|
#ifdef GL_ES // for tiling, texcoord can be greater than the lowfp range
|
|
|
|
varying mediump vec2 vTexCoord;
|
|
|
|
#else
|
2010-05-25 10:35:35 +04:00
|
|
|
varying vec2 vTexCoord;
|
2011-05-19 14:53:02 +04:00
|
|
|
#endif
|
2012-03-19 00:07:25 +04:00
|
|
|
@end
|
|
|
|
|
|
|
|
@define VERTEX_SHADER_HEADER<Mask>
|
|
|
|
$VERTEX_SHADER_HEADER<>$
|
|
|
|
|
|
|
|
uniform mat4 uMaskQuadTransform;
|
|
|
|
varying vec2 vMaskCoord;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@define VERTEX_SHADER_HEADER<Mask3D>
|
|
|
|
$VERTEX_SHADER_HEADER<>$
|
|
|
|
|
|
|
|
uniform mat4 uMaskQuadTransform;
|
|
|
|
varying vec3 vMaskCoord;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@define VERTEX_MASK_STUFF<>
|
|
|
|
@end
|
|
|
|
|
|
|
|
@define VERTEX_MASK_STUFF<Mask>
|
|
|
|
vMaskCoord = (uMaskQuadTransform * finalPosition).xy;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@define VERTEX_MASK_STUFF<Mask3D>
|
|
|
|
vMaskCoord.xy = (uMaskQuadTransform * vec4(finalPosition.xyz, 1.0)).xy;
|
|
|
|
// correct for perspective correct interpolation, see comment in D3D10 shader
|
|
|
|
vMaskCoord.z = 1.0;
|
|
|
|
vMaskCoord *= finalPosition.w;
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
// This is a basic Layer vertex shader. It's used for all
|
|
|
|
// Layer programs.
|
|
|
|
|
|
|
|
@shader sLayer<mask:,Mask,Mask3D>VS
|
|
|
|
$VERTEX_SHADER_HEADER<mask>$
|
|
|
|
|
2010-05-25 10:35:35 +04:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec4 finalPosition = aVertexCoord;
|
|
|
|
finalPosition = uLayerQuadTransform * finalPosition;
|
|
|
|
finalPosition = uLayerTransform * finalPosition;
|
2011-12-19 01:11:30 +04:00
|
|
|
finalPosition.xyz /= finalPosition.w;
|
2012-03-19 00:07:25 +04:00
|
|
|
|
|
|
|
$VERTEX_MASK_STUFF<mask>$
|
|
|
|
|
2010-05-25 10:35:35 +04:00
|
|
|
finalPosition = finalPosition - uRenderTargetOffset;
|
2011-12-19 01:11:30 +04:00
|
|
|
finalPosition.xyz *= finalPosition.w;
|
2010-05-25 10:35:35 +04:00
|
|
|
finalPosition = uMatrixProj * finalPosition;
|
|
|
|
|
|
|
|
vTexCoord = aTexCoord;
|
|
|
|
gl_Position = finalPosition;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2012-03-19 00:07:25 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Fragment shaders
|
|
|
|
*/
|
|
|
|
|
|
|
|
@define FRAGMENT_SHADER_HEADER
|
|
|
|
/* Fragment Shader */
|
|
|
|
#ifdef GL_ES
|
|
|
|
precision lowp float;
|
|
|
|
#endif
|
|
|
|
@end
|
|
|
|
|
|
|
|
// fragment shader header for layers
|
|
|
|
@define LAYER_FRAGMENT<>
|
|
|
|
$FRAGMENT_SHADER_HEADER$
|
|
|
|
|
|
|
|
#ifndef NO_LAYER_OPACITY
|
|
|
|
uniform float uLayerOpacity;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GL_ES // for tiling, texcoord can be greater than the lowfp range
|
|
|
|
varying mediump vec2 vTexCoord;
|
|
|
|
#else
|
|
|
|
varying vec2 vTexCoord;
|
|
|
|
#endif
|
|
|
|
@end
|
|
|
|
|
|
|
|
// fragment shader header for layers with masks
|
|
|
|
@define LAYER_FRAGMENT<Mask>
|
|
|
|
$LAYER_FRAGMENT<>$
|
|
|
|
|
|
|
|
varying vec2 vMaskCoord;
|
|
|
|
uniform sampler2D uMaskTexture;
|
|
|
|
@end
|
|
|
|
|
|
|
|
// fragment shader header for layers with masks and 3D transforms
|
|
|
|
@define LAYER_FRAGMENT<Mask3D>
|
|
|
|
$LAYER_FRAGMENT<>$
|
|
|
|
|
|
|
|
varying vec3 vMaskCoord;
|
|
|
|
uniform sampler2D uMaskTexture;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@define FRAGMENT_CALC_MASK<>
|
|
|
|
float mask = 1.0;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@define FRAGMENT_CALC_MASK<Mask>
|
|
|
|
float mask = texture2D(uMaskTexture, vMaskCoord).a;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@define FRAGMENT_CALC_MASK<Mask3D>
|
|
|
|
vec2 maskCoords = vMaskCoord.xy / vMaskCoord.z;
|
|
|
|
float mask = texture2D(uMaskTexture, maskCoords).a;
|
|
|
|
@end
|
|
|
|
|
2010-05-25 10:35:35 +04:00
|
|
|
// Solid color rendering.
|
|
|
|
// texcoords are ignored (no texture to sample).
|
|
|
|
// The layer opacity is baked in to the color.
|
2012-03-19 00:07:25 +04:00
|
|
|
@shader sSolidColorLayer<mask:,Mask>FS
|
2010-05-25 10:35:35 +04:00
|
|
|
#define NO_LAYER_OPACITY 1
|
2012-03-19 00:07:25 +04:00
|
|
|
$LAYER_FRAGMENT<mask>$
|
2010-05-25 10:35:35 +04:00
|
|
|
uniform vec4 uRenderColor;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2012-03-19 00:07:25 +04:00
|
|
|
$FRAGMENT_CALC_MASK<mask>$
|
|
|
|
gl_FragColor = mask * uRenderColor;
|
2010-05-25 10:35:35 +04:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
// Single texture in RGBA format
|
2012-03-19 00:07:25 +04:00
|
|
|
@shader sRGBATextureLayer<mask:,Mask,Mask3D>FS
|
|
|
|
$LAYER_FRAGMENT<mask>$
|
2010-05-25 10:35:35 +04:00
|
|
|
uniform sampler2D uTexture;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2012-03-19 00:07:25 +04:00
|
|
|
$FRAGMENT_CALC_MASK<mask>$
|
|
|
|
gl_FragColor = texture2D(uTexture, vTexCoord) * uLayerOpacity * mask;
|
2010-05-25 10:35:35 +04:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2012-03-19 00:07:25 +04:00
|
|
|
|
2010-05-25 10:35:35 +04:00
|
|
|
// Single texture in RGBA format, but with a Rect texture.
|
|
|
|
// Container layer needs this to render a FBO group.
|
2012-03-19 00:07:25 +04:00
|
|
|
@shader sRGBARectTextureLayer<mask:,Mask,Mask3D>FS
|
2010-05-25 10:35:35 +04:00
|
|
|
#extension GL_ARB_texture_rectangle : enable
|
|
|
|
|
2012-03-19 00:07:25 +04:00
|
|
|
$LAYER_FRAGMENT<mask>$
|
2010-05-25 10:35:35 +04:00
|
|
|
|
|
|
|
/* This should not be used on GL ES */
|
|
|
|
#ifndef GL_ES
|
|
|
|
uniform sampler2DRect uTexture;
|
|
|
|
uniform vec2 uTexCoordMultiplier;
|
|
|
|
void main()
|
|
|
|
{
|
2012-03-19 00:07:25 +04:00
|
|
|
$FRAGMENT_CALC_MASK<mask>$
|
|
|
|
gl_FragColor = texture2DRect(uTexture, vec2(vTexCoord * uTexCoordMultiplier)) * uLayerOpacity * mask;
|
2010-05-25 10:35:35 +04:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
@end
|
|
|
|
|
|
|
|
// Single texture in BGRA format (via swizzle)
|
2012-03-19 00:07:25 +04:00
|
|
|
@shader sBGRATextureLayer<mask:,Mask>FS
|
|
|
|
$LAYER_FRAGMENT<mask>$
|
2010-05-25 10:35:35 +04:00
|
|
|
uniform sampler2D uTexture;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2012-03-19 00:07:25 +04:00
|
|
|
$FRAGMENT_CALC_MASK<mask>$
|
|
|
|
gl_FragColor = texture2D(uTexture, vTexCoord).bgra * uLayerOpacity * mask;
|
2010-05-25 10:35:35 +04:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
// Single texture in RGBX format
|
2012-03-19 00:07:25 +04:00
|
|
|
@shader sRGBXTextureLayer<mask:,Mask>FS
|
|
|
|
$LAYER_FRAGMENT<mask>$
|
2010-05-25 10:35:35 +04:00
|
|
|
uniform sampler2D uTexture;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2012-03-19 00:07:25 +04:00
|
|
|
$FRAGMENT_CALC_MASK<mask>$
|
|
|
|
gl_FragColor = vec4(texture2D(uTexture, vTexCoord).rgb, 1.0) * uLayerOpacity * mask;
|
2010-05-25 10:35:35 +04:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
// Single texture in BGRX format (via swizzle)
|
2012-03-19 00:07:25 +04:00
|
|
|
@shader sBGRXTextureLayer<mask:,Mask>FS
|
|
|
|
$LAYER_FRAGMENT<mask>$
|
2010-05-25 10:35:35 +04:00
|
|
|
uniform sampler2D uTexture;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2012-03-19 00:07:25 +04:00
|
|
|
$FRAGMENT_CALC_MASK<mask>$
|
|
|
|
gl_FragColor = vec4(texture2D(uTexture, vTexCoord).bgr, 1.0) * uLayerOpacity * mask;
|
2010-05-25 10:35:35 +04:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
// Three textures, representing YCbCr planes of a video image
|
2012-03-19 00:07:25 +04:00
|
|
|
@shader sYCbCrTextureLayer<mask:,Mask>FS
|
|
|
|
$LAYER_FRAGMENT<mask>$
|
2011-05-31 01:48:47 +04:00
|
|
|
#ifdef GL_ES
|
|
|
|
precision mediump float;
|
|
|
|
#endif
|
2010-05-25 10:35:35 +04:00
|
|
|
uniform sampler2D uYTexture;
|
|
|
|
uniform sampler2D uCbTexture;
|
|
|
|
uniform sampler2D uCrTexture;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec4 yuv;
|
|
|
|
vec4 color;
|
|
|
|
yuv.r = texture2D(uCrTexture, vTexCoord).r - 0.5;
|
|
|
|
yuv.g = texture2D(uYTexture, vTexCoord).r - 0.0625;
|
|
|
|
yuv.b = texture2D(uCbTexture, vTexCoord).r - 0.5;
|
|
|
|
color.r = yuv.g * 1.164 + yuv.r * 1.596;
|
|
|
|
color.g = yuv.g * 1.164 - 0.813 * yuv.r - 0.391 * yuv.b;
|
|
|
|
color.b = yuv.g * 1.164 + yuv.b * 2.018;
|
|
|
|
color.a = 1.0;
|
2012-03-19 00:07:25 +04:00
|
|
|
$FRAGMENT_CALC_MASK<mask>$
|
|
|
|
gl_FragColor = color * uLayerOpacity * mask;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
// Two textures and two passes for component alpha rendering
|
|
|
|
@shader sComponentPass<mask:,Mask>1FS
|
|
|
|
|
|
|
|
$LAYER_FRAGMENT<mask>$
|
|
|
|
uniform sampler2D uBlackTexture;
|
|
|
|
uniform sampler2D uWhiteTexture;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec3 onBlack = texture2D(uBlackTexture, vTexCoord).bgr;
|
|
|
|
vec3 onWhite = texture2D(uWhiteTexture, vTexCoord).bgr;
|
|
|
|
vec4 alphas = (1.0 - onWhite + onBlack).rgbg;
|
|
|
|
$FRAGMENT_CALC_MASK<mask>$
|
|
|
|
gl_FragColor = alphas * uLayerOpacity * mask;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@shader sComponentPass<mask:,Mask>2FS
|
|
|
|
|
|
|
|
$LAYER_FRAGMENT<mask>$
|
|
|
|
uniform sampler2D uBlackTexture;
|
|
|
|
uniform sampler2D uWhiteTexture;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
vec3 onBlack = texture2D(uBlackTexture, vTexCoord).bgr;
|
|
|
|
vec3 onWhite = texture2D(uWhiteTexture, vTexCoord).bgr;
|
|
|
|
vec4 alphas = (1.0 - onWhite + onBlack).rgbg;
|
|
|
|
$FRAGMENT_CALC_MASK<mask>$
|
|
|
|
gl_FragColor = vec4(onBlack, alphas.a) * uLayerOpacity * mask;
|
2010-05-25 10:35:35 +04:00
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
2012-03-19 00:07:25 +04:00
|
|
|
|
|
|
|
|
2010-05-25 10:35:35 +04:00
|
|
|
//
|
|
|
|
// The "Copy" program is used for blitting a texture to a destination
|
|
|
|
// with no transforms or any other manipulation. They're used for
|
|
|
|
// blitting the contents of a FBO-rendered texture to a destination.
|
|
|
|
//
|
|
|
|
// There are two variants of the fragment shader: one that uses 2D
|
|
|
|
// textures and one that uses 2DRect textures (for when
|
|
|
|
// EXT_TEXTURE_RECTANGLE is used for FBOs).
|
|
|
|
//
|
|
|
|
// On GL ES, EXT_TEXTURE_RECTANGLE isn't available, so we still
|
|
|
|
// compile the shader but have it render pure red. It should never
|
|
|
|
// be used.
|
|
|
|
//
|
|
|
|
|
|
|
|
@shader sCopyVS
|
2012-03-19 00:07:25 +04:00
|
|
|
/* Vertex Shader */
|
2010-05-25 10:35:35 +04:00
|
|
|
|
|
|
|
attribute vec4 aVertexCoord;
|
|
|
|
attribute vec2 aTexCoord;
|
|
|
|
|
|
|
|
varying vec2 vTexCoord;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
gl_Position = aVertexCoord;
|
|
|
|
vTexCoord = aTexCoord;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@shader sCopy2DFS
|
|
|
|
$FRAGMENT_SHADER_HEADER$
|
|
|
|
|
|
|
|
varying vec2 vTexCoord;
|
|
|
|
|
|
|
|
uniform sampler2D uTexture;
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
gl_FragColor = texture2D(uTexture, vTexCoord);
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
@shader sCopy2DRectFS
|
|
|
|
#extension GL_ARB_texture_rectangle : enable
|
|
|
|
|
|
|
|
$FRAGMENT_SHADER_HEADER$
|
|
|
|
|
|
|
|
varying vec2 vTexCoord;
|
|
|
|
uniform vec2 uTexCoordMultiplier;
|
|
|
|
|
|
|
|
#ifndef GL_ES
|
|
|
|
uniform sampler2DRect uTexture;
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
gl_FragColor = texture2DRect(uTexture, vTexCoord * uTexCoordMultiplier);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
@end
|
2011-01-18 10:22:25 +03:00
|
|
|
|