Blender V4.5
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 "BLI_string.h"
16
17#include "BLT_translation.hh"
18
19#include "BKE_object.hh"
20
21#include "DEG_depsgraph.hh"
22
24
25#include "DRW_render.hh"
26
28#include "eevee_camera.hh"
29#include "eevee_cryptomatte.hh"
31#include "eevee_film.hh"
32#include "eevee_gbuffer.hh"
33#include "eevee_hizbuffer.hh"
34#include "eevee_light.hh"
35#include "eevee_lightprobe.hh"
39#include "eevee_lookdev.hh"
40#include "eevee_material.hh"
41#include "eevee_motion_blur.hh"
42#include "eevee_pipeline.hh"
43#include "eevee_raytrace.hh"
45#include "eevee_sampling.hh"
46#include "eevee_shader.hh"
47#include "eevee_shadow.hh"
48#include "eevee_subsurface.hh"
49#include "eevee_sync.hh"
50#include "eevee_view.hh"
51#include "eevee_volume.hh"
52#include "eevee_world.hh"
53
54namespace blender::eevee {
55
56/* Combines data from several modules to avoid wasting binding slots. */
59
61 {
62 data.push_update();
63 }
64
65 template<typename PassType> void bind_resources(PassType &pass)
66 {
67 pass.bind_ubo(UNIFORM_BUF_SLOT, &data);
68 }
69};
70
75class Instance : public DrawEngine {
76 friend VelocityModule;
77 friend MotionBlurModule;
78
80 static void *debug_scope_render_sample;
81 static void *debug_scope_irradiance_setup;
82 static void *debug_scope_irradiance_sample;
83
84 uint64_t depsgraph_last_update_ = 0;
85 bool overlays_enabled_ = false;
86 bool skip_render_ = false;
87
89 std::string info_ = "";
90
91 public:
102 VelocityModule velocity;
103 MotionBlurModule motion_blur;
122
124 Depsgraph *depsgraph;
136 const View *drw_view = nullptr;
137 const View3D *v3d;
139
140 const DRWContext *draw_ctx = nullptr;
141
143 bool is_light_bake = false;
145 bool is_image_render = false;
149 bool is_playback = false;
151 bool is_navigating = false;
153 bool is_painting = false;
155 bool is_transforming = false;
159 bool draw_overlays = false;
160
163
165 bool use_surfaces = true;
166 bool use_curves = true;
167 bool use_volumes = true;
168
171
172 public:
203
205 {
206 return "EEVEE";
207 }
208
209 /* Render & Viewport. */
210 /* TODO(fclem): Split for clarity. */
211 void init(const int2 &output_res,
212 const rcti *output_rect,
213 const rcti *visible_rect,
215 Depsgraph *depsgraph,
216 Object *camera_object = nullptr,
217 const RenderLayer *render_layer = nullptr,
218 View *drw_view_ = nullptr,
219 const View3D *v3d = nullptr,
220 const RegionView3D *rv3d = nullptr);
221
222 void init() final;
223
224 void begin_sync() final;
225 void object_sync(ObjectRef &ob_ref, Manager &manager) final;
226 void end_sync() final;
227
228 bool is_loaded(ShaderGroups groups) const
229 {
230 return (loaded_shaders & groups) == groups;
231 }
232
236 bool do_lightprobe_sphere_sync() const;
237 bool do_planar_probe_sync() const;
238
244 bool needs_planar_probe_passes() const;
245
246 /* Render. */
247
248 void render_sync();
249 void render_frame(RenderEngine *engine, RenderLayer *render_layer, const char *view_name);
250 void store_metadata(RenderResult *render_result);
251
252 /* Viewport. */
253
254 void draw_viewport();
256
257 void draw(Manager &manager) final;
258
259 /* Light bake. */
260
263 Object &probe,
264 FunctionRef<void()> context_enable,
265 FunctionRef<void()> context_disable,
266 FunctionRef<bool()> stop,
267 FunctionRef<void(LightProbeGridCacheFrame *, float progress)> result_update);
268
269 static void update_passes(RenderEngine *engine, Scene *scene, ViewLayer *view_layer);
270
271 /* Append a new line to the info string. */
272 template<typename... Args> void info_append(const char *msg, Args &&...args)
273 {
274 info_ += fmt::format(fmt::runtime(msg), args...);
275 info_ += "\n";
276 }
277
278 /* The same as `info_append`, but `msg` will be translated.
279 * NOTE: When calling this function, `msg` should be a string literal. */
280 template<typename... Args> void info_append_i18n(const char *msg, Args &&...args)
281 {
282 std::string fmt_msg = fmt::format(fmt::runtime(RPT_(msg)), args...) + "\n";
283 /* Don't print the same error twice. */
284 if (info_ != fmt_msg && !BLI_str_endswith(info_.c_str(), fmt_msg.c_str())) {
285 info_ += fmt_msg;
286 }
287 }
288
289 const char *info_get()
290 {
291 return info_.c_str();
292 }
293
294 bool is_viewport() const
295 {
296 return render == nullptr && !is_baking();
297 }
298
299 bool is_baking() const
300 {
301 return is_light_bake;
302 }
303
304 bool overlays_enabled() const
305 {
306 return overlays_enabled_;
307 }
308
311 {
313 }
314
315 bool use_scene_lights() const
316 {
317 return (!v3d) ||
318 ((v3d->shading.type == OB_MATERIAL) &&
319 (v3d->shading.flag & V3D_SHADING_SCENE_LIGHTS)) ||
320 ((v3d->shading.type == OB_RENDER) &&
321 (v3d->shading.flag & V3D_SHADING_SCENE_LIGHTS_RENDER));
322 }
323
324 /* Light the scene using the selected HDRI in the viewport shading pop-over. */
325 bool use_studio_light() const
326 {
327 return (v3d) && (((v3d->shading.type == OB_MATERIAL) &&
328 ((v3d->shading.flag & V3D_SHADING_SCENE_WORLD) == 0)) ||
329 ((v3d->shading.type == OB_RENDER) &&
330 ((v3d->shading.flag & V3D_SHADING_SCENE_WORLD_RENDER) == 0)));
331 }
332
334 {
335 return (v3d) &&
336 ((v3d->shading.type == OB_MATERIAL) && (v3d->overlay.flag & V3D_OVERLAY_LOOK_DEV));
337 }
338
339 int get_recalc_flags(const ObjectRef &ob_ref)
340 {
341 auto get_flags = [&](const ObjectRuntimeHandle &runtime) {
342 int flags = 0;
344 flags, runtime.last_update_transform > depsgraph_last_update_, ID_RECALC_TRANSFORM);
346 flags, runtime.last_update_geometry > depsgraph_last_update_, ID_RECALC_GEOMETRY);
348 flags, runtime.last_update_shading > depsgraph_last_update_, ID_RECALC_SHADING);
349 return flags;
350 };
351
352 int flags = get_flags(*ob_ref.object->runtime);
353 if (ob_ref.dupli_parent) {
354 flags |= get_flags(*ob_ref.dupli_parent->runtime);
355 }
356
357 return flags;
358 }
359
360 int get_recalc_flags(const ::World &world)
361 {
362 return world.last_update > depsgraph_last_update_ ? int(ID_RECALC_SHADING) : 0;
363 }
364
365 private:
370 void render_sample();
371 void render_read_result(RenderLayer *render_layer, const char *view_name);
372
373 void mesh_sync(Object *ob, ObjectHandle &ob_handle);
374
375 void update_eval_members();
376
377 void set_time(float time);
378
379 struct DebugScope {
380 void *scope;
381
382 DebugScope(void *&scope_p, const char *name)
383 {
384 if (scope_p == nullptr) {
385 scope_p = GPU_debug_capture_scope_create(name);
386 }
387 scope = scope_p;
389 }
390
391 ~DebugScope()
392 {
394 }
395 };
396};
397
398} // 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 SET_FLAG_FROM_TEST(value, test, flag)
#define RPT_(msgid)
bool DEG_id_type_any_exists(const Depsgraph *depsgraph, short id_type)
@ ID_RECALC_TRANSFORM
Definition DNA_ID.h:962
@ ID_RECALC_SHADING
Definition DNA_ID.h:1002
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:982
@ ID_GP
@ OB_RENDER
@ OB_MATERIAL
struct ObjectRuntimeHandle ObjectRuntimeHandle
@ V3D_OVERLAY_LOOK_DEV
@ V3D_SHADING_SCENE_WORLD_RENDER
@ V3D_SHADING_SCENE_WORLD
@ V3D_SHADING_SCENE_LIGHTS
@ V3D_SHADING_SCENE_LIGHTS_RENDER
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
bool stop
Definition WM_types.hh:1016
float progress
Definition WM_types.hh:1019
BMesh const char void * data
BPy_StructRNA * depsgraph
unsigned long long int uint64_t
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
#define this
PassType
draw::UniformBuffer< UniformData > UniformDataBuf
T clamp(const T &a, const T &min, const T &max)
VecBase< int32_t, 2 > int2
ObjectRuntimeHandle * runtime
void bind_resources(PassType &pass)