cgv
Loading...
Searching...
No Matches
volume_renderer.h
1#pragma once
2
3#include "renderer.h"
4
5#include "gl/lib_begin.h"
6
7namespace cgv { // @<
8 namespace render { // @<
9
10 class CGV_API volume_renderer;
11
13
16 extern CGV_API volume_renderer& ref_volume_renderer(context& ctx, int ref_count_change = 0);
17
18 enum class VolumeIntegrationQuality {
19 k8 = 8,
20 k16 = 16,
21 k32 = 32,
22 k64 = 64,
23 k128 = 128,
24 k256 = 256,
25 k512 = 512,
26 k1024 = 1024,
27 k2048 = 2048,
28 k4096 = 4096
29 };
30
32 kNearest = 0,
33 kSmoothed = 1,
34 kLinear = 2,
35 kCubic = 3
36 };
37
38 enum class VolumeCompositingMode {
39 kMaximumIntensityProjection = 0,
40 kAverage = 1,
41 kBlend = 2 // using transfer function
42 };
43
45 kNone = 0,
46 kIsovalue = 1,
48 };
49
50 enum class VolumeSliceMode {
51 kNone = 0,
52 kOpaque = 1,
53 kTransparent = 2
54 };
55
57 struct CGV_API volume_render_style : public render_style {
59 VolumeIntegrationQuality integration_quality = VolumeIntegrationQuality::k128;
61 bool enable_noise_offset = true;
63 VolumeInterpolationMode interpolation_mode = VolumeInterpolationMode::kLinear;
65 bool enable_depth_test = true;
66 // the opacity threshold needed to pass before the volume is considered a solid surface (needed for defining depth and supporting focus picking)
67 float picking_opacity_threshold = 0.03f;
68
70 VolumeCompositingMode compositing_mode = VolumeCompositingMode::kBlend;
71
73 float scale_adjustment_factor = 100.0f;
74
76 bool enable_lighting = false;
78 bool light_local_to_eye = true;
80 bool use_gradient_texture = false;
82 vec3 light_direction = normalize(cgv::vec3(-1.0f, 1.0f, 1.0f));
84 float ambient_strength = 0.3f;
86 float diffuse_strength = 0.8f;
88 float specular_strength = 0.4f;
90 float roughness = 0.3f;
92 float specular_color_mix = 0.0f;
93
95 bool enable_gradient_modulation = false;
97 float gradient_lambda = 0.0f;
98
100 VolumeIsosurfaceMode isosurface_mode = VolumeIsosurfaceMode::kNone;
102 float isovalue = 0.5f;
104 rgb isosurface_color = { 0.7f };
106 bool isosurface_color_from_transfer_function = false;
107
109 VolumeSliceMode slice_mode = VolumeSliceMode::kNone;
111 int slice_axis = 2;
113 float slice_coordinate = 0.5f;
115 float slice_opacity = 0.5f;
116
118 box3 clip_box = { vec3{0.0f}, vec3{1.0f} };
119 };
120
122 class CGV_API volume_renderer : public renderer
123 {
124 private:
127 protected:
129 texture* volume_texture = nullptr;
131 texture* transfer_function_texture = nullptr;
133 texture noise_texture = texture("uint8[R]", TF_LINEAR, TF_LINEAR, TW_REPEAT, TW_REPEAT);
135 texture* gradient_texture = nullptr;
137 texture* depth_texture = nullptr;
139 box3 bounding_box = { vec3{0.0f}, vec3{1.0f} };
141 bool apply_bounding_box_transformation = false;
143 vec2 noise_offset = { 0.0f };
144
146 std::string get_default_prog_name() const override { return "volume.glpr"; }
148 render_style* create_render_style() const override { return new volume_render_style(); }
150 void update_shader_program_options(shader_compile_options& options) const override;
152 void init_noise_texture(context& ctx);
153 public:
155 bool init(context& ctx) override;
157 void clear (const context& ctx) override;
159 bool set_volume_texture(texture* tex);
161 bool set_transfer_function_texture(texture* tex);
163 bool set_gradient_texture(texture* tex);
165 bool set_depth_texture(texture* tex);
167 void set_bounding_box(const box3& bbox);
169 void transform_to_bounding_box(bool flag);
171 void set_noise_offset(const vec2& offset);
173 bool enable(context& ctx) override;
175 bool validate_attributes(const context& ctx) const override;
177 bool disable(context& ctx) override;
179 void draw(context& ctx, size_t start, size_t count,
180 bool use_strips = false, bool use_adjacency = false, uint32_t strip_restart_index = -1) override;
181 };
182 }
183}
184
185#include <cgv/config/lib_end.h>
attribute array manager used to upload arrays to gpu
base class for all drawables, which is independent of the used rendering API.
Definition context.h:627
abstract base class for all renderers that handles a shader program and position / color attribute
Definition renderer.h:23
Stores preprocessor options used for conditionally compiling shader programs.
Definition shader_code.h:73
the texture class encapsulates all functionality independent of the rendering api.
Definition texture.h:15
renderer that supports point splatting
render_style * create_render_style() const override
create and return the default render style
std::string get_default_prog_name() const override
return the default shader program name
@ kAlphaThreshold
based on volume value (volume >= isovalue)
@ kCubic
default built-in trilinear interpolation
@ kSmoothed
only the closest voxel is sampled
@ kLinear
modification of the built-in trilinear interpolation to prevent triangular artifacts (results look bl...
volume_renderer & ref_volume_renderer(context &ctx, int ref_count_change)
reference to a singleton volume renderer that is shared among drawables
@ kTransparent
opaque slice; volume integration will stop when hit
the cgv namespace
Definition print.h:11
base class for all render styles
Definition renderer.h:16