Blender  V3.3
eevee_pipeline.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2021 Blender Foundation.
3  */
4 
13 #pragma once
14 
15 #include "DRW_render.h"
16 
17 /* TODO(fclem): Move it to GPU/DRAW. */
18 #include "../eevee/eevee_lut.h"
19 
20 namespace blender::eevee {
21 
22 class Instance;
23 
24 /* -------------------------------------------------------------------- */
31  private:
32  Instance &inst_;
33 
34  DRWPass *world_ps_ = nullptr;
35 
36  public:
37  WorldPipeline(Instance &inst) : inst_(inst){};
38 
39  void sync(GPUMaterial *gpumat);
40  void render();
41 };
42 
45 /* -------------------------------------------------------------------- */
52  private:
53  Instance &inst_;
54 
55  DRWPass *prepass_ps_ = nullptr;
56  DRWPass *prepass_velocity_ps_ = nullptr;
57  DRWPass *prepass_culled_ps_ = nullptr;
58  DRWPass *prepass_culled_velocity_ps_ = nullptr;
59  DRWPass *opaque_ps_ = nullptr;
60  DRWPass *opaque_culled_ps_ = nullptr;
61  DRWPass *transparent_ps_ = nullptr;
62 
63  // GPUTexture *input_screen_radiance_tx_ = nullptr;
64 
65  public:
66  ForwardPipeline(Instance &inst) : inst_(inst){};
67 
68  void sync();
69 
71  {
73  material_transparent_add(blender_mat, gpumat) :
74  material_opaque_add(blender_mat, gpumat);
75  }
76 
77  DRWShadingGroup *prepass_add(::Material *blender_mat, GPUMaterial *gpumat, bool has_motion)
78  {
80  prepass_transparent_add(blender_mat, gpumat) :
81  prepass_opaque_add(blender_mat, gpumat, has_motion);
82  }
83 
84  DRWShadingGroup *material_opaque_add(::Material *blender_mat, GPUMaterial *gpumat);
86  GPUMaterial *gpumat,
87  bool has_motion);
90 
91  void render(const DRWView *view,
92  Framebuffer &prepass_fb,
93  Framebuffer &combined_fb,
94  GPUTexture *depth_tx,
95  GPUTexture *combined_tx);
96 };
97 
100 /* -------------------------------------------------------------------- */
106 class UtilityTexture : public Texture {
107  struct Layer {
108  float data[UTIL_TEX_SIZE * UTIL_TEX_SIZE][4];
109  };
110 
111  static constexpr int lut_size = UTIL_TEX_SIZE;
112  static constexpr int lut_size_sqr = lut_size * lut_size;
113  static constexpr int layer_count = 4 + UTIL_BTDF_LAYER_COUNT;
114 
115  public:
116  UtilityTexture() : Texture("UtilityTx", GPU_RGBA16F, int2(lut_size), layer_count, nullptr)
117  {
118 #ifdef RUNTIME_LUT_CREATION
119  float *bsdf_ggx_lut = EEVEE_lut_update_ggx_brdf(lut_size);
120  float(*btdf_ggx_lut)[lut_size_sqr * 2] = (float(*)[lut_size_sqr * 2])
122 #else
123  const float *bsdf_ggx_lut = bsdf_split_sum_ggx;
124  const float(*btdf_ggx_lut)[lut_size_sqr * 2] = btdf_split_sum_ggx;
125 #endif
126 
127  Vector<Layer> data(layer_count);
128  {
129  Layer &layer = data[UTIL_BLUE_NOISE_LAYER];
130  memcpy(layer.data, blue_noise, sizeof(layer));
131  }
132  {
133  Layer &layer = data[UTIL_LTC_MAT_LAYER];
134  memcpy(layer.data, ltc_mat_ggx, sizeof(layer));
135  }
136  {
137  Layer &layer = data[UTIL_LTC_MAG_LAYER];
138  for (auto i : IndexRange(lut_size_sqr)) {
139  layer.data[i][0] = bsdf_ggx_lut[i * 2 + 0];
140  layer.data[i][1] = bsdf_ggx_lut[i * 2 + 1];
141  layer.data[i][2] = ltc_mag_ggx[i * 2 + 0];
142  layer.data[i][3] = ltc_mag_ggx[i * 2 + 1];
143  }
145  }
146  {
147  Layer &layer = data[UTIL_DISK_INTEGRAL_LAYER];
148  for (auto i : IndexRange(lut_size_sqr)) {
149  layer.data[i][UTIL_DISK_INTEGRAL_COMP] = ltc_disk_integral[i];
150  }
151  }
152  {
153  for (auto layer_id : IndexRange(16)) {
154  Layer &layer = data[3 + layer_id];
155  for (auto i : IndexRange(lut_size_sqr)) {
156  layer.data[i][0] = btdf_ggx_lut[layer_id][i * 2 + 0];
157  layer.data[i][1] = btdf_ggx_lut[layer_id][i * 2 + 1];
158  }
159  }
160  }
161  GPU_texture_update_mipmap(*this, 0, GPU_DATA_FLOAT, data.data());
162  }
163 
165 };
166 
169 /* -------------------------------------------------------------------- */
176  public:
178  // DeferredPipeline deferred;
180  // ShadowPipeline shadow;
181  // VelocityPipeline velocity;
182 
184 
185  public:
186  PipelineModule(Instance &inst) : world(inst), forward(inst){};
187 
188  void sync()
189  {
190  // deferred.sync();
191  forward.sync();
192  // shadow.sync();
193  // velocity.sync();
194  }
195 
197  GPUMaterial *gpumat,
198  eMaterialPipeline pipeline_type)
199  {
200  switch (pipeline_type) {
202  // return deferred.prepass_add(blender_mat, gpumat, false);
203  break;
205  // return deferred.prepass_add(blender_mat, gpumat, true);
206  break;
208  return forward.prepass_add(blender_mat, gpumat, false);
210  return forward.prepass_add(blender_mat, gpumat, true);
211  case MAT_PIPE_DEFERRED:
212  // return deferred.material_add(blender_mat, gpumat);
213  break;
214  case MAT_PIPE_FORWARD:
215  return forward.material_add(blender_mat, gpumat);
216  case MAT_PIPE_VOLUME:
217  /* TODO(fclem) volume pass. */
218  return nullptr;
219  case MAT_PIPE_SHADOW:
220  // return shadow.material_add(blender_mat, gpumat);
221  break;
222  }
223  return nullptr;
224  }
225 };
226 
229 } // namespace blender::eevee
typedef float(TangentPoint)[2]
#define BLI_assert(a)
Definition: BLI_assert.h:46
static AppView * view
bool GPU_material_flag_get(const GPUMaterial *mat, eGPUMaterialFlag flag)
Definition: gpu_material.c:601
@ GPU_MATFLAG_TRANSPARENT
Definition: GPU_material.h:76
void GPU_texture_update_mipmap(GPUTexture *tex, int miplvl, eGPUDataFormat gpu_data_format, const void *pixels)
Definition: gpu_texture.cc:406
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
@ GPU_DATA_FLOAT
Definition: GPU_texture.h:171
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Texture
DRWShadingGroup * material_add(::Material *blender_mat, GPUMaterial *gpumat)
DRWShadingGroup * prepass_transparent_add(::Material *blender_mat, GPUMaterial *gpumat)
DRWShadingGroup * prepass_opaque_add(::Material *blender_mat, GPUMaterial *gpumat, bool has_motion)
DRWShadingGroup * prepass_add(::Material *blender_mat, GPUMaterial *gpumat, bool has_motion)
DRWShadingGroup * material_opaque_add(::Material *blender_mat, GPUMaterial *gpumat)
void render(const DRWView *view, Framebuffer &prepass_fb, Framebuffer &combined_fb, GPUTexture *depth_tx, GPUTexture *combined_tx)
DRWShadingGroup * material_transparent_add(::Material *blender_mat, GPUMaterial *gpumat)
A running instance of the engine.
DRWShadingGroup * material_add(::Material *blender_mat, GPUMaterial *gpumat, eMaterialPipeline pipeline_type)
void sync(GPUMaterial *gpumat)
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img GPU_RGBA16F
const float blue_noise[64 *64][4]
Definition: eevee_lut.c:3491
const float btdf_split_sum_ggx[16][64 *64 *2]
Definition: eevee_lut.c:6569
const float bsdf_split_sum_ggx[64 *64 *2]
Definition: eevee_lut.c:5542
const float ltc_mag_ggx[64 *64 *2]
Definition: eevee_lut.c:2061
const float ltc_disk_integral[64 *64]
Definition: eevee_lut.c:2975
const float ltc_mat_ggx[64 *64 *4]
Definition: eevee_lut.c:10
float * EEVEE_lut_update_ggx_brdf(int lut_size)
Definition: eevee_lut_gen.c:23
float * EEVEE_lut_update_ggx_btdf(int lut_size, int lut_depth)
Definition: eevee_lut_gen.c:60
#define UTIL_DISK_INTEGRAL_COMP
#define UTIL_BSDF_LAYER
#define UTIL_LTC_MAG_LAYER
#define UTIL_DISK_INTEGRAL_LAYER
#define UTIL_BTDF_LAYER_COUNT
#define UTIL_LTC_MAT_LAYER
#define UTIL_TEX_SIZE
#define UTIL_BLUE_NOISE_LAYER
@ MAT_PIPE_DEFERRED_PREPASS_VELOCITY
@ MAT_PIPE_FORWARD_PREPASS_VELOCITY