2021-05-14 13:12:53 +00:00
|
|
|
//
|
|
|
|
// Phosphor shader - Copyright (C) 2011 caligari.
|
|
|
|
//
|
|
|
|
// Ported by Hyllian.
|
|
|
|
//
|
2021-05-14 16:52:38 +00:00
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License
|
|
|
|
// as published by the Free Software Foundation; either version 2
|
|
|
|
// of the License, or (at your option) any later version.
|
2021-05-14 13:12:53 +00:00
|
|
|
//
|
2021-05-14 16:52:38 +00:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2021-05-14 13:12:53 +00:00
|
|
|
//
|
2021-05-14 16:52:38 +00:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
2021-05-14 13:12:53 +00:00
|
|
|
//
|
2021-05-14 16:52:38 +00:00
|
|
|
// Taken from the RetroArch project and modified for ES-DE.
|
2021-05-14 13:12:53 +00:00
|
|
|
//
|
2020-09-04 16:59:19 +00:00
|
|
|
|
2022-03-14 23:14:06 +00:00
|
|
|
// Vertex section of code:
|
2020-09-04 16:59:19 +00:00
|
|
|
#if defined(VERTEX)
|
|
|
|
|
|
|
|
#ifdef GL_ES
|
2022-03-14 23:14:06 +00:00
|
|
|
precision mediump float;
|
2020-09-04 16:59:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
uniform mat4 MVPMatrix;
|
2022-03-14 23:14:06 +00:00
|
|
|
in vec2 positionVertex;
|
|
|
|
in vec2 texCoordVertex;
|
2022-12-12 20:51:27 +00:00
|
|
|
in vec4 colorVertex;
|
2023-08-31 15:11:32 +00:00
|
|
|
uniform vec2 texSize;
|
2022-12-12 20:51:27 +00:00
|
|
|
|
2022-03-14 23:14:06 +00:00
|
|
|
out vec2 texCoord;
|
|
|
|
out vec2 onex;
|
|
|
|
out vec2 oney;
|
2022-12-12 20:51:27 +00:00
|
|
|
out vec4 colorShift;
|
2020-09-04 16:59:19 +00:00
|
|
|
|
2023-08-31 15:11:32 +00:00
|
|
|
#define SourceSize vec4(texSize, 1.0 / texSize)
|
2020-09-04 16:59:19 +00:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2022-03-14 23:14:06 +00:00
|
|
|
gl_Position = MVPMatrix * vec4(positionVertex, 0.0, 1.0);
|
|
|
|
texCoord = texCoordVertex;
|
2021-05-14 13:12:53 +00:00
|
|
|
onex = vec2(SourceSize.z, 0.0);
|
|
|
|
oney = vec2(0.0, SourceSize.w);
|
2022-12-12 20:51:27 +00:00
|
|
|
colorShift.abgr = colorVertex.rgba;
|
2020-09-04 16:59:19 +00:00
|
|
|
}
|
|
|
|
|
2022-03-14 23:14:06 +00:00
|
|
|
// Fragment section of code:
|
2020-09-04 16:59:19 +00:00
|
|
|
#elif defined(FRAGMENT)
|
|
|
|
|
|
|
|
#ifdef GL_ES
|
|
|
|
precision mediump float;
|
|
|
|
#endif
|
|
|
|
|
2023-08-31 15:11:32 +00:00
|
|
|
uniform vec2 texSize;
|
2022-03-14 23:14:06 +00:00
|
|
|
uniform float opacity;
|
2022-12-14 19:17:41 +00:00
|
|
|
uniform float brightness;
|
2022-03-17 18:33:09 +00:00
|
|
|
uniform float saturation;
|
2023-02-06 22:38:35 +00:00
|
|
|
uniform uint shaderFlags;
|
2023-09-07 19:02:38 +00:00
|
|
|
uniform sampler2D textureSampler0;
|
2022-03-14 23:14:06 +00:00
|
|
|
in vec2 texCoord;
|
|
|
|
in vec2 onex;
|
|
|
|
in vec2 oney;
|
2022-12-12 20:51:27 +00:00
|
|
|
in vec4 colorShift;
|
2022-03-14 23:14:06 +00:00
|
|
|
out vec4 FragColor;
|
2020-09-04 16:59:19 +00:00
|
|
|
|
|
|
|
#ifdef PARAMETER_UNIFORM
|
2022-03-14 23:14:06 +00:00
|
|
|
uniform float SPOT_WIDTH;
|
|
|
|
uniform float SPOT_HEIGHT;
|
|
|
|
uniform float COLOR_BOOST;
|
|
|
|
uniform float InputGamma;
|
|
|
|
uniform float OutputGamma;
|
2020-09-04 16:59:19 +00:00
|
|
|
#else
|
|
|
|
#define SPOT_WIDTH 0.9
|
|
|
|
#define SPOT_HEIGHT 0.75
|
|
|
|
#define COLOR_BOOST 1.45
|
|
|
|
#define InputGamma 2.4
|
|
|
|
#define OutputGamma 2.2
|
|
|
|
#endif
|
|
|
|
|
2021-05-14 13:12:53 +00:00
|
|
|
#define GAMMA_IN(color) pow(color, vec4(InputGamma))
|
|
|
|
#define GAMMA_OUT(color) pow(color, vec4(1.0 / OutputGamma))
|
2020-09-04 16:59:19 +00:00
|
|
|
|
2023-09-07 19:02:38 +00:00
|
|
|
#define TEX2D(coords) GAMMA_IN(texture(textureSampler0, coords))
|
2020-09-04 16:59:19 +00:00
|
|
|
|
2021-05-14 13:12:53 +00:00
|
|
|
// Macro for weights computing.
|
2022-02-15 21:13:11 +00:00
|
|
|
#define WEIGHT(w) \
|
|
|
|
if (w > 1.0) \
|
|
|
|
w = 1.0; \
|
|
|
|
w = 1.0 - w * w; \
|
|
|
|
w = w * w;
|
2020-09-04 16:59:19 +00:00
|
|
|
|
2023-02-06 22:38:35 +00:00
|
|
|
// shaderFlags:
|
|
|
|
// 0x00000001 - Premultiplied alpha (BGRA)
|
|
|
|
// 0x00000002 - Font texture
|
|
|
|
// 0x00000004 - Post processing
|
|
|
|
// 0x00000008 - Clipping
|
|
|
|
// 0x00000010 - Screen rotated 90 or 270 degrees
|
2023-08-20 17:41:07 +00:00
|
|
|
// 0x00000020 - Rounded corners
|
|
|
|
// 0x00000040 - Rounded corners with no anti-aliasing
|
2023-02-06 22:38:35 +00:00
|
|
|
|
2020-09-04 16:59:19 +00:00
|
|
|
void main()
|
|
|
|
{
|
2023-02-06 22:38:35 +00:00
|
|
|
bool rotated = false;
|
|
|
|
if (0x0u != (shaderFlags & 0x10u))
|
|
|
|
rotated = true;
|
|
|
|
|
|
|
|
vec4 SourceSize;
|
|
|
|
if (rotated)
|
2023-08-31 15:11:32 +00:00
|
|
|
SourceSize = vec4(texSize.yx, 1.0 / texSize.yx);
|
2023-02-06 22:38:35 +00:00
|
|
|
else
|
2023-08-31 15:11:32 +00:00
|
|
|
SourceSize = vec4(texSize.xy, 1.0 / texSize.xy);
|
2023-02-06 22:38:35 +00:00
|
|
|
|
2022-03-14 23:14:06 +00:00
|
|
|
vec2 coords = (texCoord * SourceSize.xy);
|
2021-05-14 13:12:53 +00:00
|
|
|
vec2 pixel_center = floor(coords) + vec2(0.5, 0.5);
|
|
|
|
vec2 texture_coords = pixel_center * SourceSize.zw;
|
|
|
|
|
|
|
|
vec4 color = TEX2D(texture_coords);
|
|
|
|
float dx = coords.x - pixel_center.x;
|
|
|
|
|
|
|
|
float h_weight_00 = dx / SPOT_WIDTH;
|
|
|
|
WEIGHT(h_weight_00);
|
|
|
|
|
2022-02-15 21:13:11 +00:00
|
|
|
color *= vec4(h_weight_00, h_weight_00, h_weight_00, h_weight_00);
|
2021-05-14 13:12:53 +00:00
|
|
|
|
|
|
|
// Get closest horizontal neighbour to blend.
|
|
|
|
vec2 coords01;
|
|
|
|
if (dx > 0.0) {
|
2021-05-14 13:22:14 +00:00
|
|
|
coords01 = onex;
|
|
|
|
dx = 1.0 - dx;
|
2021-05-14 13:12:53 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-14 13:22:14 +00:00
|
|
|
coords01 = -onex;
|
|
|
|
dx = 1.0 + dx;
|
2021-05-14 13:12:53 +00:00
|
|
|
}
|
|
|
|
vec4 colorNB = TEX2D(texture_coords + coords01);
|
|
|
|
|
|
|
|
float h_weight_01 = dx / SPOT_WIDTH;
|
|
|
|
WEIGHT(h_weight_01);
|
|
|
|
|
|
|
|
color = color + colorNB * vec4(h_weight_01);
|
|
|
|
|
|
|
|
// Vertical blending.
|
2023-02-06 22:38:35 +00:00
|
|
|
float dy;
|
|
|
|
if (rotated)
|
|
|
|
dy = coords.x - pixel_center.x;
|
|
|
|
else
|
|
|
|
dy = coords.y - pixel_center.y;
|
2021-05-14 13:12:53 +00:00
|
|
|
float v_weight_00 = dy / SPOT_HEIGHT;
|
|
|
|
WEIGHT(v_weight_00);
|
|
|
|
color *= vec4(v_weight_00);
|
|
|
|
|
2022-03-14 23:14:06 +00:00
|
|
|
// Get closest vertical neighbour to blend.
|
2021-05-14 13:12:53 +00:00
|
|
|
vec2 coords10;
|
|
|
|
if (dy > 0.0) {
|
2021-05-14 13:22:14 +00:00
|
|
|
coords10 = oney;
|
|
|
|
dy = 1.0 - dy;
|
2021-05-14 13:12:53 +00:00
|
|
|
}
|
|
|
|
else {
|
2021-05-14 13:22:14 +00:00
|
|
|
coords10 = -oney;
|
|
|
|
dy = 1.0 + dy;
|
2021-05-14 13:12:53 +00:00
|
|
|
}
|
|
|
|
colorNB = TEX2D(texture_coords + coords10);
|
|
|
|
|
|
|
|
float v_weight_10 = dy / SPOT_HEIGHT;
|
|
|
|
WEIGHT(v_weight_10);
|
|
|
|
|
|
|
|
color = color + colorNB * vec4(v_weight_10 * h_weight_00, v_weight_10 * h_weight_00,
|
2022-02-15 21:13:11 +00:00
|
|
|
v_weight_10 * h_weight_00, v_weight_10 * h_weight_00);
|
2021-05-14 13:12:53 +00:00
|
|
|
colorNB = TEX2D(texture_coords + coords01 + coords10);
|
|
|
|
color = color + colorNB * vec4(v_weight_10 * h_weight_01, v_weight_10 * h_weight_01,
|
2022-02-15 21:13:11 +00:00
|
|
|
v_weight_10 * h_weight_01, v_weight_10 * h_weight_01);
|
2021-05-14 13:12:53 +00:00
|
|
|
color *= vec4(COLOR_BOOST);
|
|
|
|
|
2022-02-15 21:13:11 +00:00
|
|
|
vec4 colorTemp = clamp(GAMMA_OUT(color), 0.0, 1.0);
|
2022-12-12 19:24:16 +00:00
|
|
|
|
2022-12-14 19:17:41 +00:00
|
|
|
// Brightness.
|
2022-12-14 22:09:17 +00:00
|
|
|
if (brightness != 0.0) {
|
2022-12-15 18:13:37 +00:00
|
|
|
colorTemp.rgb /= colorTemp.a;
|
2022-12-14 22:09:17 +00:00
|
|
|
colorTemp.rgb += 0.3 * brightness;
|
|
|
|
colorTemp.rgb *= colorTemp.a;
|
|
|
|
}
|
2022-12-14 19:17:41 +00:00
|
|
|
|
2022-12-12 19:24:16 +00:00
|
|
|
// Saturation.
|
|
|
|
if (saturation != 1.0) {
|
|
|
|
vec3 grayscale;
|
2022-12-13 21:45:05 +00:00
|
|
|
grayscale = vec3(dot(colorTemp.bgr, vec3(0.114, 0.587, 0.299)));
|
2022-12-12 19:24:16 +00:00
|
|
|
vec3 blendedColor = mix(grayscale, colorTemp.rgb, saturation);
|
|
|
|
colorTemp = vec4(blendedColor, colorTemp.a);
|
|
|
|
}
|
|
|
|
|
2022-12-12 20:51:27 +00:00
|
|
|
// Color shift.
|
|
|
|
colorTemp.rgb *= colorShift.rgb;
|
|
|
|
colorTemp.a *= colorShift.a;
|
|
|
|
|
2022-02-15 21:13:11 +00:00
|
|
|
FragColor = vec4(colorTemp.rgb, colorTemp.a * opacity);
|
2020-09-04 16:59:19 +00:00
|
|
|
}
|
|
|
|
#endif
|