Blender V4.5
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_system.h"
14#include "BLI_vector.hh"
15#include "DNA_scene_types.h"
16#include "DRW_render.hh"
17
19
20namespace blender::eevee {
21
22class Instance;
23
24class Sampling {
25 private:
26 Instance &inst_;
27
28 /* Number of samples in the first ring of jittered depth of field. */
29 static constexpr uint64_t dof_web_density_ = 6;
30 /* High number of sample for viewport infinite rendering. */
31 static constexpr uint64_t infinite_sample_count_ = 0xFFFFFFu;
32 /* During interactive rendering, loop over the first few samples. */
33 static constexpr uint64_t interactive_sample_aa_ = 8;
34 static constexpr uint64_t interactive_sample_raytrace_ = 32;
35 static constexpr uint64_t interactive_sample_volume_ = 32;
36 static constexpr uint64_t interactive_sample_max_ = interactive_sample_aa_ *
37 interactive_sample_raytrace_ *
38 interactive_sample_volume_;
39
41 uint64_t sample_ = 0;
43 uint64_t sample_count_ = 64;
45 uint64_t dof_ring_count_ = 0;
47 uint64_t dof_sample_count_ = 1;
49 uint64_t motion_blur_steps_ = 1;
51 int64_t viewport_sample_ = 0;
53 bool reset_ = false;
58 bool interactive_mode_ = false;
64 static constexpr int interactive_mode_threshold = 3;
65
66 SamplingDataBuf data_;
67
68 ClampData &clamp_data_;
69
70 public:
71 Sampling(Instance &inst, ClampData &clamp_data) : inst_(inst), clamp_data_(clamp_data){};
73
74 void init(const Scene *scene);
75 void init(const Object &probe_object);
76 void end_sync();
77 void step();
78
79 /* Viewport Only: Function to call to notify something in the scene changed.
80 * This will reset accumulation. Do not call after end_sync() or during sample rendering. */
81 void reset();
82
83 /* Viewport Only: true if an update happened in the scene and accumulation needs reset. */
84 bool is_reset() const;
85
86 template<typename PassType> void bind_resources(PassType &pass)
87 {
88 pass.bind_ssbo(SAMPLING_BUF_SLOT, &data_);
89 }
90
91 /* Returns a pseudo random number in [0..1] range. Each dimension are de-correlated.
92 * WARNING: Don't use during init or sync,
93 * results are only valid during render, after step() has been called. */
94 float rng_get(eSamplingDimension dimension) const
95 {
96 return data_.dimensions[dimension];
97 }
98
99 /* Returns a pseudo random number in [0..1] range. Each dimension are de-correlated.
100 * WARNING: Don't use during init or sync,
101 * results are only valid during render, after step() has been called. */
102 float2 rng_2d_get(eSamplingDimension starting_dimension) const
103 {
104 return *reinterpret_cast<const float2 *>(&data_.dimensions[starting_dimension]);
105 }
106
107 /* Returns a pseudo random number in [0..1] range. Each dimension are de-correlated.
108 * WARNING: Don't use during init or sync,
109 * results are only valid during render, after step() has been called. */
110 float3 rng_3d_get(eSamplingDimension starting_dimension) const
111 {
112 return *reinterpret_cast<const float3 *>(&data_.dimensions[starting_dimension]);
113 }
114
115 /* Returns true if rendering has finished. */
116 bool finished() const
117 {
118 return (sample_ >= sample_count_);
119 }
120
121 /* Returns true if viewport smoothing and sampling has finished. */
122 bool finished_viewport() const
123 {
124 return (viewport_sample_ >= sample_count_) && !interactive_mode_;
125 }
126
127 /* Returns true if viewport renderer is in interactive mode and should use TAA. */
128 bool interactive_mode() const
129 {
130 return interactive_mode_;
131 }
132
133 /* Target sample count. */
135 {
136 return sample_count_;
137 }
138
139 /* 0 based current sample. Might not increase sequentially in viewport. */
141 {
142 return sample_;
143 }
144
145 bool use_clamp_direct() const
146 {
147 return clamp_data_.surface_direct != 0.0f;
148 }
149
151 {
152 return clamp_data_.surface_indirect != 0.0f;
153 }
154
155 /* Return true if we are starting a new motion blur step. We need to run sync again since
156 * depsgraph was updated by MotionBlur::step(). */
157 bool do_render_sync() const
158 {
159 return ((sample_ % (sample_count_ / motion_blur_steps_)) == 0);
160 }
161
170 static float3 sample_ball(const float3 &rand);
171
177 static float2 sample_disk(const float2 &rand);
178
184 static float3 sample_hemisphere(const float2 &rand);
185
191 static float3 sample_sphere(const float2 &rand);
192
198 static float2 sample_spiral(const float2 &rand);
199
204 void dof_disk_sample_get(float *r_radius, float *r_theta) const;
205
210 {
211 return dof_ring_count_;
212 }
213
218 {
219 return dof_sample_count_;
220 }
221
222 /* Cumulative Distribution Function Utils. */
223
228 static void cdf_from_curvemapping(const CurveMapping &curve, Vector<float> &cdf);
233 static void cdf_invert(Vector<float> &cdf, Vector<float> &inverted_cdf);
234};
235
236} // 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