2023-08-10 22:46:04 +00:00
|
|
|
uniform sampler2D u_texture_y; /*unit0*/
|
|
|
|
uniform sampler2D u_texture_cb; /*unit1*/
|
|
|
|
uniform sampler2D u_texture_cr; /*unit2*/
|
2023-08-10 21:53:51 +00:00
|
|
|
uniform float u_gamma;
|
|
|
|
|
|
|
|
in vec2 uv;
|
|
|
|
out vec4 fragcolor;
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
float y = texture(u_texture_y, uv).r;
|
|
|
|
float cb = texture(u_texture_cb, uv).r;
|
|
|
|
float cr = texture(u_texture_cr, uv).r;
|
|
|
|
|
|
|
|
const mat4 to_rgb = mat4(
|
|
|
|
1.0000, 1.0000, 1.0000, 0.0000,
|
|
|
|
0.0000, -0.3441, 1.7720, 0.0000,
|
|
|
|
1.4020, -0.7141, 0.0000, 0.0000,
|
|
|
|
-0.7010, 0.5291, -0.8860, 1.0000
|
|
|
|
);
|
|
|
|
vec4 texel = to_rgb * vec4(y, cb, cr, 1.0);
|
2023-08-10 22:46:04 +00:00
|
|
|
/* same as:
|
|
|
|
vec3 yCbCr = vec3(y,cb-0.5,cr-0.5);
|
|
|
|
vec4 texel = vec4( dot( vec3( 1.0, 0.0, 1.402 ), yCbCr ),
|
|
|
|
dot( vec3( 1.0 , -0.34414 , -0.71414 ), yCbCr ),
|
|
|
|
dot( vec3( 1.0, 1.772, 0.0 ), yCbCr ), 1.0);
|
|
|
|
*/
|
|
|
|
// gamma correction
|
2023-08-10 21:53:51 +00:00
|
|
|
texel.rgb = pow(texel.rgb, vec3(1.0 / u_gamma));
|
|
|
|
|
2023-08-10 22:46:04 +00:00
|
|
|
// saturation (algorithm from Chapter 16 of OpenGL Shading Language)
|
2023-08-10 21:53:51 +00:00
|
|
|
if(false) { float saturation = 2.0; const vec3 W = vec3(0.2125, 0.7154, 0.0721);
|
|
|
|
vec3 intensity = vec3(dot(texel.rgb, W));
|
|
|
|
texel.rgb = mix(intensity, texel.rgb, saturation); }
|
|
|
|
|
|
|
|
fragcolor = vec4(texel.rgb, 1.0);
|
|
|
|
}
|