Blender V4.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#include "util/string.h"
10#include "util/types.h"
11
13
14class RenderBuffers;
15class BufferPass;
16class BufferParams;
18
19/* Helper class which allows to access pass data.
20 * Is designed in a way that it is created once when the pass data is known, and then pixels gets
21 * progressively update from various render buffers. */
23 public:
25 public:
26 PassAccessInfo() = default;
27 explicit PassAccessInfo(const BufferPass &pass);
28
31 bool include_albedo = false;
32 bool is_lightgroup = false;
33 int offset = -1;
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, int num_components);
50 Destination(const PassType pass_type, half4 *pixels);
51
52 /* Destination will be initialized with the number of components which is native for the given
53 * pass type. */
54 explicit Destination(const PassType pass_type);
55
56 /* CPU-side pointers. only usable by the `PassAccessorCPU`. */
57 float *pixels = nullptr;
59
60 /* Device-side pointers. */
63
64 /* Number of components per pixel in the floating-point destination.
65 * Is ignored for half4 destination (where number of components is implied to be 4). */
67
68 /* Offset in pixels from the beginning of pixels storage.
69 * Allows to get pixels of render buffer into a partial slice of the destination. */
70 int offset = 0;
71
72 /* Offset in floats from the beginning of pixels storage.
73 * Is ignored for half4 destination. */
74 int pixel_offset = 0;
75
76 /* Number of floats per pixel. When zero is the same as `num_components`.
77 *
78 * NOTE: Is ignored for half4 destination, as the half4 pixels are always 4-component
79 * half-floats. */
80 int pixel_stride = 0;
81
82 /* Row stride in pixel elements:
83 * - For the float destination stride is a number of floats per row.
84 * - For the half4 destination stride is a number of half4 per row. */
85 int stride = 0;
86 };
87
88 class Source {
89 public:
90 Source() = default;
91 Source(const float *pixels, int num_components);
92
93 /* CPU-side pointers. only usable by the `PassAccessorCPU`. */
94 const float *pixels = nullptr;
96
97 /* Offset in pixels from the beginning of pixels storage.
98 * Allows to get pixels of render buffer into a partial slice of the destination. */
99 int offset = 0;
100 };
101
102 PassAccessor(const PassAccessInfo &pass_access_info, float exposure, 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
bool set_render_tile_pixels(RenderBuffers *render_buffers, const Source &source)
PassAccessor(const PassAccessInfo &pass_access_info, float exposure, int num_samples)
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
#define DECLARE_PASS_ACCESSOR(pass)
Definition half.h:61
uint64_t device_ptr
Definition util/types.h:45