#version 430

layout(binding=0) uniform sampler2D tex;

in vec2 uv;

layout(location = 0) out vec4 frag;
// layout(location = 1) out vec4 frag2;

uniform float g_time;
/*
float rand(vec2 co){
    return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);
}

vec3 tonemapUC2(vec3 x) {
    float A = 0.15;
    float B = 0.50;
    float C = 0.10;
    float D = 0.20;
    float E = 0.02;
    float F = 0.30;
    return ((x*(A*x+C*B)+D*E)/(x*(A*x+B)+D*F))-E/F;
}
*/
uniform float flip=1.0;

uniform float overlayAlpha=1.0;

layout(binding=0, r32i) uniform iimage2D texImageInt32;
// layout(binding=0, rgba32f) uniform image2D texImageInt32;

// uniform vec2 g_texSize = vec2(512.0, 512.0); // TBD set this!
// uniform vec2 g_texSize = vec2(1000.0, 1000.0); // TBD set this!
//uniform vec2 g_texSize = vec2(1000.0, 1000.0); // TBD set this!

void main() {

    vec2 uvS = uv;
 //   uvS.y = 1.0-uvS.y;

    ivec2 size = imageSize(texImageInt32);

    ivec4 texInt = imageLoad(texImageInt32, ivec2(uvS*size));
    // vec4 texInt = imageLoad(texImageInt32, ivec2(uvS*size));
    //vec4 texInt = imageLoad(texImageInt32, ivec2(128, 100));
 //   vec4 screen = texture2D(tex, uvS+vec2(0.0, 0.0));
    // screen.a = 1.0;
 //   texInt = screen;
    frag = fract(vec4(texInt.r)*0.01);
    // frag = fract(texInt*1.0);
    //if (texInt.r == 0) frag.r = 0.0; else frag.r = 1.0;
    //frag.rg = uv;
    frag.a = 1.0;
}

