Blender V5.0
eevee_sampling.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
13#include "BLI_vector.hh"
14#include "DNA_scene_types.h"
15
18
19namespace blender::eevee {
20
21class Instance;
22
24
25class Sampling {
26 private:
27 Instance &inst_;
28
29 /* Number of samples in the first ring of jittered depth of field. */
30 static constexpr uint64_t dof_web_density_ = 6;
31 /* High number of sample for viewport infinite rendering. */
32 static constexpr uint64_t infinite_sample_count_ = 0xFFFFFFu;
33 /* During interactive rendering, loop over the first few samples. */
34 static constexpr uint64_t interactive_sample_aa_ = 8;
35 static constexpr uint64_t interactive_sample_raytrace_ = 32;
36 static constexpr uint64_t interactive_sample_volume_ = 32;
37 static constexpr uint64_t interactive_sample_max_ = interactive_sample_aa_ *
38 interactive_sample_raytrace_ *
39 interactive_sample_volume_;
40
42 uint64_t sample_ = 0;
44 uint64_t sample_count_ = 64;
46 uint64_t dof_ring_count_ = 0;
48 uint64_t dof_sample_count_ = 1;
50 uint64_t motion_blur_steps_ = 1;
52 int64_t viewport_sample_ = 0;
54 bool reset_ = false;
59 bool interactive_mode_ = false;
65 static constexpr int interactive_mode_threshold = 3;
66
67 SamplingDataBuf data_ = {"SamplingDataBuf"};
68
69 ClampData &clamp_data_;
70
71 public:
72 Sampling(Instance &inst, ClampData &clamp_data) : inst_(inst), clamp_data_(clamp_data) {};
74
75 void init(const Scene *scene);
76 void init(const Object &probe_object);
77 void end_sync();
78 void step();
79
80 /* Viewport Only: Function to call to notify something in the scene changed.
81 * This will reset accumulation. Do not call after end_sync() or during sample rendering. */
82 void reset();
83
84 /* Viewport Only: true if an update happened in the scene and accumulation needs reset. */
85 bool is_reset() const;
86
87 template<typename PassType> void bind_resources(PassType &pass)
88 {
89 pass.bind_ssbo(SAMPLING_BUF_SLOT, &data_);
90 }
91
92 /* Returns a pseudo random number in [0..1] range. Each dimension are de-correlated.
93 * WARNING: Don't use during init or sync,
94 * results are only valid during render, after step() has been called. */
95 float rng_get(eSamplingDimension dimension) const
96 {
97 return data_.dimensions[dimension];
98 }
99
100 /* Returns a pseudo random number in [0..1] range. Each dimension are de-correlated.
101 * WARNING: Don't use during init or sync,
102 * results are only valid during render, after step() has been called. */
103 float2 rng_2d_get(eSamplingDimension starting_dimension) const
104 {
105 return *reinterpret_cast<const float2 *>(&data_.dimensions[starting_dimension]);
106 }
107
108 /* Returns a pseudo random number in [0..1] range. Each dimension are de-correlated.
109 * WARNING: Don't use during init or sync,
110 * results are only valid during render, after step() has been called. */
111 float3 rng_3d_get(eSamplingDimension starting_dimension) const
112 {
113 return *reinterpret_cast<const float3 *>(&data_.dimensions[starting_dimension]);
114 }
115
116 /* Returns true if rendering has finished. */
117 bool finished() const
118 {
119 return (sample_ >= sample_count_);
120 }
121
122 /* Returns true if viewport smoothing and sampling has finished. */
123 bool finished_viewport() const
124 {
125 return (viewport_sample_ >= sample_count_) && !interactive_mode_;
126 }
127
128 /* Returns true if viewport renderer is in interactive mode and should use TAA. */
129 bool interactive_mode() const
130 {
131 return interactive_mode_;
132 }
133
134 /* Target sample count. */
136 {
137 return sample_count_;
138 }
139
140 /* 0 based current sample. Might not increase sequentially in viewport. */
142 {
143 return sample_;
144 }
145
146 bool use_clamp_direct() const
147 {
148 return clamp_data_.surface_direct != 0.0f;
149 }
150
152 {
153 return clamp_data_.surface_indirect != 0.0f;
154 }
155
156 /* Return true if we are starting a new motion blur step. We need to run sync again since
157 * depsgraph was updated by MotionBlur::step(). */
158 bool do_render_sync() const
159 {
160 return ((sample_ % (sample_count_ / motion_blur_steps_)) == 0);
161 }
162
171 static float3 sample_ball(const float3 &rand);
172
178 static float2 sample_disk(const float2 &rand);
179
185 static float3 sample_hemisphere(const float2 &rand);
186
192 static float3 sample_sphere(const float2 &rand);
193
199 static float2 sample_spiral(const float2 &rand);
200
205 void dof_disk_sample_get(float *r_radius, float *r_theta) const;
206
211 {
212 return dof_ring_count_;
213 }
214
219 {
220 return dof_sample_count_;
221 }
222
223 /* Cumulative Distribution Function Utils. */
224
229 static void cdf_from_curvemapping(const CurveMapping &curve, Vector<float> &cdf);
234 static void cdf_invert(Vector<float> &cdf, Vector<float> &inverted_cdf);
235};
236
237} // namespace blender::eevee
void init()
long long int int64_t
unsigned long long int uint64_t
A running instance of the engine.
uint64_t sample_index() const
float rng_get(eSamplingDimension dimension) const
void bind_resources(PassType &pass)
static float3 sample_sphere(const float2 &rand)
float3 rng_3d_get(eSamplingDimension starting_dimension) const
static void cdf_invert(Vector< float > &cdf, Vector< float > &inverted_cdf)
static float2 sample_disk(const float2 &rand)
float2 rng_2d_get(eSamplingDimension starting_dimension) const
uint64_t dof_ring_count_get() const
void dof_disk_sample_get(float *r_radius, float *r_theta) const
uint64_t sample_count() const
uint64_t dof_sample_count_get() const
Sampling(Instance &inst, ClampData &clamp_data)
static float2 sample_spiral(const float2 &rand)
static void cdf_from_curvemapping(const CurveMapping &curve, Vector< float > &cdf)
static float3 sample_hemisphere(const float2 &rand)
static float3 sample_ball(const float3 &rand)
#define SAMPLING_BUF_SLOT
PassType
draw::StorageBuffer< SamplingData > SamplingDataBuf
VecBase< float, 2 > float2
VecBase< float, 3 > float3