8 #include "../proc/synthetic-stream.h"
10 #include "../proc/disparity-transform.h"
18 #include <glad/glad.h>
26 "varying vec2 textCoords;\n"
27 "uniform sampler2D textureSampler;\n"
28 "uniform sampler2D cmSampler;\n"
29 "uniform sampler2D histSampler;\n"
30 "uniform float opacity;\n"
31 "uniform float depth_units;\n"
32 "uniform float min_depth;\n"
33 "uniform float max_depth;\n"
34 "uniform float max_disparity;\n"
35 "uniform float equalize;\n"
36 "uniform float disparity;\n"
38 " vec2 tex = vec2(textCoords.x, 1.0 - textCoords.y);\n"
39 " vec4 depth = texture2D(textureSampler, tex);\n"
40 " float dx = depth.x;\n"
41 " float dy = depth.y;\n"
42 " float nd = dx + dy * 256.0;\n"
44 " if (disparity > 0.0) {;\n"
51 " if (equalize > 0.0){\n"
55 " if (disparity > 0.0) {;\n"
56 " hist = texture2D(histSampler, vec2(d / max_disparity, 0.0));\n"
59 " y = dy + (1.0 / 256.0);\n"
60 " hist = texture2D(histSampler, vec2(x, y));\n"
64 " if (disparity > 0.0) {\n"
65 " f = ((d - min_depth) / (max_depth - min_depth));\n"
67 " f = (d * depth_units - min_depth) / (max_depth - min_depth);\n"
70 " f = clamp(f, 0.0, 0.99);\n"
71 " vec4 color = texture2D(cmSampler, vec2(f, 0.0));\n"
72 " gl_FragColor = vec4(color.x / 256.0, color.y / 256.0, color.z / 256.0, opacity);\n"
74 " gl_FragColor = vec4(0.0, 0.0, 0.0, opacity);\n"
89 _depth_units_location = _shader->get_uniform_location(
"depth_units");
90 _min_depth_location = _shader->get_uniform_location(
"min_depth");
91 _max_depth_location = _shader->get_uniform_location(
"max_depth");
92 _max_disparity_location = _shader->get_uniform_location(
"max_disparity");
93 _equalize_location = _shader->get_uniform_location(
"equalize");
94 _is_disparity_location = _shader->get_uniform_location(
"disparity");
96 auto texture0_sampler_location = _shader->get_uniform_location(
"textureSampler");
97 auto texture1_sampler_location = _shader->get_uniform_location(
"cmSampler");
98 auto texture2_sampler_location = _shader->get_uniform_location(
"histSampler");
101 _shader->load_uniform(texture0_sampler_location, texture_slot());
102 _shader->load_uniform(texture1_sampler_location, color_map_slot());
103 _shader->load_uniform(texture2_sampler_location, histogram_slot());
113 _shader->load_uniform(_depth_units_location,
units);
114 _shader->load_uniform(_min_depth_location,
min);
115 _shader->load_uniform(_max_depth_location, max);
116 _shader->load_uniform(_max_disparity_location, max_disparity);
117 _shader->load_uniform(_equalize_location, equalize ? 1.
f : 0.
f);
118 _shader->load_uniform(_is_disparity_location,
disparity ? 1.
f : 0.
f);
136 void colorizer::cleanup_gpu_resources()
146 void colorizer::create_gpu_resources()
148 _viz = std::make_shared<visualizer_2d>(std::make_shared<colorize_shader>());
149 _fbo = std::make_shared<fbo>(_width, _height);
152 auto& curr_map = _maps[_map_index]->get_cache();
153 _last_selected_cm = _map_index;
160 _enabled = glsl_enabled() ? 1 : 0;
170 auto opt = std::make_shared<librealsense::ptr_option<int>>(
171 0, 1, 0, 1, &
_enabled,
"GLSL enabled");
189 f[
i] = hist[
i] / total;
251 depth_texture = input_frame.get_texture_id(0);
252 hist_texture = input_frame.get_texture_id(1);
295 gf->get_gpu_section().output_texture(0, &output_rgb,
TEXTYPE_RGB);
307 _fbo->createTextureAttachment(output_rgb);
320 if (__min < 1
e-6
f) { __min = 1
e-6
f; }
336 _viz->draw_texture(depth_texture);