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.
|
|
|
|
//
|
|
|
|
|
|
|
|
// Vertex section of code:
|
2022-03-14 23:14:06 +00:00
|
|
|
#if defined(VERTEX)
|
2022-03-11 22:17:04 +00:00
|
|
|
|
|
|
|
uniform mat4 MVPMatrix;
|
2022-03-14 23:14:06 +00:00
|
|
|
in vec2 positionVertex;
|
|
|
|
in vec2 texCoordVertex;
|
|
|
|
in vec4 colorVertex;
|
|
|
|
|
|
|
|
out vec4 color;
|
|
|
|
out vec2 texCoord;
|
2022-03-11 22:17:04 +00:00
|
|
|
|
|
|
|
void main(void)
|
|
|
|
{
|
2022-03-14 23:14:06 +00:00
|
|
|
gl_Position = MVPMatrix * vec4(positionVertex.xy, 0.0, 1.0);
|
|
|
|
texCoord = texCoordVertex;
|
|
|
|
color.rgba = colorVertex.abgr;
|
2022-03-11 22:17:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fragment section of code:
|
2022-03-14 23:14:06 +00:00
|
|
|
#elif defined(FRAGMENT)
|
2022-03-11 22:17:04 +00:00
|
|
|
|
2022-03-13 22:52:32 +00:00
|
|
|
#ifdef GL_ES
|
2022-03-14 23:14:06 +00:00
|
|
|
precision mediump float;
|
2022-03-13 22:52:32 +00:00
|
|
|
#endif
|
|
|
|
|
2022-03-14 23:14:06 +00:00
|
|
|
in vec4 color;
|
|
|
|
in vec2 texCoord;
|
|
|
|
uniform float opacity;
|
|
|
|
uniform float saturation;
|
|
|
|
uniform float dimming;
|
2022-03-14 23:25:02 +00:00
|
|
|
uniform uint shaderFlags;
|
2022-03-14 23:14:06 +00:00
|
|
|
|
2022-03-14 21:30:24 +00:00
|
|
|
uniform sampler2D textureSampler;
|
2022-03-14 23:14:06 +00:00
|
|
|
out vec4 FragColor;
|
2022-03-14 21:30:24 +00:00
|
|
|
|
|
|
|
// shaderFlags:
|
|
|
|
// 0x00000001 - BGRA to RGBA conversion
|
|
|
|
// 0x00000002 - Font texture
|
|
|
|
// 0x00000004 - Post processing
|
2022-03-11 22:17:04 +00:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2022-03-14 23:14:06 +00:00
|
|
|
vec4 sampledColor = texture(textureSampler, texCoord);
|
2022-03-13 22:52:32 +00:00
|
|
|
|
|
|
|
// For fonts the alpha information is stored in the red channel.
|
2022-03-14 21:30:24 +00:00
|
|
|
if (0u != (shaderFlags & 2u))
|
2022-03-14 23:14:06 +00:00
|
|
|
sampledColor = vec4(1.0, 1.0, 1.0, sampledColor.r);
|
2022-03-13 22:52:32 +00:00
|
|
|
|
|
|
|
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.
|
2022-03-14 21:30:24 +00:00
|
|
|
if (0u != (shaderFlags & 4u))
|
2022-03-14 23:14:06 +00:00
|
|
|
sampledColor.a = 1.0;
|
2022-03-12 16:57:59 +00:00
|
|
|
|
2022-03-11 22:17:04 +00:00
|
|
|
// Opacity.
|
2022-03-14 23:14:06 +00:00
|
|
|
if (opacity != 1.0)
|
2022-03-13 22:52:32 +00:00
|
|
|
sampledColor.a = sampledColor.a * opacity;
|
2022-03-11 22:17:04 +00:00
|
|
|
|
|
|
|
// Saturation.
|
2022-03-14 23:14:06 +00:00
|
|
|
if (saturation != 1.0) {
|
|
|
|
vec3 grayscale = vec3(dot(sampledColor.rgb, vec3(0.34, 0.55, 0.11)));
|
|
|
|
vec3 blendedColor = mix(grayscale, sampledColor.rgb, saturation);
|
2022-03-13 22:52:32 +00:00
|
|
|
sampledColor = vec4(blendedColor, sampledColor.a);
|
2022-03-11 22:17:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Dimming
|
2022-03-14 23:14:06 +00:00
|
|
|
if (dimming != 1.0) {
|
|
|
|
vec4 dimColor = vec4(dimming, dimming, dimming, 1.0);
|
2022-03-13 22:52:32 +00:00
|
|
|
sampledColor *= dimColor;
|
2022-03-12 13:22:27 +00:00
|
|
|
}
|
2022-03-11 22:17:04 +00:00
|
|
|
|
|
|
|
// BGRA to RGBA conversion.
|
2022-03-14 21:30:24 +00:00
|
|
|
if (0u != (shaderFlags & 1u))
|
2022-03-15 16:14:55 +00:00
|
|
|
sampledColor = sampledColor.bgra;
|
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
|