48 View view_ = {
"DefaultView"};
71 const char *hair_buffer_overflow_error_ =
nullptr;
83 if (material_count > dummy_gpu_materials_.size()) {
84 dummy_gpu_materials_.resize(material_count,
nullptr);
86 return dummy_gpu_materials_.as_span().slice(
IndexRange(material_count));
101 scene_state_.init(this->draw_ctx, scene_updated, camera_ob);
102 shadow_ps_.init(scene_state_, resources_);
103 resources_.init(scene_state_, this->draw_ctx);
105 outline_ps_.init(scene_state_);
106 dof_ps_.init(scene_state_, this->draw_ctx);
107 anti_aliasing_ps_.init(scene_state_);
112 resources_.material_buf.clear_and_trim();
114 opaque_ps_.sync(scene_state_, resources_);
115 transparent_ps_.sync(scene_state_, resources_);
116 transparent_depth_ps_.sync(scene_state_, resources_);
119 volume_ps_.sync(resources_);
120 outline_ps_.sync(resources_);
121 dof_ps_.sync(resources_, this->draw_ctx);
122 anti_aliasing_ps_.sync(scene_state_, resources_);
124 hair_buffer_overflow_error_ =
nullptr;
129 resources_.material_buf.push_update();
134 switch (color_type) {
140 return scene_state_.material_override;
142 return scene_state_.material_attribute_color;
157 if (scene_state_.render_finished) {
161 Object *ob = ob_ref.object;
177 volume_ps_.object_sync_modifier(
manager, resources_, scene_state_, ob_ref, md);
181 is_object_data_visible =
false;
189 if (is_object_data_visible) {
193 emitter_handle = handle;
197 this->
mesh_sync(ob_ref, handle, object_state);
198 emitter_handle = handle;
207 if (scene_state_.shading.type !=
OB_WIRE) {
208 volume_ps_.object_sync_volume(
manager,
241 if (scene_state_.xray_mode || is_transparent) {
243 draw_callback(transparent_ps_.accumulation_in_front_ps_);
244 draw_callback(transparent_depth_ps_.in_front_ps_);
247 draw_callback(transparent_ps_.accumulation_ps_);
248 draw_callback(transparent_depth_ps_.main_ps_);
253 draw_callback(opaque_ps_.gbuffer_in_front_ps_);
256 draw_callback(opaque_ps_.gbuffer_ps_);
266 bool show_missing_texture =
false)
268 resources_.material_buf.append(material);
269 int material_index = resources_.material_buf.size() - 1;
271 if (show_missing_texture && (!
texture || !
texture->gpu.texture)) {
272 texture = &resources_.missing_texture;
276 mesh_pass.get_subpass(eGeometryType::MESH, texture).draw(batch, handle, material_index);
282 bool has_transparent_material =
false;
293 ob_ref.
object, this->get_dummy_gpu_materials(material_count));
298 if (batches[
i] ==
nullptr) {
302 int material_slot =
i;
304 has_transparent_material = has_transparent_material || mat.is_transparent();
335 has_transparent_material = has_transparent_material || mat.is_transparent();
342 shadow_ps_.object_sync(scene_state_, ob_ref, handle, has_transparent_material);
360 mat.base_color =
batch.debug_color();
376 mat.base_color =
batch.debug_color();
389 resources_.material_buf.append(mat);
390 int material_index = resources_.material_buf.size() - 1;
393 PassMain::Sub &pass =
394 mesh_pass.get_subpass(eGeometryType::POINTCLOUD).sub(
"Point Cloud SubPass");
395 gpu::Batch *batch = pointcloud_sub_pass_setup(pass, ob_ref.object);
396 pass.draw(batch, handle, material_index);
408 ob_ref, ob_ref.
object->object_to_world());
415 resources_.material_buf.append(mat);
416 int material_index = resources_.material_buf.size() - 1;
419 PassMain::Sub &pass =
420 mesh_pass.get_subpass(eGeometryType::CURVES, &texture).sub(
"Hair SubPass");
421 pass.push_constant(
"emitter_object_id", int(emitter_handle.raw()));
422 gpu::Batch *batch = hair_sub_pass_setup(pass, scene_state_.scene, ob_ref, psys, md);
423 pass.draw(batch, handle, material_index);
432 resources_.material_buf.append(mat);
433 int material_index = resources_.material_buf.size() - 1;
436 PassMain::Sub &pass = mesh_pass.get_subpass(eGeometryType::CURVES).sub(
"Curves SubPass");
438 const char *error = nullptr;
439 gpu::Batch *batch = curves_sub_pass_setup(pass, scene_state_.scene, ob_ref.object, error);
441 hair_buffer_overflow_error_ = error;
443 pass.draw(
batch, handle, material_index);
452 int2 resolution = scene_state_.resolution;
456 bool needs_depth_in_front = !transparent_ps_.accumulation_in_front_ps_.is_empty() ||
457 (!opaque_ps_.gbuffer_in_front_ps_.is_empty() &&
458 scene_state_.sample == 0);
459 resources_.depth_in_front_tx.wrap(needs_depth_in_front ? depth_in_front_tx :
nullptr);
460 if (!needs_depth_in_front || opaque_ps_.gbuffer_in_front_ps_.is_empty()) {
462 resources_.clear_in_front_fb.bind();
466 resources_.depth_tx.wrap(depth_tx);
467 resources_.color_tx.wrap(color_tx);
469 if (scene_state_.render_finished) {
471 anti_aliasing_ps_.draw(
476 anti_aliasing_ps_.setup_view(view_, scene_state_);
479 if (scene_state_.draw_object_id) {
480 resources_.object_id_tx.acquire(resolution,
481 gpu::TextureFormat::UINT_16,
489 resources_.clear_fb.bind();
490 float4 clear_colors[2] = {scene_state_.background_color,
float4(0.0f)};
495 manager, view_, resources_, resolution, scene_state_.draw_shadows ? &shadow_ps_ :
nullptr);
496 transparent_ps_.draw(manager, view_, resources_, resolution);
497 transparent_depth_ps_.draw(manager, view_, resources_);
499 volume_ps_.draw(manager, view_, resources_);
500 outline_ps_.draw(manager, resources_);
501 dof_ps_.draw(manager, view_, resources_, resolution);
502 anti_aliasing_ps_.draw(
draw_ctx, manager, view_, scene_state_, resources_, depth_in_front_tx);
504 resources_.object_id_tx.release();
512 this->
draw(manager, depth_tx, depth_in_front_tx, color_tx);
514 if (scene_state_.sample + 1 < scene_state_.samples_len) {
518 if (hair_buffer_overflow_error_) {
531 if (
draw_ctx->is_viewport_image_render()) {
546 if (scene_state_.render_finished) {
549 this->
draw(manager, depth_tx, depth_in_front_tx, color_tx);
554 for (
auto i :
IndexRange(scene_state_.samples_len)) {
555 if (hair_buffer_overflow_error_) {
563 scene_state_.sample =
i;
565 resources_.init(scene_state_,
draw_ctx);
566 dof_ps_.init(scene_state_,
draw_ctx);
567 anti_aliasing_ps_.sync(scene_state_, resources_);
569 this->
draw(manager, depth_tx, depth_in_front_tx, color_tx);
582 return new Instance();
585void Engine::free_static()
587 ShaderCache::release();
604 const int2 size = {int(viewport_size.
x), int(viewport_size.
y)};
610 if (dtxl->
color ==
nullptr) {
614 "txl.color",
size.x,
size.y, 1, gpu::TextureFormat::SFLOAT_16_16_16_16, usage,
nullptr);
619 gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8,
626 gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8,
639 {GPU_ATTACHMENT_TEXTURE(dtxl->depth), GPU_ATTACHMENT_TEXTURE(dtxl->color)});
642 {GPU_ATTACHMENT_TEXTURE(dtxl->depth), GPU_ATTACHMENT_NONE});
645 {GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(dtxl->color)});
653 const char *viewname,
673 const char *viewname,
699 z = winmat[3][2] / (
z + winmat[2][2]);
707 float range =
fabsf(far - near);
714 z =
z * range - near;
General operations, lookup, etc. for materials.
Material * BKE_material_default_empty()
Material * BKE_object_material_get_eval(Object *ob, short act)
int BKE_object_material_used_with_fallback_eval(const Object &ob)
bool BKE_modifier_is_enabled(const Scene *scene, ModifierData *md, int required_mode)
ModifierData * BKE_modifiers_findby_type(const Object *ob, ModifierType type)
General operations, lookup, etc. for blender objects.
A BVH for high poly meshes.
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE int BLI_rcti_size_y(const struct rcti *rct)
BLI_INLINE int BLI_rcti_size_x(const struct rcti *rct)
char * STRNCPY(char(&dst)[N], const char *src)
uint64_t DEG_get_update_count(const Depsgraph *depsgraph)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ eModifierType_ParticleSystem
#define RE_PASSNAME_COMBINED
#define RE_PASSNAME_DEPTH
@ V3D_SHADING_TEXTURE_COLOR
@ V3D_SHADING_VERTEX_COLOR
@ V3D_SHADING_MATERIAL_COLOR
@ V3D_SHADING_OBJECT_COLOR
@ V3D_SHADING_RANDOM_COLOR
@ V3D_SHADING_SINGLE_COLOR
void DRW_submission_end()
void DRW_submission_start()
void GPU_render_step(bool force_resource_release=false)
GPUBackendType GPU_backend_get_type()
#define GPU_ATTACHMENT_TEXTURE(_texture)
void GPU_framebuffer_clear_depth_stencil(blender::gpu::FrameBuffer *fb, float clear_depth, uint clear_stencil)
void GPU_framebuffer_read_color(blender::gpu::FrameBuffer *fb, int x, int y, int width, int height, int channels, int slot, eGPUDataFormat data_format, void *r_data)
void GPU_framebuffer_multi_clear(blender::gpu::FrameBuffer *fb, const float(*clear_colors)[4])
#define GPU_ATTACHMENT_NONE
bool GPU_framebuffer_check_valid(blender::gpu::FrameBuffer *fb, char err_out[256])
void GPU_framebuffer_read_depth(blender::gpu::FrameBuffer *fb, int x, int y, int width, int height, eGPUDataFormat data_format, void *r_data)
#define GPU_framebuffer_ensure_config(_fb,...)
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_ATTACHMENT
@ GPU_TEXTURE_USAGE_GENERAL
blender::gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, blender::gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
BPy_StructRNA * depsgraph
unsigned long long int uint64_t
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
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)
float near_clip(int view_id=0) const
static View & default_get()
float far_clip(int view_id=0) const
A running instance of the engine.
void hair_sync(Manager &manager, ObjectRef &ob_ref, ResourceHandleRange emitter_handle, const ObjectState &object_state, ParticleSystem *psys, ModifierData *md)
void draw(Manager &manager) final
void mesh_sync(ObjectRef &ob_ref, ResourceHandleRange handle, const ObjectState &object_state)
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)
blender::StringRefNull name_get() final
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)
void sculpt_sync(ObjectRef &ob_ref, ResourceHandleRange handle, const ObjectState &object_state)
void pointcloud_sync(Manager &manager, ObjectRef &ob_ref, const ObjectState &object_state)
const DRWContext * draw_ctx
const DRWContext * DRW_context_get()
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)
void DRW_render_object_iter(RenderEngine *engine, Depsgraph *depsgraph, std::function< void(blender::draw::ObjectRef &, RenderEngine *, Depsgraph *)> callback)
bool DRW_object_is_renderable(const Object *ob)
int DRW_object_visibility_in_active_context(const Object *ob)
bool DRW_object_is_visible_psys_in_active_context(const Object *object, const ParticleSystem *psys)
void DRW_viewport_request_redraw()
blender::draw::Manager * DRW_manager_get()
#define SCULPT_DEBUG_DRAW
struct @021025263243242147216143265077100330027142264337::@225245033123204053237120173316075113304004012000 batch
TEX_TEMPLATE DataVec texture(T, FltCoord, float=0.0f) RET
BLI_INLINE float fb(float length, float L)
void RE_GetCameraModelMatrix(const Render *re, const Object *camera, float r_modelmat[4][4])
void RE_GetCameraWindow(Render *re, const Object *camera, float r_winmat[4][4])
Object * RE_GetCamera(Render *re)
void RE_engine_report(RenderEngine *engine, int type, const char *msg)
bool RE_engine_test_break(RenderEngine *engine)
void RE_engine_set_error_message(RenderEngine *engine, const char *msg)
void RE_engine_register_pass(RenderEngine *engine, Scene *scene, ViewLayer *view_layer, const char *name, int channels, const char *chanid, eNodeSocketDatatype type)
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)
gpu::Batch * DRW_cache_object_surface_get(Object *ob)
@ SCULPT_BATCH_VERTEX_COLOR
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)
bool assign_if_different(T &old_value, T new_value)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
RenderPass * RE_pass_find_by_name(RenderLayer *rl, const char *name, const char *viewname)
const char * RE_GetActiveRenderView(Render *re)
DefaultFramebufferList * viewport_framebuffer_list_get() const
blender::float2 viewport_size_get() const
DefaultTextureList * viewport_texture_list_get() const
blender::gpu::FrameBuffer * default_fb
blender::gpu::FrameBuffer * color_only_fb
blender::gpu::FrameBuffer * depth_only_fb
blender::gpu::Texture * depth
blender::gpu::Texture * color
blender::gpu::Texture * depth_in_front
struct FluidDomainSettings * domain
ImBufFloatBuffer float_buffer
const c_style_mat & ptr() const
bool use_per_material_batches
MaterialTexture image_paint_override
eV3DShadingColorType color_type
bool show_missing_texture
static void workbench_render(RenderEngine *engine, Depsgraph *depsgraph)
static void workbench_render_to_image(RenderEngine *engine, RenderLayer *layer, const rcti rect)
RenderEngineType DRW_engine_viewport_workbench_type
static bool workbench_render_framebuffers_init(const DRWContext *draw_ctx)
static void workbench_render_update_passes(RenderEngine *engine, Scene *scene, ViewLayer *view_layer)
static void write_render_z_output(RenderLayer *layer, const char *viewname, gpu::FrameBuffer *fb, const rcti *rect, const float4x4 &winmat)
static void write_render_color_output(RenderLayer *layer, const char *viewname, gpu::FrameBuffer *fb, const rcti *rect)