volviewer

Volumetric Data Toy Viewer
git clone anongit@rnpnr.xyz:volviewer.git
Log | Files | Refs | Feed | LICENSE

render_model.frag.glsl (1302B)


      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 bool bounding_box_test(vec3 coord, float p)
     13 {
     14 	bool result = false;
     15 	bvec3 tests = bvec3(1 - step(vec3(p), coord) * step(coord, vec3(1 - p)));
     16 	if ((tests.x && tests.y) || (tests.x && tests.z) || (tests.y && tests.z))
     17 		result = true;
     18 	return result;
     19 }
     20 
     21 void main()
     22 {
     23 	float smp = length(texture(u_texture, texture_coordinate).xy);
     24 	float threshold_val = pow(10.0f, u_threshold / 20.0f);
     25 	smp = clamp(smp, 0.0f, threshold_val);
     26 	smp = smp / threshold_val;
     27 	smp = pow(smp, u_gamma);
     28 
     29 	float t = test_texture_coordinate.y;
     30 	smp = smp * smoothstep(-0.4, 1.1, t) * u_gain;
     31 
     32 	if (u_log_scale) {
     33 		smp = 20 * log(smp) / log(10);
     34 		smp = clamp(smp, -u_db_cutoff, 0) / -u_db_cutoff;
     35 		smp = 1 - smp;
     36 	}
     37 
     38 	if (bounding_box_test(test_texture_coordinate, u_bb_fraction)) {
     39 		out_colour = u_bb_colour;
     40 	} else {
     41 		out_colour = vec4(smp, smp, smp, 1);
     42 	}
     43 
     44 	//out_colour = vec4(textureQueryLod(u_texture, texture_coordinate).y, 0, 0, 1);
     45 	//out_colour = vec4(abs(normal), 1);
     46 	//out_colour = vec4(1, 1, 1, smp);
     47 	//out_colour = vec4(smp * abs(normal), 1);
     48 }