render_3d.frag.glsl (1542B)
1 /* See LICENSE for license details. */ 2 3 /* input: h [0,360] | s,v [0, 1] * 4 * output: rgb [0,1] */ 5 vec3 hsv2rgb(vec3 hsv) 6 { 7 vec3 k = mod(vec3(5, 3, 1) + hsv.x / 60, 6); 8 k = max(min(min(k, 4 - k), 1), 0); 9 return hsv.z - hsv.z * hsv.y * k; 10 } 11 12 /* NOTE(rnp): adapted from: https://iquilezles.org/articles/distfunctions */ 13 float sdf_wire_box_outside(vec3 p, vec3 b, float e) 14 { 15 p = abs(p) - b; 16 vec3 q = abs(p + e) - e; 17 float result = min(min(length(max(vec3(p.x, q.y, q.z), 0.0)), 18 length(max(vec3(q.x, p.y, q.z), 0.0))), 19 length(max(vec3(q.x, q.y, p.z), 0.0))); 20 return result; 21 } 22 23 void main() 24 { 25 float smp = length(texture(u_texture, texture_coordinate).xy); 26 float threshold_val = pow(10.0f, u_threshold / 20.0f); 27 smp = clamp(smp, 0.0f, threshold_val); 28 smp = smp / threshold_val; 29 smp = pow(smp, u_gamma); 30 31 //float t = test_texture_coordinate.y; 32 //smp = smp * smoothstep(-0.4, 1.1, t) * u_gain; 33 34 if (u_log_scale) { 35 smp = 20 * log(smp) / log(10); 36 smp = clamp(smp, -u_db_cutoff, 0) / -u_db_cutoff; 37 smp = 1 - smp; 38 } 39 40 vec3 p = 2.0f * test_texture_coordinate - 1.0f; 41 float t = clamp(sdf_wire_box_outside(p, vec3(1.0f), u_bb_fraction) / u_bb_fraction, 0, 1); 42 43 out_colour = vec4(t * vec3(smp) + (1 - t) * u_bb_colour.xyz, 1); 44 if (u_solid_bb) out_colour = u_bb_colour; 45 46 //out_colour = vec4(textureQueryLod(u_texture, texture_coordinate).y, 0, 0, 1); 47 //out_colour = vec4(abs(normal), 1); 48 //out_colour = vec4(1, 1, 1, smp); 49 //out_colour = vec4(smp * abs(normal), 1); 50 }