Blender  V3.3
pass_accessor.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #pragma once
5 
6 #include "scene/pass.h"
7 #include "util/half.h"
8 #include "util/string.h"
9 #include "util/types.h"
10 
12 
13 class RenderBuffers;
14 class BufferPass;
15 class BufferParams;
16 struct KernelFilmConvert;
17 
18 /* Helper class which allows to access pass data.
19  * Is designed in a way that it is created once when the pass data is known, and then pixels gets
20  * progressively update from various render buffers. */
21 class PassAccessor {
22  public:
24  public:
25  PassAccessInfo() = default;
26  explicit PassAccessInfo(const BufferPass &pass);
27 
30  bool include_albedo = false;
31  bool is_lightgroup = false;
32  int offset = -1;
33 
34  /* For the shadow catcher matte pass: whether to approximate shadow catcher pass into its
35  * matte pass, so that both artificial objects and shadows can be alpha-overed onto a backdrop.
36  */
38 
39  /* When approximate shadow catcher matte is used alpha-over the result on top of background. */
41 
42  bool show_active_pixels = false;
43  };
44 
45  class Destination {
46  public:
47  Destination() = default;
48  Destination(float *pixels, int num_components);
49  Destination(const PassType pass_type, half4 *pixels);
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);
54 
55  /* CPU-side pointers. only usable by the `PassAccessorCPU`. */
56  float *pixels = nullptr;
57  half4 *pixels_half_rgba = 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). */
65  int num_components = 0;
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  /* Number of floats per pixel. When zero is the same as `num_components`.
72  *
73  * NOTE: Is ignored for half4 destination, as the half4 pixels are always 4-component
74  * half-floats. */
75  int pixel_stride = 0;
76 
77  /* Row stride in pixel elements:
78  * - For the float destination stride is a number of floats per row.
79  * - For the half4 destination stride is a number of half4 per row. */
80  int stride = 0;
81  };
82 
83  class Source {
84  public:
85  Source() = default;
86  Source(const float *pixels, int num_components);
87 
88  /* CPU-side pointers. only usable by the `PassAccessorCPU`. */
89  const float *pixels = nullptr;
90  int num_components = 0;
91 
92  /* Offset in pixels from the beginning of pixels storage.
93  * Allows to get pixels of render buffer into a partial slice of the destination. */
94  int offset = 0;
95  };
96 
97  PassAccessor(const PassAccessInfo &pass_access_info, float exposure, int num_samples);
98 
99  virtual ~PassAccessor() = default;
100 
101  /* Get pass data from the given render buffers, perform needed filtering, and store result into
102  * the pixels.
103  * The result is stored sequentially starting from the very beginning of the pixels memory. */
104  bool get_render_tile_pixels(const RenderBuffers *render_buffers,
105  const Destination &destination) const;
106  bool get_render_tile_pixels(const RenderBuffers *render_buffers,
107  const BufferParams &buffer_params,
108  const Destination &destination) const;
109  /* Set pass data for the given render buffers. Used for baking to read from passes. */
110  bool set_render_tile_pixels(RenderBuffers *render_buffers, const Source &source);
111 
112  protected:
113  virtual void init_kernel_film_convert(KernelFilmConvert *kfilm_convert,
114  const BufferParams &buffer_params,
115  const Destination &destination) const;
116 
117 #define DECLARE_PASS_ACCESSOR(pass) \
118  virtual void get_pass_##pass(const RenderBuffers *render_buffers, \
119  const BufferParams &buffer_params, \
120  const Destination &destination) const = 0;
121 
122  /* Float (scalar) passes. */
123  DECLARE_PASS_ACCESSOR(depth)
125  DECLARE_PASS_ACCESSOR(sample_count)
126  DECLARE_PASS_ACCESSOR(float)
127 
128  /* Float3 passes. */
129  DECLARE_PASS_ACCESSOR(light_path)
130  DECLARE_PASS_ACCESSOR(shadow_catcher)
132 
133  /* Float4 passes. */
134  DECLARE_PASS_ACCESSOR(motion)
135  DECLARE_PASS_ACCESSOR(cryptomatte)
136  DECLARE_PASS_ACCESSOR(shadow_catcher_matte_with_shadow)
137  DECLARE_PASS_ACCESSOR(combined)
139 
140 #undef DECLARE_PASS_ACCESSOR
141 
143 
144  float exposure_ = 0.0f;
145  int num_samples_ = 0;
146 };
147 
float float4[4]
const float * pixels
Definition: pass_accessor.h:89
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
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
Definition: cuda/compat.h:9
ccl_gpu_kernel_postfix ccl_global float int int int int ccl_global const float int int int int int int int int int int int int num_samples
PassType
Definition: kernel/types.h:334
@ PASS_NONE
Definition: kernel/types.h:335
PassMode
Definition: pass.h:19
#define DECLARE_PASS_ACCESSOR(pass)
Definition: half.h:64
uint64_t device_ptr
Definition: util/types.h:43