Blender V4.3
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
11#pragma once
12
13#include <fmt/format.h>
14
15#include "BKE_object.hh"
16#include "DEG_depsgraph.hh"
18#include "DRW_render.hh"
19
21#include "eevee_camera.hh"
22#include "eevee_cryptomatte.hh"
24#include "eevee_film.hh"
25#include "eevee_gbuffer.hh"
26#include "eevee_hizbuffer.hh"
27#include "eevee_light.hh"
28#include "eevee_lightprobe.hh"
32#include "eevee_lookdev.hh"
33#include "eevee_material.hh"
34#include "eevee_motion_blur.hh"
35#include "eevee_pipeline.hh"
36#include "eevee_raytrace.hh"
38#include "eevee_sampling.hh"
39#include "eevee_shader.hh"
40#include "eevee_shadow.hh"
41#include "eevee_subsurface.hh"
42#include "eevee_sync.hh"
43#include "eevee_view.hh"
44#include "eevee_volume.hh"
45#include "eevee_world.hh"
46
47namespace blender::eevee {
48
49/* Combines data from several modules to avoid wasting binding slots. */
52
54 {
55 data.push_update();
56 }
57
58 template<typename PassType> void bind_resources(PassType &pass)
59 {
60 pass.bind_ubo(UNIFORM_BUF_SLOT, &data);
61 }
62};
63
68class Instance {
69 friend VelocityModule;
70 friend MotionBlurModule;
71
73 static void *debug_scope_render_sample;
74 static void *debug_scope_irradiance_setup;
75 static void *debug_scope_irradiance_sample;
76
77 uint64_t depsgraph_last_update_ = 0;
78 bool overlays_enabled_ = false;
79
80 bool shaders_are_ready_ = true;
81
83 std::string info_ = "";
84
85 public:
116
118 Depsgraph *depsgraph;
131 const View3D *v3d;
133
135 bool is_light_bake = false;
137 bool use_surfaces = true;
138 bool use_curves = true;
139 bool use_volumes = true;
140
143
144 public:
146 : shaders(*ShaderModule::module_get()),
147 sync(*this),
148 materials(*this),
150 pipelines(*this, uniform_data.data.pipeline),
151 shadows(*this, uniform_data.data.shadow),
152 lights(*this),
153 ambient_occlusion(*this, uniform_data.data.ao),
154 raytracing(*this, uniform_data.data.raytrace),
155 velocity(*this),
156 motion_blur(*this),
157 depth_of_field(*this),
158 cryptomatte(*this),
159 hiz_buffer(*this, uniform_data.data.hiz),
160 sampling(*this, uniform_data.data.clamp),
161 camera(*this, uniform_data.data.camera),
162 film(*this, uniform_data.data.film),
163 render_buffers(*this, uniform_data.data.render_pass),
164 main_view(*this),
165 capture_view(*this),
166 world(*this),
167 lookdev_view(*this),
168 lookdev(*this),
169 sphere_probes(*this),
170 planar_probes(*this),
171 volume_probes(*this),
172 light_probes(*this),
173 volume(*this, uniform_data.data.volumes){};
175
176 /* Render & Viewport. */
177 /* TODO(fclem): Split for clarity. */
178 void init(const int2 &output_res,
179 const rcti *output_rect,
180 const rcti *visible_rect,
181 RenderEngine *render,
182 Depsgraph *depsgraph,
183 Object *camera_object = nullptr,
184 const RenderLayer *render_layer = nullptr,
185 const DRWView *drw_view = nullptr,
186 const View3D *v3d = nullptr,
187 const RegionView3D *rv3d = nullptr);
188
189 void view_update();
190
191 void begin_sync();
192 void object_sync(Object *ob);
193 void end_sync();
194
198 bool do_lightprobe_sphere_sync() const;
199 bool do_planar_probe_sync() const;
200
206 bool needs_planar_probe_passes() const;
207
208 /* Render. */
209
210 void render_sync();
211 void render_frame(RenderEngine *engine, RenderLayer *render_layer, const char *view_name);
212 void store_metadata(RenderResult *render_result);
213
214 /* Viewport. */
215
216 void draw_viewport();
218
219 /* Light bake. */
220
223 Object &probe,
224 FunctionRef<void()> context_enable,
225 FunctionRef<void()> context_disable,
226 FunctionRef<bool()> stop,
227 FunctionRef<void(LightProbeGridCacheFrame *, float progress)> result_update);
228
229 static void update_passes(RenderEngine *engine, Scene *scene, ViewLayer *view_layer);
230
231 /* Append a new line to the info string. */
232 template<typename... Args> void info_append(const char *msg, Args &&...args)
233 {
234 info_ += fmt::format(msg, args...);
235 info_ += "\n";
236 }
237
238 /* The same as `info_append`, but `msg` will be translated.
239 * NOTE: When calling this function, `msg` should be a string literal. */
240 template<typename... Args> void info_append_i18n(const char *msg, Args &&...args)
241 {
242 std::string fmt_msg = fmt::format(RPT_(msg), args...) + "\n";
243 /* Don't print the same error twice. */
244 if (info_ != fmt_msg && !BLI_str_endswith(info_.c_str(), fmt_msg.c_str())) {
245 info_ += fmt_msg;
246 }
247 }
248
249 const char *info_get()
250 {
251 return info_.c_str();
252 }
253
254 bool is_viewport() const
255 {
256 return render == nullptr && !is_baking();
257 }
258
259 bool is_image_render() const
260 {
262 }
263
265 {
267 }
268
269 bool is_baking() const
270 {
271 return is_light_bake;
272 }
273
274 bool overlays_enabled() const
275 {
276 return overlays_enabled_;
277 }
278
281 {
283 }
284
285 bool is_playback() const
286 {
287 return DRW_state_is_playback();
288 }
289
290 bool is_transforming() const
291 {
292 BLI_assert_msg(!is_image_render(), "Caller need to check, otherwise this is unsafe");
293 return (G.moving & (G_TRANSFORM_OBJ | G_TRANSFORM_EDIT)) != 0;
294 }
295
296 bool is_navigating() const
297 {
299 }
300
301 bool is_painting() const
302 {
303 return DRW_state_is_painting();
304 }
305
306 bool use_scene_lights() const
307 {
308 return (!v3d) ||
309 ((v3d->shading.type == OB_MATERIAL) &&
311 ((v3d->shading.type == OB_RENDER) &&
313 }
314
315 /* Light the scene using the selected HDRI in the viewport shading pop-over. */
316 bool use_studio_light() const
317 {
318 return (v3d) && (((v3d->shading.type == OB_MATERIAL) &&
320 ((v3d->shading.type == OB_RENDER) &&
322 }
323
325 {
326 return (v3d) &&
328 }
329
330 int get_recalc_flags(const ObjectRef &ob_ref)
331 {
332 auto get_flags = [&](const ObjectRuntimeHandle &runtime) {
333 int flags = 0;
335 flags, runtime.last_update_transform > depsgraph_last_update_, ID_RECALC_TRANSFORM);
337 flags, runtime.last_update_geometry > depsgraph_last_update_, ID_RECALC_GEOMETRY);
339 flags, runtime.last_update_shading > depsgraph_last_update_, ID_RECALC_SHADING);
340 return flags;
341 };
342
343 int flags = get_flags(*ob_ref.object->runtime);
344 if (ob_ref.dupli_parent) {
345 flags |= get_flags(*ob_ref.dupli_parent->runtime);
346 }
347
348 return flags;
349 }
350
351 int get_recalc_flags(const ::World &world)
352 {
353 return world.last_update > depsgraph_last_update_ ? int(ID_RECALC_SHADING) : 0;
354 }
355
356 private:
358 static void object_sync_render(void *instance_,
359 Object *ob,
360 RenderEngine *engine,
361 Depsgraph *depsgraph);
366 void render_sample();
367 void render_read_result(RenderLayer *render_layer, const char *view_name);
368
369 void mesh_sync(Object *ob, ObjectHandle &ob_handle);
370
371 void update_eval_members();
372
373 void set_time(float time);
374
375 struct DebugScope {
376 void *scope;
377
378 DebugScope(void *&scope_p, const char *name)
379 {
380 if (scope_p == nullptr) {
381 scope_p = GPU_debug_capture_scope_create(name);
382 }
383 scope = scope_p;
385 }
386
387 ~DebugScope()
388 {
390 }
391 };
392};
393
394} // namespace blender::eevee
@ G_TRANSFORM_OBJ
@ G_TRANSFORM_EDIT
General operations, lookup, etc. for blender objects.
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:57
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:1021
@ ID_RECALC_SHADING
Definition DNA_ID.h:1061
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1041
@ 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
void init()
A running instance of the engine.
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
const RenderLayer * render_layer
void object_sync(Object *ob)
const RegionView3D * rv3d
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_viewport_image_render() 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)
bool DRW_state_is_viewport_image_render()
bool DRW_state_is_image_render()
bool DRW_state_is_painting()
bool DRW_state_is_navigating()
bool DRW_state_is_playback()
#define UNIFORM_BUF_SLOT
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
PassType
#define G(x, y, z)
unsigned __int64 uint64_t
Definition stdint.h:90
ObjectRuntimeHandle * runtime
View3DOverlay overlay
View3DShading shading
void bind_resources(PassType &pass)