Blender V5.3
pass_accessor.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "scene/pass.h"
8#include "util/half.h"
9
11
12class RenderBuffers;
13class BufferPass;
14class BufferParams;
16
17/* Helper class which allows to access pass data.
18 * Is designed in a way that it is created once when the pass data is known, and then pixels gets
19 * progressively update from various render buffers. */
21 public:
23 public:
24 PassAccessInfo() = default;
25 explicit PassAccessInfo(const BufferPass &pass);
26
29 bool include_albedo = false;
30 bool is_lightgroup = false;
31 int offset = -1;
32
33 bool use_sample_count = true;
34
35 /* For the shadow catcher matte pass: whether to approximate shadow catcher pass into its
36 * matte pass, so that both artificial objects and shadows can be alpha-overed onto a backdrop.
37 */
39
40 /* When approximate shadow catcher matte is used alpha-over the result on top of background. */
42
43 bool show_active_pixels = false;
44 };
45
47 public:
48 Destination() = default;
49 Destination(float *pixels, const int num_components);
50
51 /* Destination will be initialized with the number of components which is native for the given
52 * pass type. */
53 explicit Destination(const PassType pass_type, const PassMode pass_mode);
54
55 /* CPU-side pointers. only usable by the `PassAccessorCPU`. */
56 float *pixels = nullptr;
58
59 /* Device-side pointers. */
62
63 /* Number of components per pixel in the floating-point destination.
64 * Is ignored for half4 destination (where number of components is implied to be 4). */
66
67 /* Offset in pixels from the beginning of pixels storage.
68 * Allows to get pixels of render buffer into a partial slice of the destination. */
69 int offset = 0;
70
71 /* Offset in floats from the beginning of pixels storage.
72 * Is ignored for half4 destination. */
73 int pixel_offset = 0;
74
75 /* Number of floats per pixel. When zero is the same as `num_components`.
76 *
77 * NOTE: Is ignored for half4 destination, as the half4 pixels are always 4-component
78 * half-floats. */
79 int pixel_stride = 0;
80
81 /* Row stride in pixel elements:
82 * - For the float destination stride is a number of floats per row.
83 * - For the half4 destination stride is a number of half4 per row. */
84 int stride = 0;
85 };
86
87 class Source {
88 public:
89 Source() = default;
90 Source(const float *pixels, const int num_components);
91
92 /* CPU-side pointers. only usable by the `PassAccessorCPU`. */
93 const float *pixels = nullptr;
95
96 /* Offset in pixels from the beginning of pixels storage.
97 * Allows to get pixels of render buffer into a partial slice of the destination. */
98 int offset = 0;
99 };
100
101 PassAccessor(const PassAccessInfo &pass_access_info,
102 const float exposure,
103 const int num_samples);
104
105 virtual ~PassAccessor() = default;
106
107 /* Get pass data from the given render buffers, perform needed filtering, and store result into
108 * the pixels.
109 * The result is stored sequentially starting from the very beginning of the pixels memory. */
110 bool get_render_tile_pixels(const RenderBuffers *render_buffers,
111 const Destination &destination) const;
112 bool get_render_tile_pixels(const RenderBuffers *render_buffers,
113 const BufferParams &buffer_params,
114 const Destination &destination) const;
115 /* Set pass data for the given render buffers. Used for baking to read from passes. */
116 bool set_render_tile_pixels(RenderBuffers *render_buffers, const Source &source);
117
119 {
120 return pass_access_info_;
121 }
122
123 protected:
124 virtual void init_kernel_film_convert(KernelFilmConvert *kfilm_convert,
125 const BufferParams &buffer_params,
126 const Destination &destination) const;
127
128#define DECLARE_PASS_ACCESSOR(pass) \
129 virtual void get_pass_##pass(const RenderBuffers *render_buffers, \
130 const BufferParams &buffer_params, \
131 const Destination &destination) const = 0;
132
133 /* Float (scalar) passes. */
136 DECLARE_PASS_ACCESSOR(volume_majorant)
137 DECLARE_PASS_ACCESSOR(sample_count)
139
140 /* Float3 passes. */
141 DECLARE_PASS_ACCESSOR(light_path)
142 DECLARE_PASS_ACCESSOR(shadow_catcher)
145
146 /* Float4 passes. */
148 DECLARE_PASS_ACCESSOR(cryptomatte)
149 DECLARE_PASS_ACCESSOR(shadow_catcher_matte_with_shadow)
150 DECLARE_PASS_ACCESSOR(combined)
152
153#undef DECLARE_PASS_ACCESSOR
154
156
157 float exposure_ = 0.0f;
159};
160
const float * pixels
PassAccessor(const PassAccessInfo &pass_access_info, const float exposure, const int num_samples)
bool set_render_tile_pixels(RenderBuffers *render_buffers, const Source &source)
bool get_render_tile_pixels(const RenderBuffers *render_buffers, const Destination &destination) const
virtual ~PassAccessor()=default
const PassAccessInfo & get_pass_access_info() const
virtual void init_kernel_film_convert(KernelFilmConvert *kfilm_convert, const BufferParams &buffer_params, const Destination &destination) const
PassAccessInfo pass_access_info_
#define CCL_NAMESPACE_END
PassType
@ PASS_NONE
PassMode
Definition pass.h:20
@ NOISY
Definition pass.h:21
#define DECLARE_PASS_ACCESSOR(pass)
Definition half.h:53
uint64_t device_ptr
Definition types_base.h:44