News:

--

Main Menu

GLSL YUV pixel shader loader

Started by butterw, January 29, 2021, 11:21:01 PM

Previous topic - Next topic

butterw

Using OpenGL output (rather than D3D/DXVA2 on Windows), gpu pixel shaders can be loaded with filter>OpenGL>  shader loader.

A single GLSL source file is required instead of a compiled C++ plugin.

https://avidemux.org/smif/index.php?topic=16893.0

butterw

#1
Available inputs are: Y texture, subsampled U, V textures, input xy resolution, pts time, and xy screen position pos
Output is gl_FragColor

As an example, a 4-level luma_map.shader
output can be color or grayscale.
the values in #define can be changed in the code.

#extension GL_ARB_texture_rectangle: enable
uniform sampler2DRect myTextureY;
uniform sampler2DRect myTextureU;
uniform sampler2DRect myTextureV;
uniform vec2  myResolution;
uniform float pts;
const vec2 haalf_vec=vec2(0.5, 0.5);

void main(void){
    vec2 pos = gl_TexCoord[0].xy ;
    float lum=texture2DRect(myTextureY, pos).r;
    #define C3 0.95
    #define C2 0.7
    #define C1 0.45
    #define C0 0.1
    lum = (lum>0.8) ? C3: (lum>0.6) ? C2: (lum>0.2) ? C1: C0;
    float chromaU=texture2DRect(myTextureU, pos*haalf_vec).r;
    float chromaV=texture2DRect(myTextureV, pos*haalf_vec).r;
    gl_FragColor = vec4(lum, chromaU, chromaV, 1.0);
    // gl_FragColor = vec4(lum, 0.5, 0.5, 1.0); //Greyscale output
}