#[compute]
#version 450

layout( local_size_x = 8, local_size_y = 8, local_size_z = 1 ) in;

layout( rgba16f, set = 0, binding = 0) 
uniform image2D color_image;

layout( set = 1, binding = 0) 
uniform sampler2D depth_sampler;


layout(push_constant, std430)
uniform Params 
{
	vec2 raster_size;
	vec2 amounts;
  float power;

} params;

float sample_depth( ivec2 coord ) 
{
    coord = clamp( coord, ivec2( 0 ), ivec2( params.raster_size ) - ivec2( 1 ) );

    vec2 uv = ( vec2( coord ) + 0.5 ) / params.raster_size;
    return texture( depth_sampler, uv ).r;
}

void main() 
{
	ivec2 uv   = ivec2( gl_GlobalInvocationID.xy );
	ivec2 size = ivec2( params.raster_size );

	if ( uv.x >= size.x || uv.y >= size.y ) 
  {
		return;
	}

	vec4 color = imageLoad( color_image, uv );
  float depth = sample_depth( uv ); 

	float gray = color.r * 0.2125 + color.g * 0.7154 + color.b * 0.0721;

	color.rgb = vec3( params.amounts.x * gray, pow( params.amounts.y * depth, params.power ), 0.0 );

	imageStore( color_image, uv, color );
}