Blender V5.0
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 /* For the shadow catcher matte pass: whether to approximate shadow catcher pass into its
34 * matte pass, so that both artificial objects and shadows can be alpha-overed onto a backdrop.
35 */
37
38 /* When approximate shadow catcher matte is used alpha-over the result on top of background. */
40
41 bool show_active_pixels = false;
42 };
43
45 public:
46 Destination() = default;
47 Destination(float *pixels, const int num_components);
48
49 /* Destination will be initialized with the number of components which is native for the given
50 * pass type. */
51 explicit Destination(const PassType pass_type, const PassMode pass_mode);
52
53 /* CPU-side pointers. only usable by the `PassAccessorCPU`. */
54 float *pixels = nullptr;
56
57 /* Device-side pointers. */
60
61 /* Number of components per pixel in the floating-point destination.
62 * Is ignored for half4 destination (where number of components is implied to be 4). */
64
65 /* Offset in pixels from the beginning of pixels storage.
66 * Allows to get pixels of render buffer into a partial slice of the destination. */
67 int offset = 0;
68
69 /* Offset in floats from the beginning of pixels storage.
70 * Is ignored for half4 destination. */
71 int pixel_offset = 0;
72
73 /* Number of floats per pixel. When zero is the same as `num_components`.
74 *
75 * NOTE: Is ignored for half4 destination, as the half4 pixels are always 4-component
76 * half-floats. */
77 int pixel_stride = 0;
78
79 /* Row stride in pixel elements:
80 * - For the float destination stride is a number of floats per row.
81 * - For the half4 destination stride is a number of half4 per row. */
82 int stride = 0;
83 };
84
85 class Source {
86 public:
87 Source() = default;
88 Source(const float *pixels, const int num_components);
89
90 /* CPU-side pointers. only usable by the `PassAccessorCPU`. */
91 const float *pixels = nullptr;
93
94 /* Offset in pixels from the beginning of pixels storage.
95 * Allows to get pixels of render buffer into a partial slice of the destination. */
96 int offset = 0;
97 };
98
99 PassAccessor(const PassAccessInfo &pass_access_info,
100 const float exposure,
101 const int num_samples);
102
103 virtual ~PassAccessor() = default;
104
105 /* Get pass data from the given render buffers, perform needed filtering, and store result into
106 * the pixels.
107 * The result is stored sequentially starting from the very beginning of the pixels memory. */
108 bool get_render_tile_pixels(const RenderBuffers *render_buffers,
109 const Destination &destination) const;
110 bool get_render_tile_pixels(const RenderBuffers *render_buffers,
111 const BufferParams &buffer_params,
112 const Destination &destination) const;
113 /* Set pass data for the given render buffers. Used for baking to read from passes. */
114 bool set_render_tile_pixels(RenderBuffers *render_buffers, const Source &source);
115
117 {
118 return pass_access_info_;
119 }
120
121 protected:
122 virtual void init_kernel_film_convert(KernelFilmConvert *kfilm_convert,
123 const BufferParams &buffer_params,
124 const Destination &destination) const;
125
126#define DECLARE_PASS_ACCESSOR(pass) \
127 virtual void get_pass_##pass(const RenderBuffers *render_buffers, \
128 const BufferParams &buffer_params, \
129 const Destination &destination) const = 0;
130
131 /* Float (scalar) passes. */
134 DECLARE_PASS_ACCESSOR(volume_majorant)
135 DECLARE_PASS_ACCESSOR(sample_count)
137
138 /* Float3 passes. */
139 DECLARE_PASS_ACCESSOR(light_path)
140 DECLARE_PASS_ACCESSOR(shadow_catcher)
143
144 /* Float4 passes. */
146 DECLARE_PASS_ACCESSOR(cryptomatte)
147 DECLARE_PASS_ACCESSOR(shadow_catcher_matte_with_shadow)
148 DECLARE_PASS_ACCESSOR(combined)
150
151#undef DECLARE_PASS_ACCESSOR
152
154
155 float exposure_ = 0.0f;
157};
158
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:60
uint64_t device_ptr
Definition types_base.h:44