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