[vert.glsl]

#version 120

attribute vec2 in_Position;

varying vec2 pass_position;

void main()
{
    pass_position = in_Position;
    gl_Position = vec4(in_Position, 0.0, 1.0);
}

[frag.glsl]

#version 120

#if defined GL_ES
precision highp float;
#endif

uniform sampler2D in_texture;
varying vec2 pass_position;

vec3 rand_color(float t)
{
    return vec3(0.5 + 0.5 * sin(t * 19.0 + 17.0),
                0.5 + 0.5 * sin(t * 24.0 + 23.0),
                0.5 + 0.5 * sin(t * 37.0 + 12.0));
}

void main(void)
{
    vec2 texcoords = pass_position * 0.5 + vec2(0.5, 0.5);
    vec4 src_color = texture2D(in_texture, texcoords);
    float newg = src_color.z;
    float newb = 0.0;
    if (newg > 0.0)
        newb = 1.0;
    gl_FragColor = vec4(rand_color(newg), 1.0);
}

[vert.hlsl]

void main(float2 in_Position : POSITION,
          out float2 pass_Position : TEXCOORD0,
          out float4 out_Position : POSITION)
{
    pass_Position = in_Position;
    out_Position = float4(in_Position, 0.0, 1.0);
}

[frag.hlsl]

float3 rand_color(float t)
{
    return float3(0.5 + 0.5 * sin(t * 9.0 + 3.0),
                  0.5 + 0.5 * sin(t * 4.0 + 1.0),
                  0.5 + 0.5 * sin(t * 7.0 + 2.0));
}

void main(in float2 pass_Position : TEXCOORD0,
          uniform sampler2D u_texture,
          uniform float in_Flag,
          uniform float3 in_Point,
          uniform float3 in_Color,
          out float4 out_FragColor : COLOR)
{
    if (in_Flag == 0.0)
    {
        float tc = 0.0, ta = 0.0;
        {
            float s = 3.0 + 2.0 * in_Point.z;
            float2 p = pass_Position - in_Point.xy * 0.9;
            float t = clamp(1.2 - dot(s * p, s * p), 0.0, 1.0);
            float u = t * t * t * t;
            tc += 3.0 * t * t - 2.0 * t * t * t;
            ta += 3.0 * u * u - 2.0 * u * u * u;
        }

        out_FragColor = float4(tc * in_Color, ta + 0.1);
    }
    else
    {
        float2 texcoords = pass_Position * float2(0.5, -0.5) + float2(0.5, 0.5);
        /* FIXME: this should be passed as a uniform or something */
        texcoords += float2(0.5 / 800.0, 0.5 / 600.0);
        out_FragColor = float4(tex2D(u_texture, texcoords).xyz, 1.0);
    }
}