Blender V5.0
eevee_instance.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
13#include <fmt/format.h>
14
15#include "CLG_log.h"
16
17#include "BLI_string.h"
18
19#include "BLT_translation.hh"
20
21#include "BKE_object.hh"
22
23#include "DEG_depsgraph.hh"
24
26
27#include "DRW_render.hh"
28
30#include "eevee_camera.hh"
31#include "eevee_cryptomatte.hh"
32#include "eevee_debug_shared.hh"
34#include "eevee_film.hh"
35#include "eevee_gbuffer.hh"
36#include "eevee_hizbuffer.hh"
37#include "eevee_light.hh"
38#include "eevee_lightprobe.hh"
42#include "eevee_lookdev.hh"
43#include "eevee_material.hh"
44#include "eevee_motion_blur.hh"
45#include "eevee_pipeline.hh"
46#include "eevee_raytrace.hh"
48#include "eevee_sampling.hh"
49#include "eevee_shader.hh"
50#include "eevee_shadow.hh"
51#include "eevee_subsurface.hh"
52#include "eevee_sync.hh"
53#include "eevee_view.hh"
54#include "eevee_volume.hh"
55#include "eevee_world.hh"
56
57namespace blender::eevee {
58
60
61/* Combines data from several modules to avoid wasting binding slots. */
63 UniformDataBuf data = {"UniformDataBuf"};
64
66 {
67 data.push_update();
68 }
69
70 template<typename PassType> void bind_resources(PassType &pass)
71 {
72 pass.bind_ubo(UNIFORM_BUF_SLOT, &data);
73 }
74};
75
80class Instance : public DrawEngine {
81 friend VelocityModule;
82 friend MotionBlurModule;
83
85 static void *debug_scope_render_sample;
86 static void *debug_scope_irradiance_setup;
87 static void *debug_scope_irradiance_sample;
88
89 uint64_t depsgraph_last_update_ = 0;
90 bool overlays_enabled_ = false;
91 bool skip_render_ = false;
92
94 std::string info_ = "";
95
96 public:
107 VelocityModule velocity;
108 MotionBlurModule motion_blur;
127
129
131 Depsgraph *depsgraph;
143 const View *drw_view = nullptr;
144 const View3D *v3d;
146
147 const DRWContext *draw_ctx = nullptr;
148
150 bool is_light_bake = false;
152 bool is_image_render = false;
156 bool is_playback = false;
158 bool is_navigating = false;
160 bool is_painting = false;
162 bool is_transforming = false;
166 bool draw_overlays = false;
167
170
172 bool use_surfaces = true;
173 bool use_curves = true;
174 bool use_volumes = true;
175
178
179 public:
181 : shaders(*ShaderModule::module_get()),
182 sync(*this),
183 materials(*this),
185 pipelines(*this, uniform_data.data.pipeline),
186 shadows(*this, uniform_data.data.shadow),
187 lights(*this),
189 raytracing(*this, uniform_data.data.raytrace),
190 velocity(*this),
191 motion_blur(*this),
192 depth_of_field(*this),
193 cryptomatte(*this),
194 hiz_buffer(*this, uniform_data.data.hiz),
197 film(*this, uniform_data.data.film),
198 render_buffers(*this, uniform_data.data.render_pass),
199 main_view(*this),
200 capture_view(*this),
201 world(*this),
202 lookdev_view(*this),
203 lookdev(*this),
204 sphere_probes(*this),
205 planar_probes(*this),
206 volume_probes(*this),
207 light_probes(*this),
208 volume(*this, uniform_data.data.volumes) {};
210
212 {
213 return "EEVEE";
214 }
215
216 /* Render & Viewport. */
217 /* TODO(fclem): Split for clarity. */
218 void init(const int2 &output_res,
219 const rcti *output_rect,
220 const rcti *visible_rect,
222 Depsgraph *depsgraph,
223 Object *camera_object = nullptr,
224 const RenderLayer *render_layer = nullptr,
225 View *drw_view_ = nullptr,
226 const View3D *v3d = nullptr,
227 const RegionView3D *rv3d = nullptr);
228
229 void init() final;
230
231 void begin_sync() final;
232 void object_sync(ObjectRef &ob_ref, Manager &manager) final;
233 void end_sync() final;
234
235 bool is_loaded(ShaderGroups groups) const
236 {
237 return (loaded_shaders & groups) == groups;
238 }
239
243 bool do_lightprobe_sphere_sync() const;
244 bool do_planar_probe_sync() const;
245
251 bool needs_planar_probe_passes() const;
252
253 /* Render. */
254
255 void render_sync();
256 void render_frame(RenderEngine *engine, RenderLayer *render_layer, const char *view_name);
257 void store_metadata(RenderResult *render_result);
258
259 /* Viewport. */
260
261 void draw_viewport();
263
264 void draw(Manager &manager) final;
265
266 /* Light bake. */
267
270 Object &probe,
271 FunctionRef<void()> context_enable,
272 FunctionRef<void()> context_disable,
273 FunctionRef<bool()> stop,
274 FunctionRef<void(LightProbeGridCacheFrame *, float progress)> result_update);
275
276 static void update_passes(RenderEngine *engine, Scene *scene, ViewLayer *view_layer);
277
278 /* Append a new line to the info string. */
279 template<typename... Args> void info_append(const char *msg, Args &&...args)
280 {
281 std::string fmt_msg = fmt::format(fmt::runtime(msg), args...) + "\n";
282 /* Don't print the same error twice. */
283 if (info_ != fmt_msg && !BLI_str_endswith(info_.c_str(), fmt_msg.c_str())) {
284 info_ += fmt_msg;
285 }
286 }
287
288 /* The same as `info_append`, but `msg` will be translated.
289 * NOTE: When calling this function, `msg` should be a string literal. */
290 template<typename... Args> void info_append_i18n(const char *msg, Args &&...args)
291 {
292 std::string fmt_msg = fmt::format(fmt::runtime(RPT_(msg)), args...) + "\n";
293 /* Don't print the same error twice. */
294 if (info_ != fmt_msg && !BLI_str_endswith(info_.c_str(), fmt_msg.c_str())) {
295 info_ += fmt_msg;
296 }
297 }
298
299 const char *info_get()
300 {
301 return info_.c_str();
302 }
303
304 bool is_viewport() const
305 {
306 return render == nullptr && !is_baking();
307 }
308
309 bool is_baking() const
310 {
311 return is_light_bake;
312 }
313
314 bool overlays_enabled() const
315 {
316 return overlays_enabled_;
317 }
318
321 {
323 }
324
325 bool use_scene_lights() const
326 {
327 return (!v3d) ||
328 ((v3d->shading.type == OB_MATERIAL) &&
329 (v3d->shading.flag & V3D_SHADING_SCENE_LIGHTS)) ||
330 ((v3d->shading.type == OB_RENDER) &&
331 (v3d->shading.flag & V3D_SHADING_SCENE_LIGHTS_RENDER));
332 }
333
334 /* Light the scene using the selected HDRI in the viewport shading pop-over. */
335 bool use_studio_light() const
336 {
337 return (v3d) && (((v3d->shading.type == OB_MATERIAL) &&
338 ((v3d->shading.flag & V3D_SHADING_SCENE_WORLD) == 0)) ||
339 ((v3d->shading.type == OB_RENDER) &&
340 ((v3d->shading.flag & V3D_SHADING_SCENE_WORLD_RENDER) == 0)));
341 }
342
344 {
345 return (v3d) &&
346 ((v3d->shading.type == OB_MATERIAL) && (v3d->overlay.flag & V3D_OVERLAY_LOOK_DEV));
347 }
348
349 int get_recalc_flags(const ObjectRef &ob_ref)
350 {
351 return ob_ref.recalc_flags(depsgraph_last_update_);
352 }
353
354 int get_recalc_flags(const ::World &world)
355 {
356 return world.last_update > depsgraph_last_update_ ? int(ID_RECALC_SHADING) : 0;
357 }
358
359 private:
364 void render_sample();
365 void render_read_result(RenderLayer *render_layer, const char *view_name);
366
367 void mesh_sync(Object *ob, ObjectHandle &ob_handle);
368
369 void update_eval_members();
370
371 void set_time(float time);
372
373 struct DebugScope {
374 void *scope;
375
376 DebugScope(void *&scope_p, const char *name)
377 {
378 if (scope_p == nullptr) {
380 }
381 scope = scope_p;
383 }
384
385 ~DebugScope()
386 {
388 }
389 };
390};
391
392} // namespace blender::eevee
General operations, lookup, etc. for blender objects.
#define final(a, b, c)
Definition BLI_hash.h:19
int bool bool BLI_str_endswith(const char *__restrict str, const char *__restrict end) ATTR_NONNULL(1
#define RPT_(msgid)
bool DEG_id_type_any_exists(const Depsgraph *depsgraph, short id_type)
@ ID_RECALC_SHADING
Definition DNA_ID.h:1094
@ ID_GP
@ OB_RENDER
@ OB_MATERIAL
@ V3D_SHADING_SCENE_WORLD_RENDER
@ V3D_SHADING_SCENE_WORLD
@ V3D_SHADING_SCENE_LIGHTS
@ V3D_SHADING_SCENE_LIGHTS_RENDER
@ V3D_OVERLAY_LOOK_DEV
void GPU_debug_capture_scope_end(void *scope)
Definition gpu_debug.cc:145
bool GPU_debug_capture_scope_begin(void *scope)
Definition gpu_debug.cc:123
void * GPU_debug_capture_scope_create(const char *name)
Definition gpu_debug.cc:109
BMesh const char void * data
BPy_StructRNA * depsgraph
unsigned long long int uint64_t
int recalc_flags(uint64_t last_update) const
VolumeProbeModule volume_probes
void render_frame(RenderEngine *engine, RenderLayer *render_layer, const char *view_name)
SphereProbeModule sphere_probes
AmbientOcclusion ambient_occlusion
void info_append_i18n(const char *msg, Args &&...args)
bool gpencil_engine_enabled() const
SubsurfaceModule subsurface
int get_recalc_flags(const ::World &world)
void light_bake_irradiance(Object &probe, FunctionRef< void()> context_enable, FunctionRef< void()> context_disable, FunctionRef< bool()> stop, FunctionRef< void(LightProbeGridCacheFrame *, float progress)> result_update)
bool needs_lightprobe_sphere_passes() const
int get_recalc_flags(const ObjectRef &ob_ref)
bool needs_planar_probe_passes() const
void object_sync(ObjectRef &ob_ref, Manager &manager) final
const RenderLayer * render_layer
const DRWContext * draw_ctx
const RegionView3D * rv3d
blender::StringRefNull name_get() final
void store_metadata(RenderResult *render_result)
void info_append(const char *msg, Args &&...args)
PlanarProbeModule planar_probes
static void update_passes(RenderEngine *engine, Scene *scene, ViewLayer *view_layer)
bool is_loaded(ShaderGroups groups) const
bool do_lightprobe_sphere_sync() const
UniformDataModule uniform_data
LightProbeModule light_probes
MotionBlurModule motion_blur
void init_light_bake(Depsgraph *depsgraph, draw::Manager *manager)
#define UNIFORM_BUF_SLOT
PassType
draw::UniformBuffer< UniformData > UniformDataBuf
T clamp(const T &a, const T &min, const T &max)
VecBase< int32_t, 2 > int2
const char * name
void bind_resources(PassType &pass)