Welcome to mirror list, hosted at ThFree Co, Russian Federation.

eevee_velocity.hh « eevee « engines « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a168858d44ead24b9b9b144cb0441b452030bfd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright 2021 Blender Foundation.
 */

/** \file
 * \ingroup eevee
 *
 * The velocity pass outputs motion vectors to use for either
 * temporal re-projection or motion blur.
 *
 * It is the module that tracks the objects between frames updates.
 */

#pragma once

#include "BLI_map.hh"

#include "eevee_id_map.hh"
#include "eevee_renderpasses.hh"
#include "eevee_shader_shared.hh"

namespace blender::eevee {

/* -------------------------------------------------------------------- */
/** \name VelocityModule
 *
 * \{ */

/** Container for scene velocity data. */
class VelocityModule {
 public:
  enum eStep {
    STEP_PREVIOUS = 0,
    STEP_NEXT = 1,
    STEP_CURRENT = 2,
  };

  /** Map an object key to a velocity data. */
  Map<ObjectKey, VelocityObjectBuf *> objects_steps;
  struct {
    /** Copies of camera data. One for previous and one for next time step. */
    draw::UniformBuffer<CameraData> prev, next;
  } camera_step;

 private:
  Instance &inst_;

  eStep step_;

 public:
  VelocityModule(Instance &inst) : inst_(inst){};

  ~VelocityModule()
  {
    for (VelocityObjectBuf *data : objects_steps.values()) {
      delete data;
    }
  }

  void init(void);

  void step_camera_sync(void);
  void step_sync(eStep step, float time);

  /* Gather motion data from all objects in the scene. */
  void step_object_sync(Object *ob, ObjectKey &ob_key);

  /* Moves next frame data to previous frame data. Nullify next frame data. */
  void step_swap(void);

  void begin_sync(void);
  void end_sync(void);

 private:
  bool object_has_velocity(const Object *ob);
  bool object_is_deform(const Object *ob);
};

/** \} */

/* -------------------------------------------------------------------- */
/** \name VelocityPass
 *
 * Draws velocity data from VelocityModule module to a framebuffer / texture.
 * \{ */

class VelocityPass {
 private:
  Instance &inst_;

  DRWPass *object_ps_ = nullptr;
  DRWPass *camera_ps_ = nullptr;

  /** Shading groups from object_ps_ */
  DRWShadingGroup *mesh_grp_;

  /** Reference only. Not owned. */
  GPUTexture *input_depth_tx_;

 public:
  VelocityPass(Instance &inst) : inst_(inst){};

  void sync(void);

  void mesh_add(Object *ob, ObjectHandle &handle);

  void render_objects(void);
  void resolve_camera_motion(GPUTexture *depth_tx);
};

/** \} */

/* -------------------------------------------------------------------- */
/** \name Velocity
 *
 * \{ */

/**
 * Per view module.
 */
class Velocity {
 private:
  Instance &inst_;

  StringRefNull view_name_;

  /** Owned resources. */
  Framebuffer velocity_fb_;
  Framebuffer velocity_only_fb_;
  /** Draw resources. Not owned. */
  GPUTexture *velocity_camera_tx_ = nullptr;
  GPUTexture *velocity_view_tx_ = nullptr;

 public:
  Velocity(Instance &inst, const char *name) : inst_(inst), view_name_(name){};
  ~Velocity(){};

  void sync(int extent[2]);

  void render(GPUTexture *depth_tx);

  /**
   * Getters
   **/
  GPUTexture *view_vectors_get(void) const
  {
    return (velocity_view_tx_ != nullptr) ? velocity_view_tx_ : velocity_camera_tx_;
  }
  GPUTexture *camera_vectors_get(void) const
  {
    return velocity_camera_tx_;
  }
};

/** \} */

}  // namespace blender::eevee