Blender  V3.3
eevee_sampling.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2021 Blender Foundation.
3  */
4 
11 #pragma once
12 
13 #include "BKE_colortools.h"
14 #include "BLI_system.h"
15 #include "BLI_vector.hh"
16 #include "DNA_scene_types.h"
17 #include "DRW_render.h"
18 
19 #include "eevee_shader_shared.hh"
20 
21 namespace blender::eevee {
22 
23 class Instance;
24 
25 class Sampling {
26  private:
27  Instance &inst_;
28 
29  /* Number of samples in the first ring of jittered depth of field. */
30  constexpr static uint64_t dof_web_density_ = 6;
31  /* High number of sample for viewport infinite rendering. */
32  constexpr static uint64_t infinite_sample_count_ = 0xFFFFFFu;
33  /* During interactive rendering, loop over the first few samples. */
34  constexpr static uint64_t interactive_sample_max_ = 8;
35 
37  uint64_t sample_ = 0;
39  uint64_t sample_count_ = 64;
41  uint64_t dof_ring_count_ = 0;
43  uint64_t dof_sample_count_ = 1;
45  uint64_t motion_blur_steps_ = 1;
47  int64_t viewport_sample_ = 0;
49  bool reset_ = false;
54  bool interactive_mode_ = false;
60  static constexpr int interactive_mode_threshold = 3;
61 
62  SamplingDataBuf data_;
63 
64  public:
65  Sampling(Instance &inst) : inst_(inst){};
66  ~Sampling(){};
67 
68  void init(const Scene *scene);
69  void end_sync();
70  void step();
71 
72  /* Viewport Only: Function to call to notify something in the scene changed.
73  * This will reset accumulation. Do not call after end_sync() or during sample rendering. */
74  void reset()
75  {
76  reset_ = true;
77  }
78 
79  /* Viewport Only: true if an update happened in the scene and accumulation needs reset. */
80  bool is_reset() const
81  {
82  return reset_;
83  }
84 
86  {
87  DRW_shgroup_storage_block_ref(grp, "sampling_buf", &data_);
88  }
89 
90  /* Returns a pseudo random number in [0..1] range. Each dimension are de-correlated. */
91  float rng_get(eSamplingDimension dimension) const
92  {
93  return data_.dimensions[dimension];
94  }
95 
96  /* Returns a pseudo random number in [0..1] range. Each dimension are de-correlated. */
97  float2 rng_2d_get(eSamplingDimension starting_dimension) const
98  {
99  return *reinterpret_cast<const float2 *>(&data_.dimensions[starting_dimension]);
100  }
101 
102  /* Returns a pseudo random number in [0..1] range. Each dimension are de-correlated. */
103  float3 rng_3d_get(eSamplingDimension starting_dimension) const
104  {
105  return *reinterpret_cast<const float3 *>(&data_.dimensions[starting_dimension]);
106  }
107 
108  /* Returns true if rendering has finished. */
109  bool finished() const
110  {
111  return (sample_ >= sample_count_);
112  }
113 
114  /* Returns true if viewport smoothing and sampling has finished. */
115  bool finished_viewport() const
116  {
117  return (viewport_sample_ >= sample_count_) && !interactive_mode_;
118  }
119 
120  /* Returns true if viewport renderer is in interactive mode and should use TAA. */
121  bool interactive_mode() const
122  {
123  return interactive_mode_;
124  }
125 
127  {
128  return sample_count_;
129  }
130 
131  /* Return true if we are starting a new motion blur step. We need to run sync again since
132  * depsgraph was updated by MotionBlur::step(). */
133  bool do_render_sync() const
134  {
135  return ((sample_ % (sample_count_ / motion_blur_steps_)) == 0);
136  }
137 
146  static float3 sample_ball(const float3 &rand);
147 
153  static float2 sample_disk(const float2 &rand);
154 
160  static float2 sample_spiral(const float2 &rand);
161 
166  void dof_disk_sample_get(float *r_radius, float *r_theta) const;
167 
172  {
173  return dof_ring_count_;
174  }
175 
180  {
181  return dof_sample_count_;
182  }
183 
184  /* Cumulative Distribution Function Utils. */
185  static void cdf_from_curvemapping(const CurveMapping &curve, Vector<float> &cdf);
187 };
188 
189 } // namespace blender::eevee
#define DRW_shgroup_storage_block_ref(shgroup, name, ssbo)
Definition: DRW_render.h:657
A running instance of the engine.
Sampling(Instance &inst)
void bind_resources(DRWShadingGroup *grp)
float rng_get(eSamplingDimension dimension) const
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
void init(const Scene *scene)
static float2 sample_spiral(const float2 &rand)
static void cdf_from_curvemapping(const CurveMapping &curve, Vector< float > &cdf)
static float3 sample_ball(const float3 &rand)
Scene scene
Curve curve
float inverted_cdf[FILTER_CDF_TABLE_SIZE]
T * data_
Definition: eval_output.h:163
__int64 int64_t
Definition: stdint.h:89
unsigned __int64 uint64_t
Definition: stdint.h:90