render.glsl (1351B)
1 /* See LICENSE for license details. */ 2 #version 430 core 3 4 in vec2 fragTexCoord; 5 out vec4 v_out_colour; 6 7 layout(binding = 0) uniform sampler3D u_out_data_tex; 8 layout(location = 1) uniform float u_db_cutoff = -60; 9 layout(location = 2) uniform float u_threshold = 40; 10 11 /* input: h [0,360] | s,v [0, 1] * 12 * output: rgb [0,1] */ 13 vec3 hsv2rgb(vec3 hsv) 14 { 15 vec3 k = mod(vec3(5, 3, 1) + hsv.x / 60, 6); 16 k = max(min(min(k, 4 - k), 1), 0); 17 return hsv.z - hsv.z * hsv.y * k; 18 } 19 20 void main() 21 { 22 ivec3 out_data_dim = textureSize(u_out_data_tex, 0); 23 24 /* TODO: select between x and y with potentially a slice if viewing rendered volumes */ 25 ivec2 coord = ivec2(fragTexCoord * vec2(out_data_dim.xz)); 26 vec2 min_max = texelFetch(u_out_data_tex, ivec3(0), textureQueryLevels(u_out_data_tex) - 1).xy; 27 28 ivec3 smp_coord = ivec3(coord.x, 0, coord.y); 29 float smp = length(texelFetch(u_out_data_tex, smp_coord, 0).xy); 30 31 //float absmax = max(abs(min_max.y), abs(min_max.x)); 32 //smp = 20 * log(smp / absmax) / log(10); 33 34 float threshold_val = pow(10.0f, u_threshold / 10.0f); 35 smp = clamp(smp, 0.0f, threshold_val); 36 smp = 20 * log(smp / threshold_val) / log(10); 37 38 smp = clamp(smp, u_db_cutoff, 0) / u_db_cutoff; 39 smp = 1 - smp; 40 41 //v_out_colour = vec4(hsv2rgb(vec3(360 * smp, 0.8, 0.95)), 1); 42 v_out_colour = vec4(smp, smp, smp, 1); 43 }