46 View view_ = {
"DefaultView"};
79 if (material_count > dummy_gpu_materials_.size()) {
80 dummy_gpu_materials_.resize(material_count,
nullptr);
82 return dummy_gpu_materials_.as_span().slice(
IndexRange(material_count));
97 scene_state_.init(this->draw_ctx, scene_updated, camera_ob);
98 shadow_ps_.init(scene_state_, resources_);
99 resources_.init(scene_state_, this->draw_ctx);
101 outline_ps_.init(scene_state_);
102 dof_ps_.init(scene_state_, this->draw_ctx);
103 anti_aliasing_ps_.init(scene_state_);
108 resources_.material_buf.clear_and_trim();
110 opaque_ps_.sync(scene_state_, resources_);
111 transparent_ps_.sync(scene_state_, resources_);
112 transparent_depth_ps_.sync(scene_state_, resources_);
115 volume_ps_.sync(resources_);
116 outline_ps_.sync(resources_);
117 dof_ps_.sync(resources_, this->draw_ctx);
118 anti_aliasing_ps_.sync(scene_state_, resources_);
123 resources_.material_buf.push_update();
128 switch (color_type) {
134 return scene_state_.material_override;
136 return scene_state_.material_attribute_color;
151 if (scene_state_.render_finished) {
155 Object *ob = ob_ref.object;
171 volume_ps_.object_sync_modifier(
manager, resources_, scene_state_, ob_ref, md);
175 is_object_data_visible =
false;
183 if (is_object_data_visible) {
191 emitter_handle = handle;
195 this->
mesh_sync(ob_ref, handle, object_state);
196 emitter_handle = handle;
205 if (scene_state_.shading.type !=
OB_WIRE) {
206 volume_ps_.object_sync_volume(
manager,
239 if (scene_state_.xray_mode || is_transparent) {
241 draw_callback(transparent_ps_.accumulation_in_front_ps_);
242 draw_callback(transparent_depth_ps_.in_front_ps_);
245 draw_callback(transparent_ps_.accumulation_ps_);
246 draw_callback(transparent_depth_ps_.main_ps_);
251 draw_callback(opaque_ps_.gbuffer_in_front_ps_);
254 draw_callback(opaque_ps_.gbuffer_ps_);
264 bool show_missing_texture =
false)
266 resources_.material_buf.append(material);
267 int material_index = resources_.material_buf.size() - 1;
269 if (show_missing_texture && (!
texture || !
texture->gpu.texture)) {
270 texture = &resources_.missing_texture;
274 mesh_pass.get_subpass(eGeometryType::MESH, texture).draw(batch, handle, material_index);
280 bool has_transparent_material =
false;
291 ob_ref.
object,
this->get_dummy_gpu_materials(material_count));
296 if (batches[
i] ==
nullptr) {
300 int material_slot =
i;
302 has_transparent_material = has_transparent_material || mat.is_transparent();
333 has_transparent_material = has_transparent_material || mat.is_transparent();
340 shadow_ps_.object_sync(scene_state_, ob_ref, handle, has_transparent_material);
358 mat.base_color =
batch.debug_color();
374 mat.base_color =
batch.debug_color();
387 resources_.material_buf.append(mat);
388 int material_index = resources_.material_buf.size() - 1;
391 PassMain::Sub &pass =
392 mesh_pass.get_subpass(eGeometryType::POINTCLOUD).sub(
"Point Cloud SubPass");
393 gpu::Batch *batch = pointcloud_sub_pass_setup(pass, ob_ref.object);
394 pass.draw(batch, handle, material_index);
413 resources_.material_buf.append(mat);
414 int material_index = resources_.material_buf.size() - 1;
417 PassMain::Sub &pass =
418 mesh_pass.get_subpass(eGeometryType::CURVES, &texture).sub(
"Hair SubPass");
419 pass.push_constant(
"emitter_object_id", int(emitter_handle.raw));
420 gpu::Batch *batch = hair_sub_pass_setup(pass, scene_state_.scene, ob_ref, psys, md);
421 pass.draw(batch, handle, material_index);
431 resources_.material_buf.append(mat);
432 int material_index = resources_.material_buf.size() - 1;
435 PassMain::Sub &pass = mesh_pass.get_subpass(eGeometryType::CURVES).sub(
"Curves SubPass");
436 gpu::Batch *batch = curves_sub_pass_setup(pass, scene_state_.scene, ob_ref.object);
437 pass.draw(batch, handle, material_index);
442 GPUTexture *depth_tx,
443 GPUTexture *depth_in_front_tx,
444 GPUTexture *color_tx)
446 int2 resolution = scene_state_.resolution;
450 bool needs_depth_in_front = !transparent_ps_.accumulation_in_front_ps_.is_empty() ||
451 (!opaque_ps_.gbuffer_in_front_ps_.is_empty() &&
452 scene_state_.sample == 0);
453 resources_.depth_in_front_tx.wrap(needs_depth_in_front ? depth_in_front_tx :
nullptr);
454 if (!needs_depth_in_front || opaque_ps_.gbuffer_in_front_ps_.is_empty()) {
456 resources_.clear_in_front_fb.bind();
460 resources_.depth_tx.wrap(depth_tx);
461 resources_.color_tx.wrap(color_tx);
463 if (scene_state_.render_finished) {
465 anti_aliasing_ps_.draw(
470 anti_aliasing_ps_.setup_view(view_, scene_state_);
473 if (scene_state_.draw_object_id) {
474 resources_.object_id_tx.acquire(
481 resources_.clear_fb.bind();
482 float4 clear_colors[2] = {scene_state_.background_color,
float4(0.0f)};
487 manager, view_, resources_, resolution, scene_state_.draw_shadows ? &shadow_ps_ :
nullptr);
488 transparent_ps_.draw(
manager, view_, resources_, resolution);
489 transparent_depth_ps_.draw(
manager, view_, resources_);
491 volume_ps_.draw(
manager, view_, resources_);
492 outline_ps_.draw(
manager, resources_);
493 dof_ps_.draw(
manager, view_, resources_, resolution);
494 anti_aliasing_ps_.draw(
draw_ctx,
manager, view_, scene_state_, resources_, depth_in_front_tx);
496 resources_.object_id_tx.release();
500 GPUTexture *depth_tx,
501 GPUTexture *depth_in_front_tx,
502 GPUTexture *color_tx)
504 this->
draw(
manager, depth_tx, depth_in_front_tx, color_tx);
506 if (scene_state_.sample + 1 < scene_state_.samples_len) {
516 if (
draw_ctx->is_viewport_image_render()) {
526 GPUTexture *depth_tx,
527 GPUTexture *depth_in_front_tx,
528 GPUTexture *color_tx,
531 if (scene_state_.render_finished) {
534 this->
draw(
manager, depth_tx, depth_in_front_tx, color_tx);
539 for (
auto i :
IndexRange(scene_state_.samples_len)) {
544 scene_state_.sample =
i;
546 resources_.init(scene_state_,
draw_ctx);
547 dof_ps_.init(scene_state_,
draw_ctx);
548 anti_aliasing_ps_.sync(scene_state_, resources_);
550 this->
draw(
manager, depth_tx, depth_in_front_tx, color_tx);
563 return new Instance();
568 ShaderCache::release();
577using namespace blender;
585 const int2 size = {int(viewport_size.
x), int(viewport_size.
y)};
591 if (dtxl->
color ==
nullptr) {
610 {GPU_ATTACHMENT_TEXTURE(dtxl->depth), GPU_ATTACHMENT_TEXTURE(dtxl->color)});
613 {GPU_ATTACHMENT_TEXTURE(dtxl->depth), GPU_ATTACHMENT_NONE});
616 {GPU_ATTACHMENT_NONE, GPU_ATTACHMENT_TEXTURE(dtxl->color)});
624 const char *viewname,
644 const char *viewname,
670 z = winmat[3][2] / (
z + winmat[2][2]);
678 float range =
fabsf(far - near);
685 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)
uint64_t DEG_get_update_count(const Depsgraph *depsgraph)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
@ eModifierType_ParticleSystem
#define RE_PASSNAME_COMBINED
@ 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)
eGPUBackendType GPU_backend_get_type()
void GPU_framebuffer_read_color(GPUFrameBuffer *fb, int x, int y, int width, int height, int channels, int slot, eGPUDataFormat data_format, void *r_data)
#define GPU_ATTACHMENT_TEXTURE(_texture)
bool GPU_framebuffer_check_valid(GPUFrameBuffer *fb, char err_out[256])
void GPU_framebuffer_clear_depth_stencil(GPUFrameBuffer *fb, float clear_depth, uint clear_stencil)
void GPU_framebuffer_read_depth(GPUFrameBuffer *fb, int x, int y, int width, int height, eGPUDataFormat data_format, void *r_data)
#define GPU_ATTACHMENT_NONE
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
void GPU_framebuffer_multi_clear(GPUFrameBuffer *fb, const float(*clear_colors)[4])
#define GPU_framebuffer_ensure_config(_fb,...)
GPUTexture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, eGPUTextureFormat format, eGPUTextureUsage usage, const float *data)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_ATTACHMENT
@ GPU_TEXTURE_USAGE_GENERAL
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)
ResourceHandleRange resource_handle(const ObjectRef &ref, float inflate_bounds=0.0f)
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 draw(Manager &manager) final
void draw(Manager &manager, GPUTexture *depth_tx, GPUTexture *depth_in_front_tx, GPUTexture *color_tx)
void draw_image_render(Manager &manager, GPUTexture *depth_tx, GPUTexture *depth_in_front_tx, GPUTexture *color_tx, RenderEngine *engine=nullptr)
Material get_material(ObjectRef ob_ref, eV3DShadingColorType color_type, int slot=0)
void object_sync(ObjectRef &ob_ref, Manager &manager) final
void draw_viewport(Manager &manager, GPUTexture *depth_tx, GPUTexture *depth_in_front_tx, GPUTexture *color_tx)
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 init(Depsgraph *depsgraph, Object *camera_ob=nullptr)
void draw_mesh(ObjectRef &ob_ref, Material &material, gpu::Batch *batch, ResourceHandle handle, const MaterialTexture *texture=nullptr, bool show_missing_texture=false)
void sculpt_sync(ObjectRef &ob_ref, ResourceHandle handle, const ObjectState &object_state)
void mesh_sync(ObjectRef &ob_ref, ResourceHandle handle, const ObjectState &object_state)
void pointcloud_sync(Manager &manager, ObjectRef &ob_ref, const ObjectState &object_state)
void hair_sync(Manager &manager, ObjectRef &ob_ref, ResourceHandle emitter_handle, const ObjectState &object_state, ParticleSystem *psys, ModifierData *md)
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 @242053044010324116347033273112253060004051364061::@051143074301336237271216303350234260141112266062 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_register_pass(RenderEngine *engine, Scene *scene, ViewLayer *view_layer, const char *name, int channels, const char *chanid, eNodeSocketDatatype type)
pbvh::Tree * pbvh_get(Object &object)
Bounds< float3 > bounds_get(const Tree &pbvh)
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)
T midpoint(const T &a, const T &b)
bool assign_if_different(T &old_value, T new_value)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 3 > float3
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
GPUFrameBuffer * depth_only_fb
GPUFrameBuffer * color_only_fb
GPUFrameBuffer * default_fb
GPUTexture * depth_in_front
struct FluidDomainSettings * domain
ImBufFloatBuffer float_buffer
const c_style_mat & ptr() const
static void free_static()
DrawEngine * create_instance() final
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, GPUFrameBuffer *fb, const rcti *rect, const float4x4 &winmat)
static void write_render_color_output(RenderLayer *layer, const char *viewname, GPUFrameBuffer *fb, const rcti *rect)