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

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

/** \file
 * \ingroup eevee
 *
 * The light module manages light data buffers and light culling system.
 */

#pragma once

#include "BLI_bitmap.h"
#include "BLI_vector.hh"
#include "DNA_light_types.h"

#include "eevee_camera.hh"
#include "eevee_id_map.hh"
#include "eevee_sampling.hh"
#include "eevee_shader.hh"
#include "eevee_shader_shared.hh"
#include "eevee_shadow.hh"
#include "eevee_wrapper.hh"

namespace blender::eevee {

class Instance;

/* -------------------------------------------------------------------- */
/** \name Light Object
 * \{ */

struct Light : public LightData {
 public:
  bool initialized = false;
  bool used = false;

 public:
  Light()
  {
    shadow_id = LIGHT_NO_SHADOW;
  }

  void sync(ShadowModule &shadows, const Object *ob, float threshold);

  void shadow_discard_safe(ShadowModule &shadows);

  void debug_draw(void);

 private:
  float attenuation_radius_get(const ::Light *la, float light_threshold, float light_power);
  void shape_parameters_set(const ::Light *la, const float scale[3]);
  float shape_power_get(const ::Light *la);
  float point_power_get(const ::Light *la);
};

/** \} */

/* -------------------------------------------------------------------- */
/** \name LightModule
 * \{ */

/**
 * The light module manages light data buffers and light culling system.
 */
class LightModule {
  friend ShadowModule;

 public:
  /** Scene lights data. */
  LightDataBuf lights_data;
  /** Shadow data. TODO(fclem): merge with lights_data. */
  ShadowDataBuf shadows_data;
  /** Culling infos. */
  CullingDataBuf culling_data;
  /** Key buffer containing only visible lights indices. */
  CullingKeyBuf culling_key_buf;
  /** LightData buffer used for rendering. Ordered by the culling phase. */
  CullingLightBuf culling_light_buf;
  /** Zbins containing min and max light index for each Z bin. */
  CullingZbinBuf culling_zbin_buf;
  /** Bitmap of lights touching each tiles. Using one layer for each culling batch. */
  CullingTileBuf culling_tile_buf;

 private:
  Instance &inst_;

  /** Map of light objects. This is used to track light deletion. */
  Map<ObjectKey, Light> lights_;

  Vector<Light *> light_refs_;

  /** Follows the principles of Tiled Culling + Z binning from:
   * "Improved Culling for Tiled and Clustered Rendering"
   * by Michal Drobot
   * http://advances.realtimerendering.com/s2017/2017_Sig_Improved_Culling_final.pdf */
  DRWPass *culling_ps_ = nullptr;
  int3 culling_tile_dispatch_size_ = int3(1);
  /* Number of batches of lights that are separately processed. */
  int batch_len_ = 1;

  float light_threshold_;
  bool use_scene_lights_ = false;

  /** Debug Culling visualization. */
  DRWPass *debug_draw_ps_ = nullptr;
  GPUTexture *input_depth_tx_ = nullptr;

 public:
  LightModule(Instance &inst) : inst_(inst){};
  ~LightModule(){};

  void begin_sync(void);
  void sync_light(const Object *ob, ObjectHandle &handle);
  void end_sync(void);

  void set_view(const DRWView *view,
                const int2 extent,
                bool no_scene_lights,
                bool enable_specular = true);

  void shgroup_resources(DRWShadingGroup *grp);

  void debug_end_sync(void);
  void debug_draw(GPUFrameBuffer *view_fb, HiZBuffer &hiz);
};

/** \} */

}  // namespace blender::eevee