/*{
    "CREDIT": "Diagnostic - not an effect",
    "DESCRIPTION": "Isolates when IMG_SIZE fails in Magic. Two-pass shader throughout; only the code varies. Set TEST to 1, 2 then 3, reloading each time, and note which compile.",
    "ISFVSN": "2",
    "CATEGORIES": [ "Utility" ],
    "INPUTS": [
        {
            "NAME": "inputImage",
            "TYPE": "image"
        }
    ],
    "PASSES": [
        {
            "TARGET": "bufTest",
            "WIDTH": 64,
            "HEIGHT": 64
        },
        {
        }
    ]
}*/

// ---------------------------------------------------------------------------
// Every test below is the SAME two-pass shader.  Only the final pass differs.
//
//   TEST 1  no size query at all            - baseline, must compile
//   TEST 2  size of the INPUT IMAGE         - in a multi-pass shader
//   TEST 3  size of the PASS TARGET         - the buffer
//
// Set TEST, reload, note which numbers compile and the exact error text for
// any that do not.  A passing test shows a red/green ramp with a blue tint.
// ---------------------------------------------------------------------------

#define TEST 3


void main() {

    if (PASSINDEX == 0) {
        gl_FragColor = vec4(0.5, 0.25, 0.125, 1.0);
        return;
    }

    vec2 q = gl_FragCoord.xy / RENDERSIZE;
    vec3 tint = vec3(0.0, 0.0, 1.0);

#if TEST == 2
    vec2 sz = IMG_SIZE(inputImage);
    tint = vec3(sz / 4096.0, 1.0);
#endif

#if TEST == 3
    vec2 sz = IMG_SIZE(bufTest);
    tint = vec3(sz / 4096.0, 1.0);
#endif

    gl_FragColor = vec4(q, 0.0, 1.0) * vec4(tint, 1.0)
                 + 0.25 * IMG_NORM_PIXEL(bufTest, q);
}