Blender V4.5
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 Destination(const PassType pass_type, half4 *pixels);
49
50 /* Destination will be initialized with the number of components which is native for the given
51 * pass type. */
52 explicit Destination(const PassType pass_type);
53
54 /* CPU-side pointers. only usable by the `PassAccessorCPU`. */
55 float *pixels = nullptr;
57
58 /* Device-side pointers. */
61
62 /* Number of components per pixel in the floating-point destination.
63 * Is ignored for half4 destination (where number of components is implied to be 4). */
65
66 /* Offset in pixels from the beginning of pixels storage.
67 * Allows to get pixels of render buffer into a partial slice of the destination. */
68 int offset = 0;
69
70 /* Offset in floats from the beginning of pixels storage.
71 * Is ignored for half4 destination. */
72 int pixel_offset = 0;
73
74 /* Number of floats per pixel. When zero is the same as `num_components`.
75 *
76 * NOTE: Is ignored for half4 destination, as the half4 pixels are always 4-component
77 * half-floats. */
78 int pixel_stride = 0;
79
80 /* Row stride in pixel elements:
81 * - For the float destination stride is a number of floats per row.
82 * - For the half4 destination stride is a number of half4 per row. */
83 int stride = 0;
84 };
85
86 class Source {
87 public:
88 Source() = default;
89 Source(const float *pixels, const int num_components);
90
91 /* CPU-side pointers. only usable by the `PassAccessorCPU`. */
92 const float *pixels = nullptr;
94
95 /* Offset in pixels from the beginning of pixels storage.
96 * Allows to get pixels of render buffer into a partial slice of the destination. */
97 int offset = 0;
98 };
99
100 PassAccessor(const PassAccessInfo &pass_access_info,
101 const float exposure,
102 const int num_samples);
103
104 virtual ~PassAccessor() = default;
105
106 /* Get pass data from the given render buffers, perform needed filtering, and store result into
107 * the pixels.
108 * The result is stored sequentially starting from the very beginning of the pixels memory. */
109 bool get_render_tile_pixels(const RenderBuffers *render_buffers,
110 const Destination &destination) const;
111 bool get_render_tile_pixels(const RenderBuffers *render_buffers,
112 const BufferParams &buffer_params,
113 const Destination &destination) const;
114 /* Set pass data for the given render buffers. Used for baking to read from passes. */
115 bool set_render_tile_pixels(RenderBuffers *render_buffers, const Source &source);
116
118 {
119 return pass_access_info_;
120 }
121
122 protected:
123 virtual void init_kernel_film_convert(KernelFilmConvert *kfilm_convert,
124 const BufferParams &buffer_params,
125 const Destination &destination) const;
126
127#define DECLARE_PASS_ACCESSOR(pass) \
128 virtual void get_pass_##pass(const RenderBuffers *render_buffers, \
129 const BufferParams &buffer_params, \
130 const Destination &destination) const = 0;
131
132 /* Float (scalar) passes. */
135 DECLARE_PASS_ACCESSOR(sample_count)
137
138 /* Float3 passes. */
139 DECLARE_PASS_ACCESSOR(light_path)
140 DECLARE_PASS_ACCESSOR(shadow_catcher)
142
143 /* Float4 passes. */
145 DECLARE_PASS_ACCESSOR(cryptomatte)
146 DECLARE_PASS_ACCESSOR(shadow_catcher_matte_with_shadow)
147 DECLARE_PASS_ACCESSOR(combined)
149
150#undef DECLARE_PASS_ACCESSOR
151
153
154 float exposure_ = 0.0f;
156};
157
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
VecBase< float, 4 > float4
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