8 #include "../proc/synthetic-stream.h"
10 #include "../proc/disparity-transform.h"
18 #include <glad/glad.h>
25 "varying vec2 textCoords;\n"
26 "uniform sampler2D textureSampler;\n"
27 "uniform sampler2D cmSampler;\n"
28 "uniform sampler2D histSampler;\n"
29 "uniform float opacity;\n"
30 "uniform float depth_units;\n"
31 "uniform float min_depth;\n"
32 "uniform float max_depth;\n"
33 "uniform float max_disparity;\n"
34 "uniform float equalize;\n"
35 "uniform float disparity;\n"
37 " vec2 tex = vec2(textCoords.x, 1.0 - textCoords.y);\n"
38 " vec4 depth = texture2D(textureSampler, tex);\n"
39 " float dx = depth.x;\n"
40 " float dy = depth.y;\n"
41 " float nd = dx + dy * 256.0;\n"
43 " if (disparity > 0.0) {;\n"
50 " if (equalize > 0.0){\n"
54 " if (disparity > 0.0) {;\n"
55 " hist = texture2D(histSampler, vec2(d / max_disparity, 0.0));\n"
58 " y = dy + (1.0 / 256.0);\n"
59 " hist = texture2D(histSampler, vec2(x, y));\n"
63 " if (disparity > 0.0) {\n"
64 " f = ((d - min_depth) / (max_depth - min_depth));\n"
66 " f = (d * depth_units - min_depth) / (max_depth - min_depth);\n"
69 " f = clamp(f, 0.0, 0.99);\n"
70 " vec4 color = texture2D(cmSampler, vec2(f, 0.0));\n"
71 " gl_FragColor = vec4(color.x / 256.0, color.y / 256.0, color.z / 256.0, opacity);\n"
73 " gl_FragColor = vec4(0.0, 0.0, 0.0, opacity);\n"
88 _depth_units_location = _shader->get_uniform_location(
"depth_units");
89 _min_depth_location = _shader->get_uniform_location(
"min_depth");
90 _max_depth_location = _shader->get_uniform_location(
"max_depth");
91 _max_disparity_location = _shader->get_uniform_location(
"max_disparity");
92 _equalize_location = _shader->get_uniform_location(
"equalize");
93 _is_disparity_location = _shader->get_uniform_location(
"disparity");
95 auto texture0_sampler_location = _shader->get_uniform_location(
"textureSampler");
96 auto texture1_sampler_location = _shader->get_uniform_location(
"cmSampler");
97 auto texture2_sampler_location = _shader->get_uniform_location(
"histSampler");
100 _shader->load_uniform(texture0_sampler_location, texture_slot());
101 _shader->load_uniform(texture1_sampler_location, color_map_slot());
102 _shader->load_uniform(texture2_sampler_location, histogram_slot());
110 void set_params(
float units,
float min,
float max,
float max_disparity,
bool equalize,
bool disparity)
112 _shader->load_uniform(_depth_units_location,
units);
113 _shader->load_uniform(_min_depth_location,
min);
114 _shader->load_uniform(_max_depth_location, max);
115 _shader->load_uniform(_max_disparity_location, max_disparity);
116 _shader->load_uniform(_equalize_location, equalize ? 1.
f : 0.
f);
117 _shader->load_uniform(_is_disparity_location, disparity ? 1.
f : 0.
f);
135 void colorizer::cleanup_gpu_resources()
145 void colorizer::create_gpu_resources()
147 _viz = std::make_shared<visualizer_2d>(std::make_shared<colorize_shader>());
148 _fbo = std::make_shared<fbo>(_width, _height);
151 auto& curr_map = _maps[_map_index]->get_cache();
152 _last_selected_cm = _map_index;
159 _enabled = glsl_enabled() ? 1 : 0;
169 auto opt = std::make_shared<librealsense::ptr_option<int>>(
170 0, 1, 0, 1, &
_enabled,
"GLSL enabled");
187 LOG_DEBUG(
"Error while performing cleaning up gpu resources" );
195 f[
i] = hist[
i] / total;
248 throw std::runtime_error(
"Frame interface is not depth frame");
258 depth_texture = input_frame.get_texture_id(0);
259 hist_texture = input_frame.get_texture_id(1);
304 gf->get_gpu_section().output_texture( 0, &output_rgb,
TEXTYPE_RGB );
316 _fbo->createTextureAttachment(output_rgb);
329 if (__min < 1
e-6
f) { __min = 1
e-6
f; }
345 _viz->draw_texture(depth_texture);