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,
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,
48 };
49
50 enum class VolumeSliceMode {
51 kNone = 0,
52 kOpaque = 1,
54 };
55
57 struct CGV_API volume_render_style : public render_style {
59 VolumeIntegrationQuality integration_quality = VolumeIntegrationQuality::k128;
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
74
76 bool show_volume = true;
78 bool enable_lighting = false;
80 bool light_local_to_eye = true;
84 vec3 light_direction = normalize(cgv::vec3(-1.0f, 1.0f, 1.0f));
86 float ambient_strength = 0.3f;
88 float diffuse_strength = 0.8f;
90 float specular_strength = 0.4f;
92 float roughness = 0.3f;
94 float specular_color_mix = 0.0f;
95
99 float gradient_lambda = 0.0f;
100
102 VolumeIsosurfaceMode isosurface_mode = VolumeIsosurfaceMode::kNone;
104 float isovalue = 0.5f;
109
111 VolumeSliceMode slice_mode = VolumeSliceMode::kNone;
113 int slice_axis = 2;
115 float slice_coordinate = 0.5f;
117 float slice_opacity = 0.5f;
118
120 box3 clip_box = { vec3(0.0), vec3(1.0f) };
121 };
122
124 class CGV_API volume_renderer : public renderer
125 {
126 private:
129 protected:
135 texture noise_texture = texture("uint8[R]", TF_LINEAR, TF_LINEAR, TW_REPEAT, TW_REPEAT);
141 box3 bounding_box = { vec3(0.0f), vec3(1.0f) };
145 vec2 noise_offset = { 0.0f };
146
148 std::string get_default_prog_name() const override { return "volume.glpr"; }
150 render_style* create_render_style() const override { return new volume_render_style(); }
152 void update_shader_program_options(shader_compile_options& options) const override;
154 void init_noise_texture(context& ctx);
155 public:
157 bool init(context& ctx) override;
159 void clear (const context& ctx) override;
161 bool set_volume_texture(texture* tex);
163 bool set_transfer_function_texture(texture* tex);
165 bool set_gradient_texture(texture* tex);
167 bool set_depth_texture(texture* tex);
169 void set_bounding_box(const box3& bbox);
171 void transform_to_bounding_box(bool flag);
173 void set_noise_offset(const vec2& offset);
175 bool enable(context& ctx) override;
177 bool validate_attributes(const context& ctx) const override;
179 bool disable(context& ctx) override;
181 void draw(context& ctx, size_t start, size_t count,
182 bool use_strips = false, bool use_adjacency = false, uint32_t strip_restart_index = -1) override;
183 };
184 }
185}
186
187#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:670
renderer()
construct and init attribute tracking flags
Definition renderer.cxx:9
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
texture * gradient_texture
the 3D texture containing vector gradients used for lighting normal calculation
render_style * create_render_style() const override
create and return the default render style
texture * depth_texture
a 2D texture from a frame buffer depth buffer used to combine volume rendering with opaque geometry
texture * transfer_function_texture
the 2D transfer function texture used for classification of the volume values
bool apply_bounding_box_transformation
whether to translate and scale the volume to the given bounding box during rendering
vec2 noise_offset
offset applied to the noise texture (can be used in conjunction with temporal anti aliasing)
std::string get_default_prog_name() const override
return the default shader program name
texture * volume_texture
the 3D texture used for rendering
texture noise_texture
a 2D texture containing random noise used to offset ray start positions in order to reduce ring artif...
box3 bounding_box
the bounding box of the volume in scene units
namespace for api independent GPU programming
@ 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
this header is dependency free
Definition print.h:11
cgv::media::axis_aligned_box< float, 3 > box3
declare type of 3d single precision floating point axis-aligned boxes
cgv::media::color< float, cgv::media::RGB > rgb
declare rgb color type with 32 bit components
Definition color.h:896
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors
Definition fvec.h:692
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
Definition fvec.h:694
base class for all render styles
Definition renderer.h:16
bool light_local_to_eye
whether the light is local to the eye position (moves with the eye) or is static to the scene
bool enable_noise_offset
whether to use the noise texture to offset ray start positions in order to reduce sampling artifacts
bool enable_lighting
whether to enable lighting
bool show_volume
whether to show direct volume
float specular_strength
material specular component strength
float ambient_strength
light ambient component strength
VolumeIsosurfaceMode isosurface_mode
mode of a single supported isosurface
rgb isosurface_color
the default constant isosurface color
bool enable_depth_test
whether to enable depth testing by reading depth from a texture to allow geometry intersecting the vo...
float isovalue
the value used to check for an isosurface
float gradient_lambda
influence scale for gradient-based opacity modulation
VolumeSliceMode slice_mode
mode of slice rendering
bool isosurface_color_from_transfer_function
whether to color the isosurface based on the transfer function
float scale_adjustment_factor
the coefficient used to adjust sample opacity based on volume scaling (useful range between 50 and 50...
VolumeInterpolationMode interpolation_mode
the interpolation method used (supplied volume texture should be set to GL_LINEAR)
float slice_opacity
in case of transparent mode, slice opacity
VolumeIntegrationQuality integration_quality
quality measure for the number of steps used during ray marching
float specular_color_mix
material specular color mix factor (0 = color from transfer function, 1 = pure white)
vec3 light_direction
the direction of the directional light
float roughness
material roughness (inversely proportional to specular shininess)
bool use_gradient_texture
whether to use a supplied gradient texture or compute gradients on the fly via central differences (d...
VolumeCompositingMode compositing_mode
the compositing mode used
int slice_axis
coordinate axis orthogonal to which slice is rendered
float diffuse_strength
material diffuse component strength
bool enable_gradient_modulation
whether to enable modulating the volume opacity by the gradient magnitude
box3 clip_box
a bounding box used to define a subspace of the volume to be visualized
float slice_coordinate
coordinate value along axis defining slice in range [0,1]