2022-03-11 22:17:04 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
//
|
|
|
|
// EmulationStation Desktop Edition
|
|
|
|
// core.glsl
|
|
|
|
//
|
|
|
|
// Core shader functionality:
|
|
|
|
// opacity, saturation, dimming and BGRA to RGBA conversion.
|
|
|
|
//
|
|
|
|
|
|
|
|
#if defined(VERTEX)
|
|
|
|
// Vertex section of code:
|
|
|
|
|
|
|
|
#if __VERSION__ >= 130
|
|
|
|
#define COMPAT_VARYING out
|
2022-03-13 22:52:32 +00:00
|
|
|
#define COMPAT_ATTRIBUTE in
|
2022-03-11 22:17:04 +00:00
|
|
|
#else
|
|
|
|
#define COMPAT_VARYING varying
|
2022-03-13 22:52:32 +00:00
|
|
|
#define COMPAT_ATTRIBUTE attribute
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef GL_ES
|
|
|
|
#define COMPAT_PRECISION mediump
|
|
|
|
#else
|
|
|
|
#define COMPAT_PRECISION
|
2022-03-11 22:17:04 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
uniform mat4 MVPMatrix;
|
2022-03-13 22:52:32 +00:00
|
|
|
COMPAT_ATTRIBUTE vec2 positionAttrib;
|
|
|
|
COMPAT_ATTRIBUTE vec2 TexCoord;
|
|
|
|
COMPAT_ATTRIBUTE vec4 colorAttrib;
|
2022-03-11 22:17:04 +00:00
|
|
|
COMPAT_VARYING vec4 color;
|
|
|
|
COMPAT_VARYING vec2 texCoord;
|
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
2022-03-13 22:52:32 +00:00
|
|
|
color.rgba = colorAttrib.abgr;
|
|
|
|
texCoord = TexCoord;
|
|
|
|
gl_Position = MVPMatrix * vec4(positionAttrib.xy, 0.0, 1.0);
|
2022-03-11 22:17:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#elif defined(FRAGMENT)
|
|
|
|
// Fragment section of code:
|
|
|
|
|
2022-03-13 22:52:32 +00:00
|
|
|
#ifdef GL_ES
|
|
|
|
#define COMPAT_PRECISION mediump
|
|
|
|
#else
|
|
|
|
#define COMPAT_PRECISION
|
|
|
|
#endif
|
|
|
|
|
2022-03-11 22:17:04 +00:00
|
|
|
#if __VERSION__ >= 130
|
2022-03-13 22:52:32 +00:00
|
|
|
#define COMPAT_VARYING in
|
2022-03-11 22:17:04 +00:00
|
|
|
#define COMPAT_TEXTURE texture
|
2022-03-13 22:52:32 +00:00
|
|
|
out COMPAT_PRECISION vec4 FragColor;
|
2022-03-11 22:17:04 +00:00
|
|
|
#else
|
|
|
|
#define COMPAT_VARYING varying
|
|
|
|
#define COMPAT_TEXTURE texture2D
|
2022-03-13 22:52:32 +00:00
|
|
|
#define FragColor gl_FragColor
|
2022-03-11 22:17:04 +00:00
|
|
|
#endif
|
|
|
|
|
2022-03-13 22:52:32 +00:00
|
|
|
COMPAT_VARYING COMPAT_PRECISION vec4 color;
|
|
|
|
COMPAT_VARYING COMPAT_PRECISION vec4 color2;
|
|
|
|
COMPAT_VARYING COMPAT_PRECISION vec2 texCoord;
|
|
|
|
uniform COMPAT_PRECISION float opacity;
|
|
|
|
uniform COMPAT_PRECISION float saturation;
|
|
|
|
uniform COMPAT_PRECISION float dimming;
|
|
|
|
uniform int BGRAToRGBA;
|
|
|
|
uniform int font;
|
|
|
|
uniform int postProcessing;
|
2022-03-11 22:17:04 +00:00
|
|
|
uniform sampler2D myTexture;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2022-03-13 22:52:32 +00:00
|
|
|
COMPAT_PRECISION vec4 sampledColor = COMPAT_TEXTURE(myTexture, texCoord);
|
|
|
|
|
|
|
|
// For fonts the alpha information is stored in the red channel.
|
|
|
|
if (font == 1)
|
|
|
|
sampledColor = vec4(1.0f, 1.0f, 1.0f, sampledColor.r);
|
|
|
|
|
|
|
|
sampledColor *= color;
|
2022-03-11 22:17:04 +00:00
|
|
|
|
2022-03-12 16:57:59 +00:00
|
|
|
// When post-processing we drop the alpha channel to avoid strange issues
|
|
|
|
// with some graphics drivers.
|
|
|
|
if (postProcessing == 1)
|
2022-03-13 22:52:32 +00:00
|
|
|
sampledColor.a = 1.0f;
|
2022-03-12 16:57:59 +00:00
|
|
|
|
2022-03-11 22:17:04 +00:00
|
|
|
// Opacity.
|
|
|
|
if (opacity != 1.0f)
|
2022-03-13 22:52:32 +00:00
|
|
|
sampledColor.a = sampledColor.a * opacity;
|
2022-03-11 22:17:04 +00:00
|
|
|
|
|
|
|
// Saturation.
|
|
|
|
if (saturation != 1.0f) {
|
2022-03-13 22:52:32 +00:00
|
|
|
COMPAT_PRECISION vec3 grayscale = vec3(dot(sampledColor.rgb, vec3(0.34f, 0.55f, 0.11f)));
|
|
|
|
COMPAT_PRECISION vec3 blendedColor = mix(grayscale, sampledColor.rgb, saturation);
|
|
|
|
sampledColor = vec4(blendedColor, sampledColor.a);
|
2022-03-11 22:17:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dimming
|
2022-03-12 13:22:27 +00:00
|
|
|
if (dimming != 1.0f) {
|
2022-03-13 22:52:32 +00:00
|
|
|
COMPAT_PRECISION vec4 dimColor = vec4(dimming, dimming, dimming, 1.0f);
|
|
|
|
sampledColor *= dimColor;
|
2022-03-12 13:22:27 +00:00
|
|
|
}
|
2022-03-11 22:17:04 +00:00
|
|
|
|
|
|
|
// BGRA to RGBA conversion.
|
|
|
|
if (BGRAToRGBA == 1)
|
2022-03-13 22:52:32 +00:00
|
|
|
sampledColor = vec4(sampledColor.bgr, sampledColor.a);
|
2022-03-11 22:17:04 +00:00
|
|
|
|
2022-03-13 22:52:32 +00:00
|
|
|
FragColor = sampledColor;
|
2022-03-11 22:17:04 +00:00
|
|
|
}
|
|
|
|
#endif
|