/////////////////////////////////////
// Unbound Visual + PT v9.6 by EminGT //
/////////////////////////////////////

//Common//
#include "/lib/common.glsl"

//////////Begin//////////Begin//////////Begin//////////
#ifdef BEGIN

#if defined CUSTOM_GI_VOXEL_INTERNAL && defined OVERWORLD

layout (local_size_x = 8, local_size_y = 8, local_size_z = 8) in;
#if GI_VOXEL_RESOLUTION == 64
    const ivec3 workGroups = ivec3(8, 8, 8);
#elif GI_VOXEL_RESOLUTION == 128
    const ivec3 workGroups = ivec3(16, 16, 16);
#elif GI_VOXEL_RESOLUTION == 192
    const ivec3 workGroups = ivec3(24, 24, 24);
#elif GI_VOXEL_RESOLUTION == 256
    const ivec3 workGroups = ivec3(32, 32, 32);
#endif

//Common Variables//
writeonly uniform image3D gi_voxel_img;
writeonly uniform image3D gi_radiance_a_img;
writeonly uniform image3D gi_radiance_b_img;
writeonly uniform image3D gi_emission_img;

//Program//
void main() {
    ivec3 pos = ivec3(gl_GlobalInvocationID);

    // Full clear every frame (pasal 2.3's toroidal scrolling optimization is
    // skipped here: the shadow pass already redraws all shadow-casting
    // geometry within shadowDistance every single frame regardless, so a
    // full voxelize + full clear costs nothing extra on top of that).
    //
    // gi_history_img is deliberately NOT declared/cleared here when
    // GI_TEMPORAL_ACCUM is on - it needs to survive from last frame so this
    // frame's injection pass (prepare.glsl) can read it back as the
    // temporal accumulation seed. It's fully overwritten every frame anyway
    // (see the GI_IS_LAST_PASS block in giPropagateBody.glsl), just not by
    // this clear pass.
    imageStore(gi_voxel_img, pos, vec4(0.0));
    imageStore(gi_radiance_a_img, pos, vec4(0.0));
    imageStore(gi_radiance_b_img, pos, vec4(0.0));
    imageStore(gi_emission_img, pos, vec4(0.0));
}

#else

// Dummy invocation so this stage compiles even when the GI system is off.
layout (local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
const ivec3 workGroups = ivec3(1, 1, 1);
void main() {}

#endif

#endif
