@@ -5,14 +5,25 @@ uniform sampler2D rgb_texture;
55uniform sampler2D y_texture ;
66// CbCr component texture (Feed ID 2 -> FEED_CBCR_IMAGE)
77uniform sampler2D cbcr_texture ;
8- // mode: 0 -> RGB, mode: 1 -> YCbCr
9- uniform int mode : hint_range (0 , 1 );
8+ // YCbCr component texture (Feed ID 1 -> FEED_YCBCR_IMAGE)
9+ uniform sampler2D ycbcr_texture ;
10+ // mode: 0 -> RGB, mode: 1 -> YCbCr_sep, mode: 2 -> YCbCr
11+ uniform int mode : hint_range (0 , 2 );
1012
1113// YCbCr to RGB conversion (BT.601 standard)
1214void fragment () {
1315 vec3 color ;
14- color .r = texture (y_texture , UV ).r ;
15- color .gb = texture (cbcr_texture , UV ).rg - vec2 (0.5 , 0.5 );
16+
17+ if (mode == 1 ) {
18+ color .r = texture (y_texture , UV ).r ;
19+ color .gb = texture (cbcr_texture , UV ).rg - vec2 (0.5 , 0.5 );
20+ } else if (mode == 2 ) {
21+ vec2 UV_u = UV - floor (mod (UV / TEXTURE_PIXEL_SIZE , 2 )) * vec2 (1 , 0 ) * TEXTURE_PIXEL_SIZE ;
22+ vec2 UV_v = UV + (vec2 (1 , 0 ) - floor (mod (UV / TEXTURE_PIXEL_SIZE , 2 ))) * vec2 (1 , 0 ) * TEXTURE_PIXEL_SIZE ;
23+ color .r = texture (ycbcr_texture , UV ).r ;
24+ color .g = texture (ycbcr_texture , UV_u ).g - 0.5 ;
25+ color .b = texture (ycbcr_texture , UV_v ).g - 0.5 ;
26+ }
1627
1728 // YCbCr -> SRGB conversion
1829 // Using BT.709 which is the standard for HDTV
@@ -23,5 +34,5 @@ void fragment() {
2334 * color .rgb ;
2435
2536 vec3 rgb = texture (rgb_texture , UV ).rgb ;
26- COLOR = vec4 (mix (rgb , color , float (mode )), 1.0 );
37+ COLOR = vec4 (mix (rgb , color , clamp ( float (mode ), 0.0 , 1.0 )), 1.0 );
2738}
0 commit comments