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

eevee_cryptomatte.hh « eevee_next « engines « draw « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 37f5edf4c6db1affc77b2af46c0c23e4626f5205 (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
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright 2021 Blender Foundation.
 */

/** \file
 * \ingroup eevee
 *
 * Cryptomatte.
 *
 * During rasterization, cryptomatte hashes are stored into a single array texture.
 * The film pass then resamples this texture using pixel filter weighting.
 * Each cryptomatte layer can hold N samples. These are stored in sequential layers
 * of the array texture. The samples are sorted and merged only for final rendering.
 */

#pragma once

#include "eevee_shader_shared.hh"

#include "BKE_cryptomatte.hh"

extern "C" {
struct Material;
struct CryptomatteSession;
}

namespace blender::eevee {

class Instance;

/* -------------------------------------------------------------------- */
/** \name Cryptomatte
 * \{ */

class Cryptomatte {
 private:
  class Instance &inst_;

  bke::cryptomatte::CryptomatteSessionPtr session_;

  /* Cached pointer to the cryptomatte layer instances. */
  bke::cryptomatte::CryptomatteLayer *object_layer_ = nullptr;
  bke::cryptomatte::CryptomatteLayer *asset_layer_ = nullptr;
  bke::cryptomatte::CryptomatteLayer *material_layer_ = nullptr;

  /** Contains per object hashes (object and asset hash). Indexed by resource ID. */
  CryptomatteObjectBuf cryptomatte_object_buf;

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

  void begin_sync();
  void sync_object(Object *ob, ResourceHandle res_handle);
  void sync_material(const ::Material *material);
  void end_sync();

  template<typename T> void bind_resources(draw::detail::PassBase<T> *pass)
  {
    pass->bind_ssbo(CRYPTOMATTE_BUF_SLOT, &cryptomatte_object_buf);
  }

  /* Register ID to use inside cryptomatte layer and returns associated hash as float. */
  float register_id(const eViewLayerEEVEEPassType layer, const ID &id) const;
  void store_metadata(RenderResult *render_result);
};

/** \} */

}  // namespace blender::eevee