<!-- 
osgEarth Sample - Per-layer GLSL shader injection
-->

<Map>    
    <GDALImage name="world-tiff">
        <url>../data/world.tif</url>
        <shader>
          <![CDATA[
            #pragma vp_function cycle_monochrome, fragment
            uniform float osg_FrameTime;
            uniform vec3 oe_Camera;
            
            vec3 rgb_to_ycbcr(in vec3 rgb)
            {
                float y = 0.299 * rgb.r + 0.587 * rgb.g + 0.114 * rgb.b;
                return vec3(y, (rgb.b - y) * 0.565, (rgb.r - y) * 0.713);
            }
            
            vec3 ycbcr_to_rgb(in vec3 ycc)
            {
                return vec3(ycc.x + 1.403 * ycc.z, ycc.x - 0.344 * ycc.y - 0.714 * ycc.z, ycc.x + 1.770 * ycc.y);
            }
            
            void cycle_monochrome(inout vec4 color)
            {
                float t =  0.5 * (sin(osg_FrameTime) + 1.0);
                float y = float(gl_FragCoord.y) / float(oe_Camera.y);
                if (abs(y-t) < 0.001) {
                    color = vec4(1,1,0,1);
                }
                else if (t > y) {
                    vec3 ycbcr = rgb_to_ycbcr(color.rgb);
                    ycbcr[1] = ycbcr[2] = 0.0;
                    color.rgb = ycbcr_to_rgb(ycbcr.xyz);
                }
            }            
          ]]>
        </shader>
    </GDALImage>
</Map>
