min_max.glsl (904B)
1 /* See LICENSE for license details. */ 2 3 /* NOTE: Does a binary search in 3D for smallest and largest output values */ 4 5 #version 460 core 6 layout(local_size_x = 32, local_size_y = 1, local_size_z = 32) in; 7 8 layout(rg32f, binding = 0) readonly uniform image3D u_out_data_tex; 9 layout(rg32f, binding = 1) writeonly uniform image3D u_mip_view_tex; 10 layout(location = 1) uniform int u_mip_map = 0; 11 12 void main() 13 { 14 ivec3 out_coord = ivec3(gl_GlobalInvocationID.xyz); 15 16 ivec3 idx = out_coord * 2; 17 vec2 min_max = vec2(1000000000, 0); 18 for (int i = 0; i < 2; i++) { 19 for (int j = 0; j < 2; j++) { 20 vec2 a = imageLoad(u_out_data_tex, idx + ivec3(i, j, 0)).xy; 21 vec2 b = imageLoad(u_out_data_tex, idx + ivec3(i, j, 1)).xy; 22 min_max.x = min(min_max.x, min(a.x, b.x)); 23 min_max.y = max(min_max.y, max(a.y, b.y)); 24 } 25 } 26 imageStore(u_mip_view_tex, out_coord, vec4(min_max, 0, 1)); 27 }