54 View view_ = {
"DefaultView"};
77 const char *hair_buffer_overflow_error_ =
nullptr;
89 if (material_count > dummy_gpu_materials_.size()) {
90 dummy_gpu_materials_.resize(material_count,
nullptr);
92 return dummy_gpu_materials_.as_span().slice(
IndexRange(material_count));
107 scene_state_.init(this->draw_ctx, scene_updated, camera_ob);
108 shadow_ps_.init(scene_state_, resources_);
109 resources_.init(scene_state_, this->draw_ctx);
111 outline_ps_.init(scene_state_);
112 dof_ps_.init(scene_state_, this->draw_ctx);
113 anti_aliasing_ps_.init(scene_state_);
118 resources_.material_buf.clear_and_trim();
120 opaque_ps_.sync(scene_state_, resources_);
121 transparent_ps_.sync(scene_state_, resources_);
122 transparent_depth_ps_.sync(scene_state_, resources_);
124 shadow_ps_.sync(resources_);
125 volume_ps_.sync(resources_);
126 outline_ps_.sync(resources_);
127 dof_ps_.sync(resources_, this->draw_ctx);
128 anti_aliasing_ps_.sync(scene_state_, resources_);
130 hair_buffer_overflow_error_ =
nullptr;
135 resources_.material_buf.push_update();
136 shadow_ps_.end_sync();
141 switch (color_type) {
147 return scene_state_.material_override;
149 return scene_state_.material_attribute_color;
164 if (scene_state_.render_finished) {
168 Object *ob = ob_ref.object;
184 volume_ps_.object_sync_modifier(
manager, resources_, scene_state_, ob_ref, md);
188 is_object_data_visible =
false;
196 if (is_object_data_visible) {
200 emitter_handle = handle;
205 emitter_handle = handle;
214 if (scene_state_.shading.type !=
OB_WIRE) {
215 volume_ps_.object_sync_volume(
manager,
248 if (scene_state_.xray_mode || is_transparent) {
250 draw_callback(transparent_ps_.accumulation_in_front_ps_);
251 draw_callback(transparent_depth_ps_.in_front_ps_);
254 draw_callback(transparent_ps_.accumulation_ps_);
255 draw_callback(transparent_depth_ps_.main_ps_);
260 draw_callback(opaque_ps_.gbuffer_in_front_ps_);
263 draw_callback(opaque_ps_.gbuffer_ps_);
273 bool show_missing_texture =
false)
275 resources_.material_buf.append(material);
276 int material_index = resources_.material_buf.size() - 1;
278 if (show_missing_texture && (!
texture || !
texture->gpu.texture)) {
279 texture = &resources_.missing_texture;
283 mesh_pass.get_subpass(eGeometryType::MESH, texture).draw(batch, handle, material_index);
292 bool has_transparent_material =
false;
303 ob_ref.
object, this->get_dummy_gpu_materials(material_count));
308 if (batches[i] ==
nullptr) {
312 int material_slot = i;
314 has_transparent_material = has_transparent_material || mat.is_transparent();
345 has_transparent_material = has_transparent_material || mat.is_transparent();
352 shadow_ps_.object_sync(scene_state_, ob_ref, handle, has_transparent_material);
372 if (scene_state_.show_paint_bvh_debug) {
373 mat.base_color = batch.debug_color();
388 if (scene_state_.show_paint_bvh_debug) {
389 mat.base_color = batch.debug_color();
402 resources_.material_buf.append(mat);
403 int material_index = resources_.material_buf.size() - 1;
406 const bool has_transparency = mat.is_transparent();
413 pass.
draw(batch, handle, material_index);
425 ob_ref.
object->object_to_world());
432 resources_.material_buf.append(mat);
433 int material_index = resources_.material_buf.size() - 1;
436 PassMain::Sub &pass =
437 mesh_pass.get_subpass(eGeometryType::CURVES, &texture).sub(
"Hair SubPass");
438 pass.push_constant(
"emitter_object_id", int(emitter_handle.raw()));
439 gpu::Batch *batch = hair_sub_pass_setup(pass, scene_state_.scene, ob_ref, psys, md);
440 pass.draw(batch, {ResourceID(handle)}, material_index);
449 resources_.material_buf.append(mat);
450 int material_index = resources_.material_buf.size() - 1;
453 PassMain::Sub &pass = mesh_pass.get_subpass(eGeometryType::CURVES).sub(
"Curves SubPass");
455 const char *error = nullptr;
456 gpu::Batch *batch = curves_sub_pass_setup(pass, scene_state_.scene, ob_ref.object, error);
458 hair_buffer_overflow_error_ = error;
460 pass.draw(batch, handle, material_index);
469 int2 resolution = scene_state_.resolution;
473 bool needs_depth_in_front = !transparent_ps_.accumulation_in_front_ps_.is_empty() ||
474 (!opaque_ps_.gbuffer_in_front_ps_.is_empty() &&
475 scene_state_.sample == 0);
476 resources_.depth_in_front_tx.wrap(needs_depth_in_front ? depth_in_front_tx :
nullptr);
477 if (!needs_depth_in_front || opaque_ps_.gbuffer_in_front_ps_.is_empty()) {
479 resources_.clear_in_front_fb.bind();
483 resources_.depth_tx.wrap(depth_tx);
484 resources_.color_tx.wrap(color_tx);
486 if (scene_state_.render_finished) {
488 anti_aliasing_ps_.draw(
493 anti_aliasing_ps_.setup_view(view_, scene_state_);
499 if (scene_state_.draw_object_id) {
500 resources_.object_id_tx.acquire_2d(resolution,
501 gpu::TextureFormat::UINT_16,
509 resources_.clear_fb.bind();
510 std::array<double4, 2> clear_colors = {
double4(scene_state_.background_color),
double4(0.0f)};
515 manager, view_, resources_, resolution, scene_state_.draw_shadows ? &shadow_ps_ :
nullptr);
516 transparent_ps_.draw(manager, view_, resources_, resolution);
517 transparent_depth_ps_.draw(manager, view_, resources_);
519 volume_ps_.draw(manager, view_, resources_);
520 outline_ps_.draw(manager, resources_);
521 dof_ps_.draw(manager, view_, resources_, resolution);
522 anti_aliasing_ps_.draw(
draw_ctx, manager, view_, scene_state_, resources_, depth_in_front_tx);
524 resources_.object_id_tx.release();
532 this->
draw(manager, depth_tx, depth_in_front_tx, color_tx);
534 if (scene_state_.sample + 1 < scene_state_.samples_len) {
538 if (hair_buffer_overflow_error_) {
551 if (
draw_ctx->is_viewport_image_render()) {
566 if (scene_state_.render_finished) {
569 this->
draw(manager, depth_tx, depth_in_front_tx, color_tx);
574 for (
auto i :
IndexRange(scene_state_.samples_len)) {
575 if (hair_buffer_overflow_error_) {
583 scene_state_.sample = i;
585 resources_.init(scene_state_,
draw_ctx);
586 dof_ps_.init(scene_state_,
draw_ctx);
587 anti_aliasing_ps_.sync(scene_state_, resources_);
589 this->
draw(manager, depth_tx, depth_in_front_tx, color_tx);
607void Engine::free_static()
609 ShaderCache::release();
624 const int2 size = {int(viewport_size.x), int(viewport_size.y)};
630 if (dtxl->
color ==
nullptr) {
634 "txl.color", size.x, size.y, 1, gpu::TextureFormat::SFLOAT_16_16_16_16, usage,
nullptr);
639 gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8,
646 gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8,
659 {GPU_ATTACHMENT_TEXTURE(dtxl->depth), GPU_ATTACHMENT_TEXTURE(dtxl->color)});
662 {GPU_ATTACHMENT_TEXTURE(dtxl->depth), GPU_ATTACHMENT_NONE});
665 {GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(dtxl->color)});
673 const char *viewname,
693 const char *viewname,
719 z = winmat[3][2] / (
z + winmat[2][2]);
727 float range =
fabsf(far - near);
734 z =
z * range - near;
753 Depsgraph *depsgraph = draw_ctx->
depsgraph;
771 instance.
init(depsgraph, camera_ob);
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
A BVH for high poly meshes.
#define RE_PASSNAME_COMBINED
#define RE_PASSNAME_DEPTH
#define GPU_ATTACHMENT_TEXTURE(_texture)
#define GPU_ATTACHMENT_NONE
#define GPU_framebuffer_ensure_config(_fb,...)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
constexpr IndexRange()=default
constexpr bool is_empty() const
void begin_sync(Object *object_active=nullptr)
ResourceHandle resource_handle_for_psys(const ObjectRef &ref, const float4x4 &model_matrix)
ResourceHandleRange unique_handle_for_sculpt(const ObjectRef &ref)
ResourceHandleRange unique_handle(const ObjectRef &ref)
static void default_set(const float4x4 &view_mat, const float4x4 &win_mat)
static View & default_get()
PassBase< DrawCommandBufType > & sub(const char *name)
void draw(gpu::Batch *batch, uint instance_len=-1, uint vertex_len=-1, uint vertex_first=-1, ResourceIDRange res_id={}, uint custom_id=0)
detail::PassBase< command::DrawMultiBuf > Sub
A running instance of the engine.
void object_sync(ObjectRef &ob_ref, Manager &manager) final
void init(const int2 &output_res, const rcti *output_rect, const rcti *visible_rect, RenderEngine *render, Depsgraph *depsgraph, Object *camera_object=nullptr, const RenderLayer *render_layer=nullptr, View *drw_view_=nullptr, const View3D *v3d=nullptr, const RegionView3D *rv3d=nullptr)
void draw(Manager &manager) final
void draw_viewport(Manager &manager, gpu::Texture *depth_tx, gpu::Texture *depth_in_front_tx, gpu::Texture *color_tx)
void draw_mesh(ObjectRef &ob_ref, Material &material, gpu::Batch *batch, ResourceHandleRange handle, const MaterialTexture *texture=nullptr, bool show_missing_texture=false)
Material get_material(ObjectRef ob_ref, eV3DShadingColorType color_type, int slot=0)
void draw(Manager &manager, gpu::Texture *depth_tx, gpu::Texture *depth_in_front_tx, gpu::Texture *color_tx)
void object_sync(ObjectRef &ob_ref, Manager &manager) final
void draw_to_mesh_pass(ObjectRef &ob_ref, bool is_transparent, F draw_callback)
Span< const GPUMaterial * > get_dummy_gpu_materials(int material_count)
void curves_sync(Manager &manager, ObjectRef &ob_ref, const ObjectState &object_state)
void draw_image_render(Manager &manager, gpu::Texture *depth_tx, gpu::Texture *depth_in_front_tx, gpu::Texture *color_tx, RenderEngine *engine=nullptr)
void init(Depsgraph *depsgraph, Object *camera_ob=nullptr)
StringRefNull name_get() final
void pointcloud_sync(Manager &manager, ObjectRef &ob_ref, const ObjectState &object_state)
void mesh_sync(Manager &manager, ObjectRef &ob_ref, ResourceHandleRange handle, const ObjectState &object_state)
void hair_sync(Manager &manager, ObjectRef &ob_ref, ResourceHandle emitter_handle, const ObjectState &object_state, ParticleSystem *psys, ModifierData *md)
void sculpt_sync(Manager &manager, ObjectRef &ob_ref, ResourceHandleRange handle, const ObjectState &object_state)
const DRWContext * draw_ctx
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
void DRW_gsplat_ensure_radiance(draw::Manager &manager, draw::View &view)
Span< gpu::Batch * > DRW_cache_mesh_surface_texpaint_get(Object *ob)
gpu::Batch * DRW_cache_mesh_surface_sculptcolors_get(Object *ob)
gpu::Batch * DRW_cache_mesh_surface_vertpaint_get(Object *ob)
Vector< SculptBatch > sculpt_batches_get(const Object *ob, SculptBatchFeature features)
bool pointcloud_is_gsplat(Object *ob)
gpu::Batch * DRW_cache_object_surface_get(Object *ob)
@ SCULPT_BATCH_VERTEX_COLOR
gpu::Batch * pointcloud_sub_pass_setup(PassMain::Sub &sub_ps, const ObjectRef &ob_ref, const ResourceHandleRange &res_handle, GPUMaterial *gpu_material=nullptr)
Span< gpu::Batch * > DRW_cache_object_surface_material_get(Object *ob, const Span< const GPUMaterial * > materials)
gpu::Batch * DRW_cache_mesh_surface_texpaint_single_get(Object *ob)
CartesianBasis invert(const CartesianBasis &basis)
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void DRW_render_to_image(RenderEngine *engine, Depsgraph *depsgraph, std::function< void(RenderEngine *, RenderLayer *, const rcti)> render_view_cb, std::function< void(RenderResult *)> store_metadata_cb)
unsigned __int64 uint64_t
void GPU_framebuffer_read_color(gpu::FrameBuffer *fb, int x, int y, int width, int height, int channels, int slot, eGPUDataFormat data_format, void *r_data)
static void workbench_render_to_image(RenderEngine *engine, RenderLayer *layer, const rcti rect)
char * STRNCPY(char(&dst)[N], const char *src)
int BKE_object_material_used_with_fallback_eval(const Object &ob)
RenderEngineType DRW_engine_viewport_workbench_type
bool assign_if_different(T &old_value, T &&new_value)
bool GPU_framebuffer_check_valid(gpu::FrameBuffer *fb, char err_out[256])
void RE_engine_report(RenderEngine *engine, int type, const char *msg)
BLI_INLINE float fb(float length, float L)
uint64_t DEG_get_update_count(const Depsgraph *depsgraph)
void GPU_framebuffer_clear_depth_stencil(gpu::FrameBuffer *fb, float clear_depth, uint clear_stencil)
bool DRW_object_is_renderable(const Object *ob)
GPUBackendType GPU_backend_get_type()
@ eModifierType_ParticleSystem
void GPU_render_step(bool force_resource_release=false)
void RE_GetCameraWindow(Render *re, const Object *camera, float r_winmat[4][4])
Material * BKE_material_default_empty()
MatBase< float, 4, 4 > float4x4
int DRW_object_visibility_in_active_context(const Object *ob)
void DRW_render_object_iter(RenderEngine *engine, Depsgraph *depsgraph, std::function< void(draw::ObjectRef &, RenderEngine *, Depsgraph *)> callback)
static void workbench_render(RenderEngine *engine, Depsgraph *depsgraph)
const char * RE_GetActiveRenderView(Render *re)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
void RE_GetCameraModelMatrix(const Render *re, const Object *camera, float r_modelmat[4][4])
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void RE_engine_register_pass(RenderEngine *engine, Scene *scene, ViewLayer *view_layer, const char *name, int channels, const char *chanid, eNodeSocketDatatype type)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_GENERAL
@ GPU_TEXTURE_USAGE_ATTACHMENT
static void write_render_color_output(RenderLayer *layer, const char *viewname, gpu::FrameBuffer *fb, const rcti *rect)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
bool RE_engine_test_break(RenderEngine *engine)
bool DRW_object_is_visible_psys_in_active_context(const Object *object, const ParticleSystem *psys)
void DRW_submission_end()
const DRWContext * DRW_context_get()
@ V3D_SHADING_SINGLE_COLOR
@ V3D_SHADING_RANDOM_COLOR
@ V3D_SHADING_MATERIAL_COLOR
@ V3D_SHADING_VERTEX_COLOR
@ V3D_SHADING_TEXTURE_COLOR
@ V3D_SHADING_OBJECT_COLOR
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
static bool workbench_render_framebuffers_init(const DRWContext *draw_ctx)
void GPU_framebuffer_multi_clear(gpu::FrameBuffer *fb, Span< double4 > clear_colors)
RenderPass * RE_pass_find_by_name(RenderLayer *rl, const char *name, const char *viewname)
void RE_engine_set_error_message(RenderEngine *engine, const char *msg)
ModifierData * BKE_modifiers_findby_type(const Object *ob, ModifierType type)
Material * BKE_object_material_get_eval(Object *ob, short act)
void DRW_submission_start()
draw::Manager * DRW_manager_get()
void GPU_framebuffer_read_depth(gpu::FrameBuffer *fb, int x, int y, int width, int height, eGPUDataFormat data_format, void *r_data)
static void workbench_render_update_passes(RenderEngine *engine, Scene *scene, ViewLayer *view_layer)
bool BKE_modifier_is_enabled(const Scene *scene, ModifierData *md, int required_mode)
VecBase< double, 4 > double4
void DRW_viewport_request_redraw()
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
static void write_render_z_output(RenderLayer *layer, const char *viewname, gpu::FrameBuffer *fb, const rcti *rect, const float4x4 &winmat)
Object * RE_GetCamera(Render *re)
DefaultTextureList * viewport_texture_list_get() const
float2 viewport_size_get() const
DefaultFramebufferList * viewport_framebuffer_list_get() const
bool is_scene_render() const
gpu::FrameBuffer * default_fb
gpu::FrameBuffer * depth_only_fb
gpu::FrameBuffer * color_only_fb
gpu::Texture * depth_in_front
struct FluidDomainSettings * domain
float * float_data_for_write()
const c_style_mat & ptr() const
ListBaseT< ModifierData > modifiers
eObject_DrawExtraFlag dtx
DrawEngine * create_instance() final
bool use_per_material_batches
MaterialTexture image_paint_override
eV3DShadingColorType color_type
bool show_missing_texture