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-6f) { __min = 1
e-6
f; }
336 _viz->draw_texture(depth_texture);
void cleanup_gpu_resources() override
#define GL_TEXTURE_MAG_FILTER
rs2::frame process_frame(const rs2::frame_source &source, const rs2::frame &f) override
uint32_t _depth_units_location
rs2::stream_profile _source_stream_profile
static const int MAX_DEPTH
void add_extension(rs2_extension ex)
rs2_format format() const
uint32_t _is_disparity_location
uint32_t _min_depth_location
int histogram_slot() const
frame allocate_video_frame(const stream_profile &profile, const frame &original, int new_bpp=0, int new_width=0, int new_height=0, int new_stride=0, rs2_extension frame_type=RS2_EXTENSION_VIDEO_FRAME) const
void register_option(rs2_option id, std::shared_ptr< option > option)
std::shared_ptr< rs2::visualizer_2d > _viz
static info update_info_from_frame(const rs2::frame &f)
def info(name, value, persistent=False)
#define GL_COLOR_BUFFER_BIT
#define glBindFramebuffer
uint32_t _max_disparity_location
int color_map_slot() const
static const int MAX_DISPARITY
std::vector< color_map * > _maps
#define GL_TEXTURE_MIN_FILTER
rs2::stream_profile _target_stream_profile
std::vector< float > _fhist
const rs2_stream_profile * get() const
const void * get_data() const
#define RS2_EXTENSION_VIDEO_FRAME_GL
void perform_gl_action(T action, S fallback)
static const char * fragment_shader_text
float _d2d_convert_factor
#define GL_COLOR_ATTACHMENT0
static void update_histogram(int *hist, const T *depth_data, int w, int h)
rs2_stream stream_type() const
uint32_t _equalize_location
std::shared_ptr< rs2::fbo > _fbo
static void populate_floating_histogram(float *f, int *hist)
void set_params(float units, float min, float max, float max_disparity, bool equalize, bool disparity)
stream_profile clone(rs2_stream type, int index, rs2_format format) const
uint32_t _max_depth_location
stream_profile get_profile() const