#version 430

// layout(binding=0, r32i) uniform iimage2D pardexBucketPrefix;
layout(binding=0, r32i) uniform iimage2D testFixed;
layout(binding=1, r32i) uniform iimage2D pardexBucketCounts;
layout(binding=2, r32f) uniform image2D pardexTransmittance;

layout(binding=3, r32i) uniform iimage2D pardexFree;
layout(binding=4, r32i) uniform iimage2D pardexActive;
layout(binding=5, rgba32f) uniform image2D pardexPos;
layout(binding=6, rgba32f) uniform image2D pardexAge;

uniform float loop = 0.0;
uniform float wkw = 0.0;

layout(location = 0) out vec4 frag;

ivec2 getTrip(int idt) {
    ivec2 triBufSize = imageSize(pardexBucketCounts);
    ivec2 trip;
    trip.y = idt/triBufSize.x;
    trip.x = idt-trip.y*triBufSize.x;
   // trip.y = 0;
    return trip;
}

int getInd(ivec2 uvi) {
    return uvi.x+uvi.y*int(wkw);
}

void main() {
    ivec2 uv = ivec2(gl_FragCoord.xy*0.25);


    // int bp = imageLoad(pardexBucketPrefix, uv).x;
   // float bp = imageLoad(pardexTransmittance, ivec2(uv*4.0)+0*ivec2(2048,2048)).x;
   //  int bp = imageLoad(pardexTransmittance, ivec2(0)).x;
    //float bp = imageLoad(pardexFree, ivec2(uv*1.0)+0*ivec2(2048,2048)).x;
    //float bp = imageLoad(pardexActive, ivec2(uv*1.0)+0*ivec2(2048,2048)).x;
   // float bp = imageLoad(pardexAge, ivec2(uv*1.0)+0*ivec2(2048,2048)).x;
   // frag = vec4(bp)/1000000.0;

 //   vec4 bp = imageLoad(pardexPos, ivec2(uv.x*1.0, uv.y*1.0)+0*ivec2(2048,2048));
 //   frag = vec4(bp)*0.20;
/*
    float bp = imageLoad(pardexAgeLeft, ivec2(uv*4.0)+0*ivec2(2048,2048)).x;
    frag = vec4(bp)*0.5;
    */
/*
    bp = imageLoad(pardexFree, ivec2(uv*4.0)+0*ivec2(2048,2048)).x;
  //  frag = vec4(bp)*0.0000001;
*/

    int fix = imageLoad(testFixed, uv).x;

    if (fix == 0) {
        frag.rgb = vec3(0.0);
    } else if (fix == 1) {
        frag.rgb = vec3(0.0, 1.0, 0.0);
    } else {
        frag.rgb = vec3(1.0, 0.0, 0.0);
    }

    // frag.rgb = vec3(0.0, 0.0, 1.0);

    //frag.r = 1.0;
//    frag = vec4(bp)*0.005;
//    frag = vec4(bp)*0.0000005;


    //bp = imageLoad(pardexBucketCounts, uv).x;
    //frag = vec4(bp)*0.15;

    //frag.rgb = vec3(1.0, 0.0, 0.0);
    frag.a = 1.0;
}
