61 const float pixels[1][4] = {{1.0f, 0.0f, 1.0f, 1.0f}};
66 const float pixels[1] = {1.0f};
103 bool use_scene_lights =
false;
104 bool use_scene_world =
false;
131 use_scene_lights =
true;
132 use_scene_world =
true;
145 if (world !=
nullptr && use_scene_world) {
149 float world_light[3];
202 const bool is_fade_layer = ((!hide_overlay) && (!this->
is_render) &&
207 const bool is_fade_object = ((!hide_overlay) && (!this->
is_render) &&
269 Camera *cam = id_cast<Camera *>(
275 float fstop = cam->dof.aperture_fstop;
278 float focal_len = cam->lens;
280 const float scale_camera = 0.001f;
282 float aperture = 0.5f * scale_camera * focal_len / fstop;
283 float focal_len_scaled = scale_camera * focal_len;
284 float sensor_scaled = scale_camera * sensor;
290 this->
dof_params[1] = aperture *
fabsf(focal_len_scaled / (focus_dist - focal_len_scaled));
291 this->
dof_params[1] *= vp_size[0] / sensor_scaled;
300#define DISABLE_BATCHING 0
302bool Instance::is_used_as_layer_mask_in_viewlayer(
const GreasePencil &
grease_pencil,
303 const bke::greasepencil::Layer &mask_layer,
304 const ViewLayer &view_layer)
306 using namespace bke::greasepencil;
308 if (
layer->view_layer_name().is_empty() ||
318 for (GreasePencilLayerMask &
mask :
layer->masks) {
319 if (
STREQ(
mask.layer_name, mask_layer.name().c_str())) {
327bool Instance::use_layer_in_render(
const GreasePencil &grease_pencil,
328 const bke::greasepencil::Layer &
layer,
329 const ViewLayer &view_layer,
330 bool &r_is_used_as_mask)
332 if (!
layer.view_layer_name().is_empty() &&
337 if (is_used_as_layer_mask_in_viewlayer(grease_pencil,
layer,
view_layer)) {
338 r_is_used_as_mask =
true;
347tObject *Instance::object_sync_do(Object *ob, ResourceHandleRange res_handle)
349 using namespace ed::greasepencil;
350 using namespace bke::greasepencil;
353 const Bounds<float3> bounds = grease_pencil.bounds_min_max_eval().value_or(
Bounds(
float3(0)));
367 gpu::Texture *tex_fill = this->
dummy_tx;
368 gpu::Texture *tex_stroke = this->
dummy_tx;
370 gpu::Batch *iter_geom =
nullptr;
375 const auto drawcall_flush = [&](
PassSimple &pass) {
377 if (iter_geom !=
nullptr) {
378 pass.draw(iter_geom, 1, vcount, vfirst, res_handle);
386 const auto drawcall_add =
387 [&](
PassSimple &pass, gpu::Batch *draw_geom,
const int v_first,
const int v_count) {
389 pass.draw(iter_geom, 1, vcount, vfirst, res_handle);
392 int last = vfirst + vcount;
394 if ((draw_geom != iter_geom) || (v_first - last > 0)) {
395 drawcall_flush(pass);
397 iter_geom = draw_geom;
401 vcount = v_first + v_count - vfirst;
408 *this->
scene, grease_pencil,
true);
409 const Span<const Layer *> layers = grease_pencil.layers();
410 for (
const DrawingInfo
info : drawings) {
413 const std::optional<GroupedSpan<int3>> triangles =
info.drawing.triangles();
414 const bke::CurvesGeometry &curves =
info.drawing.strokes();
415 const OffsetIndices<int> points_by_curve = curves.evaluated_points_by_curve();
416 const bke::AttributeAccessor attributes = curves.attributes();
417 const VArray<bool> cyclic = *attributes.lookup_or_default<
bool>(
420 IndexMaskMemory memory;
422 *ob,
info.drawing, memory);
424 *ob,
info.drawing, memory);
425 const std::optional<GroupedSpan<int>> fills =
info.drawing.fills();
426 const int num_fills = fills.has_value() ? fills->size() : 0;
431 Array<int> num_triangles_per_fill(num_fills);
432 Array<int> num_vertices_per_curve(curves.curves_num());
433 int total_num_triangles = 0;
434 int total_num_vertices = 0;
436 visible_fills.foreach_index([&](
const int fill_index) {
437 const int num_stroke_triangles = (*triangles)[fill_index].size();
438 num_triangles_per_fill[fill_index] = num_stroke_triangles;
439 total_num_triangles += num_stroke_triangles;
443 visible_strokes.foreach_index([&](
const int curve_i) {
444 const IndexRange points = points_by_curve[curve_i];
445 const int num_stroke_vertices = (points.size() +
446 int(cyclic[curve_i] && (points.size() >= 3)));
447 num_vertices_per_curve[curve_i] = num_stroke_vertices;
448 total_num_vertices += num_stroke_vertices;
451 bool is_layer_used_as_mask =
false;
452 const bool show_drawing_in_render = use_layer_in_render(
454 if (!show_drawing_in_render) {
456 t_offset += total_num_triangles;
457 t_offset += total_num_vertices * 2;
462 drawcall_flush(*last_pass);
466 this, ob,
layer,
info.onion_id, is_layer_used_as_mask, tgp_ob);
477 gpu::UniformBuf *ubo_mat;
480 pass.bind_ubo(
"gp_lights", lights_ubo);
481 pass.bind_ubo(
"gp_materials", ubo_mat);
482 pass.bind_texture(
"gp_fill_tx", tex_fill);
483 pass.bind_texture(
"gp_stroke_tx", tex_stroke);
484 pass.push_constant(
"gp_material_offset", mat_ofs);
486 pass.push_constant(
"gp_stroke_index_offset", 0.0f);
489 const VArray<int> stroke_materials = *attributes.lookup_or_default<
int>(
491 const VArray<bool> is_fill_guide = *attributes.lookup_or_default<
bool>(
494 const VArray<bool> hide_stroke = *attributes.lookup_or_default<
bool>(
496 const VArray<int> fill_ids = *attributes.lookup_or_default<
int>(
499 const bool only_lines = !
ELEM(ob->mode,
505 const bool is_onion =
info.onion_id != 0;
509 Array<int> fill_index_by_curves(curves.curves_num(), -1);
510 Array<int> first_curves(curves.curves_num());
513 for (
const int curve_i : curves.curves_range()) {
514 const bool is_filled = fill_ids[curve_i] != 0;
515 const bool active_filled = is_filled && (fill_index_by_curves[curve_i] == -1);
519 const Span<int>
fill = (*fills)[fill_index];
520 const int first_curve =
fill.first();
521 for (
const int pos :
fill.index_range()) {
522 const int curve_i =
fill[pos];
523 fill_index_by_curves[curve_i] = fill_index;
524 first_curves[curve_i] = first_curve;
531 visible_strokes.foreach_index([&](
const int curve_i) {
533 const int fill_index = fill_index_by_curves[curve_i];
535 const bool is_filled = fill_index != -1;
536 const bool active_filled = is_filled && (first_curves[curve_i] == curve_i);
541 const int material_index = std::max(stroke_materials[curve_i], 0);
544 const bool is_fill_guide_stroke = is_fill_guide[curve_i];
546 const bool has_triangles = active_filled && triangles && !triangles->is_empty() &&
547 !(*triangles)[fill_index].is_empty();
550 const bool show_stroke = !hide_stroke[curve_i] || is_fill_guide_stroke;
551 const bool show_fill = (has_triangles) && active_filled && (!this->
simplify_fill) &&
552 !is_fill_guide_stroke;
555 const bool skip_stroke = hide_material || (!show_stroke && !show_fill) ||
556 (only_lines && !
do_onion && is_onion) || hide_onion;
560 t_offset += num_triangles_per_fill[fill_index];
562 t_offset += num_vertices_per_curve[curve_i] * 2;
567 gpu::UniformBuf *new_ubo_mat;
568 gpu::Texture *new_tex_fill =
nullptr;
569 gpu::Texture *new_tex_stroke =
nullptr;
571 matpool, mat_ofs + material_index, &new_tex_stroke, &new_tex_fill, &new_ubo_mat);
573 const bool resource_changed = (ubo_mat != new_ubo_mat) ||
574 (new_tex_fill && (new_tex_fill != tex_fill)) ||
575 (new_tex_stroke && (new_tex_stroke != tex_stroke));
577 if (resource_changed) {
578 drawcall_flush(pass);
580 if (new_ubo_mat != ubo_mat) {
581 pass.bind_ubo(
"gp_materials", new_ubo_mat);
582 ubo_mat = new_ubo_mat;
585 pass.bind_texture(
"gp_fill_tx", new_tex_fill);
586 tex_fill = new_tex_fill;
588 if (new_tex_stroke) {
589 pass.bind_texture(
"gp_stroke_tx", new_tex_stroke);
590 tex_stroke = new_tex_stroke;
595 if (iter_geom != geom) {
596 drawcall_flush(pass);
600 pass.bind_texture(
"gp_pos_tx", position_tx);
601 pass.bind_texture(
"gp_col_tx",
color_tx);
605 const int v_first = t_offset * 3;
606 const int v_count = num_triangles_per_fill[fill_index] * 3;
607 drawcall_add(pass, geom, v_first, v_count);
611 t_offset += num_triangles_per_fill[fill_index];
615 const int v_first = t_offset * 3;
616 const int v_count = num_vertices_per_curve[curve_i] * 2 * 3;
617 drawcall_add(pass, geom, v_first, v_count);
620 t_offset += num_vertices_per_curve[curve_i] * 2;
625 drawcall_flush(*last_pass);
643 tObject *tgp_ob = object_sync_do(ob, res_handle);
644 vfx_sync(ob, tgp_ob);
672 if (this->
tobjects.first ==
nullptr) {
680 gpu::TextureFormat::SFLOAT_16_16_16_16 :
681 gpu::TextureFormat::UNORM_10_10_10_2;
684 this->color_tx.acquire_2d(size, format_color);
712 gpu::TextureFormat::UNORM_8;
736 grease_pencil_pass.
acquire_2d(size, gpu::TextureFormat::SFLOAT_16_16_16_16);
749 this->color_tx.release();
769 bool cleared =
false;
795 if (mask_layer ==
nullptr) {
799 manager->
submit(*mask_layer->geom_ps, view);
810void Instance::draw_object(View &view,
tObject *ob)
814 const std::array<double4, 2> clear_cols = {
double4{0, 0, 0, 0},
double4{1, 1, 1, 1}};
828 if (
layer->mask_bits) {
829 draw_mask(view, ob,
layer);
832 if (
layer->blend_ps) {
840 manager->submit(*
layer->geom_ps, view);
842 if (
layer->blend_ps) {
844 manager->submit(*
layer->blend_ps);
848 for (tVfx *vfx = ob->vfx.first; vfx; vfx = vfx->next) {
850 manager->submit(*vfx->vfx_ps);
883 std::array<double4, 2> clear_cols = {
double4{0.0f, 0.0f, 0.0f, 0.0f},
884 double4{1.0f, 1.0f, 1.0f, 1.0f}};
896 clear_cols[0] =
double4(background_color, 0.0f);
903 if (this->
tobjects.first ==
nullptr) {
921 draw_object(view, ob);
925 antialiasing_draw(manager);
Camera data-block and utility functions.
Low-level operations for curves.
Low-level operations for grease pencil.
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
#define BLI_BITMAP_TEST(_bitmap, _index)
#define BLI_BITMAP_TEST_BOOL(_bitmap, _index)
#define RE_PASSNAME_COMBINED
#define RE_PASSNAME_DEPTH
#define RE_PASSNAME_GREASE_PENCIL
#define V3D_USES_SCENE_WORLD(v3d)
#define V3D_USES_SCENE_LIGHTS(v3d)
#define XRAY_ENABLED(v3d)
#define GPU_ATTACHMENT_TEXTURE(_texture)
#define GPU_ATTACHMENT_NONE
bool contains(const Key &key) const
void ensure(GPUAttachment depth=GPU_ATTACHMENT_NONE, GPUAttachment color1=GPU_ATTACHMENT_NONE, GPUAttachment color2=GPU_ATTACHMENT_NONE, GPUAttachment color3=GPU_ATTACHMENT_NONE, GPUAttachment color4=GPU_ATTACHMENT_NONE, GPUAttachment color5=GPU_ATTACHMENT_NONE, GPUAttachment color6=GPU_ATTACHMENT_NONE, GPUAttachment color7=GPU_ATTACHMENT_NONE, GPUAttachment color8=GPU_ATTACHMENT_NONE)
ResourceHandleRange unique_handle(const ObjectRef &ref)
void submit(PassSimple &pass, View &view)
bool acquire_2d(int2 extent, gpu::TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, int mip_len=1)
bool ensure_2d(gpu::TextureFormat format, int2 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
gpu::Texture * gpu_texture()
static View & default_get()
const float4x4 & viewinv(int view_id=0) const
void draw_procedural(GPUPrimType primitive, uint instance_len, uint vertex_len, uint vertex_first=-1, ResourceIDRange res_id={}, uint custom_id=0)
void shader_set(gpu::Shader *shader)
void bind_texture(const char *name, gpu::Texture *texture, GPUSamplerState state=sampler_auto)
void bind_image(const char *name, gpu::Texture *image)
void state_set(DRWState state, int clip_plane_count=0)
void push_constant(const char *name, const float &data)
static ShaderCache & get()
#define GPENCIL_SIMPLIFY_AA(scene)
#define GPENCIL_SIMPLIFY_FILL(scene, playing)
#define GPENCIL_SIMPLIFY_FX(scene, playing)
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
ccl_device_inline float3x3 inverted(const float3x3 m)
void fill_index_range(MutableSpan< T > span, const T start=0)
Set< std::string > get_used_passes(const Scene &scene, const ViewLayer *view_layer, ExecutionMode mode)
void gpencil_light_ambient_add(LightPool *lightpool, const float color[3])
void gpencil_object_cache_sort(Instance *inst)
void gpencil_light_pool_populate(LightPool *lightpool, Object *ob)
LightPool * gpencil_light_pool_add(Instance *inst)
tLayer * grease_pencil_layer_cache_add(Instance *inst, const Object *ob, const bke::greasepencil::Layer &layer, const int onion_id, const bool is_used_as_mask, tObject *tgp_ob)
void gpencil_material_resources_get(MaterialPool *first_pool, int mat_id, gpu::Texture **r_tex_stroke, gpu::Texture **r_tex_fill, gpu::UniformBuf **r_ubo_mat)
tLayer * grease_pencil_layer_cache_get(tObject *tgp_ob, int layer_id, const bool skip_onion)
MaterialPool * gpencil_material_pool_create(Instance *inst, Object *ob, int *ofs, const bool is_vertex_mode)
tObject * gpencil_object_cache_add(Instance *inst, Object *ob, const bool is_stroke_order_3d, const Bounds< float3 > bounds)
gpu::Batch * DRW_cache_grease_pencil_get(const Scene *scene, Object *ob)
detail::Pass< command::DrawCommandBuf > PassSimple
gpu::VertBuf * DRW_cache_grease_pencil_position_buffer_get(const Scene *scene, Object *ob)
gpu::VertBuf * DRW_cache_grease_pencil_color_buffer_get(const Scene *scene, Object *ob)
Vector< DrawingInfo > retrieve_visible_drawings(const Scene &scene, const GreasePencil &grease_pencil, const bool do_onion_skinning)
IndexMask retrieve_visible_strokes(Object &object, const bke::greasepencil::Drawing &drawing, IndexMaskMemory &memory)
IndexMask retrieve_visible_fills(Object &object, const bke::greasepencil::Drawing &drawing, IndexMaskMemory &memory)
BLI_NOINLINE void fill(T *__restrict data, const T &value, const IndexMask &mask)
T interpolate(const T &a, const T &b, const FactorT &t)
void GPU_framebuffer_bind(gpu::FrameBuffer *fb)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
@ GP_LAYER_TREE_NODE_USE_LIGHTS
@ GP_LAYER_TREE_NODE_DISABLE_MASKS_IN_VIEWLAYER
draw::TextureFromPool & DRW_viewport_pass_texture_get(const char *pass_name)
void ED_view3d_background_color_get(const Scene *scene, const View3D *v3d, float r_color[3])
MINLINE void copy_v3_v3(float r[3], const float a[3])
void BLI_memblock_clear(BLI_memblock *mblk, MemblockValFreeFP free_callback) ATTR_NONNULL(1)
void GPU_framebuffer_clear_depth_stencil(gpu::FrameBuffer *fb, float clear_depth, uint clear_stencil)
MatBase< float, 4, 4 > float4x4
int DRW_object_visibility_in_active_context(const Object *ob)
@ GP_MATERIAL_HIDE_ONIONSKIN
VecBase< float, 4 > float4
MaterialGPencilStyle * BKE_gpencil_material_settings(Object *ob, short act)
float BKE_camera_object_dof_distance(const struct Object *ob)
@ GREASE_PENCIL_STROKE_ORDER_3D
@ GP_USE_MULTI_FRAME_EDITING
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
@ GPU_TEXTURE_USAGE_SHADER_READ
T & DRW_object_get_data_for_drawing(const Object &object)
@ OB_MODE_VERTEX_GREASE_PENCIL
@ OB_MODE_WEIGHT_GREASE_PENCIL
@ OB_MODE_PAINT_GREASE_PENCIL
wmWindowManager * CTX_wm_manager(const bContext *C)
@ V3D_GP_ONION_SKIN_ACTIVE_OBJECT
@ V3D_GP_FADE_NOACTIVE_LAYERS
@ V3D_GP_FORCE_STROKE_ORDER_3D
@ V3D_GP_SHOW_MULTIEDIT_LINES
@ V3D_GP_FADE_NOACTIVE_GPENCIL
void DRW_submission_end()
const DRWContext * DRW_context_get()
@ V3D_SHADING_VERTEX_COLOR
void BLI_memblock_iternew(BLI_memblock *mblk, BLI_memblock_iter *iter) ATTR_NONNULL()
void * BLI_memblock_iterstep(BLI_memblock_iter *iter) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
void GPU_uniformbuf_update(gpu::UniformBuf *ubo, const void *data)
void GPU_debug_group_end()
void GPU_framebuffer_multi_clear(gpu::FrameBuffer *fb, Span< double4 > clear_colors)
float BKE_camera_sensor_size(int sensor_fit, float sensor_x, float sensor_y)
MINLINE void copy_v3_fl(float r[3], float f)
void DRW_submission_start()
draw::Manager * DRW_manager_get()
VecBase< float, 3 > float3
bool DRW_viewport_pass_texture_exists(const char *pass_name)
void GPU_framebuffer_clear_color_depth(gpu::FrameBuffer *fb, const double4 clear_col, float clear_depth)
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
float DEG_get_ctime(const Depsgraph *graph)
VecBase< double, 4 > double4
bScreen * ED_screen_animation_playing(const wmWindowManager *wm)
void GPU_debug_group_begin(const char *name)
DefaultTextureList * viewport_texture_list_get() const
float2 viewport_size_get() const
DefaultFramebufferList * viewport_framebuffer_list_get() const
bool is_viewport_compositor_used() const
gpu::FrameBuffer * default_fb
eRegionView3D_Persp persp
struct ToolSettings * toolsettings
float gpencil_paper_opacity
float gpencil_vertex_paint_opacity
eV3DShadingColorType color_type
float studiolight_intensity
static void free_static()
DrawEngine * create_instance() final
TextureFromPool smaa_edge_tx
bool do_onion_only_active_object
LightPool * shadeless_light_pool
Framebuffer gpencil_pass_fb
Framebuffer combined_pass_fb
bool need_grease_pencil_pass
gpu::Batch * stroke_batch
LightPool * last_light_pool
Texture snapshot_depth_tx
PassSimple merge_depth_pass_ps
struct BLI_memblock * gp_object_pool
gpu::Texture * depth_pass_img
TextureFromPool color_object_tx
tLayer_Pool * gp_layer_pool
float vertex_paint_opacity
TextureFromPool mask_color_tx
struct blender::draw::gpencil::Instance::@250045130013031054234100054276160145124267353263 tobjects_infront
struct ViewLayer * view_layer
float fade_3d_object_opacity
bool force_stroke_order_3d
gpu::FrameBuffer * scene_fb
struct BLI_memblock * gp_material_pool
const DRWContext * draw_ctx
PassSimple mask_invert_ps
float fade_gp_object_opacity
TextureFromPool mask_depth_tx
bool use_multiedit_lines_only
Texture snapshot_reveal_tx
TextureFromPool color_layer_tx
void draw(Manager &manager) final
float4x4 object_bound_mat
MaterialPool * last_material_pool
float v3d_single_color[3]
Texture snapshot_color_tx
void object_sync(ObjectRef &ob_ref, Manager &manager) final
TextureFromPool reveal_layer_tx
struct blender::draw::gpencil::Instance::@250045130013031054234100054276160145124267353263 tobjects
TextureFromPool reveal_tx
TextureFromPool reveal_object_tx
gpu::Texture * scene_depth_tx
LightPool * global_light_pool
TextureFromPool smaa_weight_tx
PassSimple merge_depth_ps
struct BLI_memblock * gp_maskbit_pool
struct BLI_memblock * gp_light_pool
struct blender::draw::gpencil::Instance::@270103242060374244001011226234131367140002277206 sbuffer_tobjects
gpLight light_data[GPENCIL_LIGHT_BUFFER_LEN]
gpMaterial mat_data[GPENCIL_MATERIAL_BUFFER_LEN]