Blender V4.3
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
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 reset_ = true;
84 }
85
86 /* Viewport Only: true if an update happened in the scene and accumulation needs reset. */
87 bool is_reset() const
88 {
89 return reset_;
90 }
91
92 template<typename PassType> void bind_resources(PassType &pass)
93 {
94 pass.bind_ssbo(SAMPLING_BUF_SLOT, &data_);
95 }
96
97 /* Returns a pseudo random number in [0..1] range. Each dimension are de-correlated.
98 * WARNING: Don't use during init or sync,
99 * results are only valid during render, after step() has been called. */
100 float rng_get(eSamplingDimension dimension) const
101 {
102 return data_.dimensions[dimension];
103 }
104
105 /* Returns a pseudo random number in [0..1] range. Each dimension are de-correlated.
106 * WARNING: Don't use during init or sync,
107 * results are only valid during render, after step() has been called. */
108 float2 rng_2d_get(eSamplingDimension starting_dimension) const
109 {
110 return *reinterpret_cast<const float2 *>(&data_.dimensions[starting_dimension]);
111 }
112
113 /* Returns a pseudo random number in [0..1] range. Each dimension are de-correlated.
114 * WARNING: Don't use during init or sync,
115 * results are only valid during render, after step() has been called. */
116 float3 rng_3d_get(eSamplingDimension starting_dimension) const
117 {
118 return *reinterpret_cast<const float3 *>(&data_.dimensions[starting_dimension]);
119 }
120
121 /* Returns true if rendering has finished. */
122 bool finished() const
123 {
124 return (sample_ >= sample_count_);
125 }
126
127 /* Returns true if viewport smoothing and sampling has finished. */
128 bool finished_viewport() const
129 {
130 return (viewport_sample_ >= sample_count_) && !interactive_mode_;
131 }
132
133 /* Returns true if viewport renderer is in interactive mode and should use TAA. */
134 bool interactive_mode() const
135 {
136 return interactive_mode_;
137 }
138
139 /* Target sample count. */
141 {
142 return sample_count_;
143 }
144
145 /* 0 based current sample. Might not increase sequentially in viewport. */
147 {
148 return sample_;
149 }
150
151 /* Return true if we are starting a new motion blur step. We need to run sync again since
152 * depsgraph was updated by MotionBlur::step(). */
153 bool do_render_sync() const
154 {
155 return ((sample_ % (sample_count_ / motion_blur_steps_)) == 0);
156 }
157
166 static float3 sample_ball(const float3 &rand);
167
173 static float2 sample_disk(const float2 &rand);
174
180 static float3 sample_hemisphere(const float2 &rand);
181
187 static float3 sample_sphere(const float2 &rand);
188
194 static float2 sample_spiral(const float2 &rand);
195
200 void dof_disk_sample_get(float *r_radius, float *r_theta) const;
201
206 {
207 return dof_ring_count_;
208 }
209
214 {
215 return dof_sample_count_;
216 }
217
218 /* Cumulative Distribution Function Utils. */
219
224 static void cdf_from_curvemapping(const CurveMapping &curve, Vector<float> &cdf);
229 static void cdf_invert(Vector<float> &cdf, Vector<float> &inverted_cdf);
230};
231
232} // namespace blender::eevee
void init()
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
__int64 int64_t
Definition stdint.h:89
unsigned __int64 uint64_t
Definition stdint.h:90
float dimensions[SAMPLING_DIMENSION_COUNT]