62 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;
126 const bool shmode_xray_support =
v3d->shading.type <=
OB_SOLID;
131 use_scene_lights =
true;
132 use_scene_world =
true;
145 if (world !=
nullptr && use_scene_world) {
149 float world_light[3];
195 const bool is_fade_layer = ((!hide_overlay) && (!this->
is_render) &&
200 const bool is_fade_object = ((!hide_overlay) && (!this->
is_render) &&
204 draw_ctx->v3d->overlay.gpencil_paper_opacity :
208 draw_ctx->v3d->overlay.gpencil_paper_opacity :
272 float fstop = cam->dof.aperture_fstop;
275 float focal_len = cam->lens;
277 const float scale_camera = 0.001f;
279 float aperture = 0.5f * scale_camera * focal_len / fstop;
280 float focal_len_scaled = scale_camera * focal_len;
281 float sensor_scaled = scale_camera * sensor;
284 sensor_scaled *=
draw_ctx->rv3d->viewcamtexcofac[0];
287 this->
dof_params[1] = aperture *
fabsf(focal_len_scaled / (focus_dist - focal_len_scaled));
288 this->
dof_params[1] *= vp_size[0] / sensor_scaled;
297#define DISABLE_BATCHING 0
299bool Instance::is_used_as_layer_mask_in_viewlayer(
const GreasePencil &grease_pencil,
300 const bke::greasepencil::Layer &mask_layer,
303 using namespace bke::greasepencil;
304 for (
const Layer *layer : grease_pencil.layers()) {
305 if (layer->view_layer_name().is_empty() ||
316 if (
STREQ(
mask->layer_name, mask_layer.name().c_str())) {
324bool Instance::use_layer_in_render(
const GreasePencil &grease_pencil,
325 const bke::greasepencil::Layer &layer,
327 bool &r_is_used_as_mask)
329 if (!layer.view_layer_name().is_empty() &&
334 if (is_used_as_layer_mask_in_viewlayer(grease_pencil, layer,
view_layer)) {
335 r_is_used_as_mask =
true;
344tObject *Instance::object_sync_do(
Object *ob, ResourceHandle res_handle)
346 using namespace ed::greasepencil;
347 using namespace bke::greasepencil;
350 const Bounds<float3> bounds = grease_pencil.bounds_min_max_eval().value_or(Bounds(
float3(0)));
354 const bool do_multi_frame = (((this->
scene->toolsettings->gpencil_flags &
364 GPUTexture *tex_fill = this->
dummy_tx;
365 GPUTexture *tex_stroke = this->
dummy_tx;
367 gpu::Batch *iter_geom =
nullptr;
372 const auto drawcall_flush = [&](
PassSimple &pass) {
374 if (iter_geom !=
nullptr) {
375 pass.draw(iter_geom, 1, vcount, vfirst, res_handle);
383 const auto drawcall_add =
384 [&](
PassSimple &pass, gpu::Batch *draw_geom,
const int v_first,
const int v_count) {
386 pass.draw(iter_geom, 1, vcount, vfirst, res_handle);
389 int last = vfirst + vcount;
391 if ((draw_geom != iter_geom) || (v_first -
last > 0)) {
392 drawcall_flush(pass);
394 iter_geom = draw_geom;
398 vcount = v_first + v_count - vfirst;
405 *this->
scene, grease_pencil,
true);
406 const Span<const Layer *> layers = grease_pencil.layers();
407 for (
const DrawingInfo
info : drawings) {
408 const Layer &layer = *layers[
info.layer_index];
410 const bke::CurvesGeometry &curves =
info.drawing.strokes();
411 const OffsetIndices<int> points_by_curve = curves.evaluated_points_by_curve();
412 const bke::AttributeAccessor attributes = curves.attributes();
413 const VArray<bool> cyclic = *attributes.lookup_or_default<
bool>(
416 IndexMaskMemory memory;
418 *ob,
info.drawing, memory);
423 Array<int> num_triangles_per_stroke(visible_strokes.
size());
424 Array<int> num_vertices_per_stroke(visible_strokes.
size());
425 int total_num_triangles = 0;
426 int total_num_vertices = 0;
428 const IndexRange points = points_by_curve[stroke_i];
429 const int num_stroke_triangles = (points.
size() >= 3) ? (points.
size() - 2) : 0;
430 const int num_stroke_vertices = (points.
size() +
431 int(cyclic[stroke_i] && (points.
size() >= 3)));
432 num_triangles_per_stroke[
pos] = num_stroke_triangles;
433 num_vertices_per_stroke[
pos] = num_stroke_vertices;
434 total_num_triangles += num_stroke_triangles;
435 total_num_vertices += num_stroke_vertices;
438 bool is_layer_used_as_mask =
false;
439 const bool show_drawing_in_render = use_layer_in_render(
440 grease_pencil, layer, *this->
view_layer, is_layer_used_as_mask);
441 if (!show_drawing_in_render) {
443 t_offset += total_num_triangles;
444 t_offset += total_num_vertices * 2;
449 drawcall_flush(*last_pass);
453 this, ob, layer,
info.onion_id, is_layer_used_as_mask, tgp_ob);
464 GPUUniformBuf *ubo_mat;
467 pass.bind_ubo(
"gp_lights", lights_ubo);
468 pass.bind_ubo(
"gp_materials", ubo_mat);
469 pass.bind_texture(
"gp_fill_tx", tex_fill);
470 pass.bind_texture(
"gp_stroke_tx", tex_stroke);
471 pass.push_constant(
"gp_material_offset", mat_ofs);
473 pass.push_constant(
"gp_stroke_index_offset", 0.0f);
474 pass.push_constant(
"viewport_size",
float2(
draw_ctx->viewport_size_get()));
476 const VArray<int> stroke_materials = *attributes.lookup_or_default<
int>(
478 const VArray<bool> is_fill_guide = *attributes.lookup_or_default<
bool>(
481 const bool only_lines = !
ELEM(ob->
mode,
487 const bool is_onion =
info.onion_id != 0;
490 const IndexRange points = points_by_curve[stroke_i];
494 const int material_index = std::max(stroke_materials[stroke_i], 0);
497 const bool is_fill_guide_stroke = is_fill_guide[stroke_i];
501 is_fill_guide_stroke;
502 const bool show_fill = (points.
size() >= 3) &&
507 const bool skip_stroke = hide_material || (!show_stroke && !show_fill) ||
508 (only_lines && !
do_onion && is_onion) || hide_onion;
511 t_offset += num_triangles_per_stroke[
pos];
512 t_offset += num_vertices_per_stroke[
pos] * 2;
516 GPUUniformBuf *new_ubo_mat;
517 GPUTexture *new_tex_fill =
nullptr;
518 GPUTexture *new_tex_stroke =
nullptr;
520 matpool, mat_ofs + material_index, &new_tex_stroke, &new_tex_fill, &new_ubo_mat);
522 const bool resource_changed = (ubo_mat != new_ubo_mat) ||
523 (new_tex_fill && (new_tex_fill != tex_fill)) ||
524 (new_tex_stroke && (new_tex_stroke != tex_stroke));
526 if (resource_changed) {
527 drawcall_flush(pass);
529 if (new_ubo_mat != ubo_mat) {
530 pass.bind_ubo(
"gp_materials", new_ubo_mat);
531 ubo_mat = new_ubo_mat;
534 pass.bind_texture(
"gp_fill_tx", new_tex_fill);
535 tex_fill = new_tex_fill;
537 if (new_tex_stroke) {
538 pass.bind_texture(
"gp_stroke_tx", new_tex_stroke);
539 tex_stroke = new_tex_stroke;
544 if (iter_geom != geom) {
545 drawcall_flush(pass);
549 pass.bind_texture(
"gp_pos_tx", position_tx);
550 pass.bind_texture(
"gp_col_tx",
color_tx);
554 const int v_first = t_offset * 3;
555 const int v_count = num_triangles_per_stroke[
pos] * 3;
556 drawcall_add(pass, geom, v_first, v_count);
559 t_offset += num_triangles_per_stroke[
pos];
562 const int v_first = t_offset * 3;
563 const int v_count = num_vertices_per_stroke[
pos] * 2 * 3;
564 drawcall_add(pass, geom, v_first, v_count);
567 t_offset += num_vertices_per_stroke[
pos] * 2;
572 drawcall_flush(*last_pass);
590 tObject *tgp_ob = object_sync_do(ob, res_handle);
591 vfx_sync(ob, tgp_ob);
619 if (this->
tobjects.first ==
nullptr) {
629 this->color_tx.acquire(
size, format_color);
672 this->color_tx.release();
689 const float clear_col[4] = {1.0f, 1.0f, 1.0f, 1.0f};
691 bool inverted =
false;
694 bool cleared =
false;
709 inverted = !inverted;
719 if (mask_layer ==
nullptr) {
738 const float clear_cols[2][4] = {{0.0f, 0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}};
753 draw_mask(
view, ob, layer);
774 manager->submit(*vfx->vfx_ps);
788void Instance::fast_draw_start()
790 DefaultFramebufferList *dfbl = this->
draw_ctx->viewport_framebuffer_list_get();
802void Instance::fast_draw_end(
View &
view)
804 DefaultFramebufferList *dfbl = this->
draw_ctx->viewport_framebuffer_list_get();
815 draw_object(
view, ob);
834 float clear_cols[2][4] = {{0.0f, 0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}};
840 float background_color[3];
851 if (this->
tobjects.first ==
nullptr) {
873 draw_object(
view, ob);
881 antialiasing_draw(manager);
Camera data-block and utility functions.
float BKE_camera_sensor_size(int sensor_fit, float sensor_x, float sensor_y)
float BKE_camera_object_dof_distance(const struct Object *ob)
wmWindowManager * CTX_wm_manager(const bContext *C)
Low-level operations for curves.
#define GPENCIL_SIMPLIFY_AA(scene)
#define GPENCIL_SIMPLIFY_FILL(scene, playing)
#define GPENCIL_SIMPLIFY_FX(scene, playing)
Low-level operations for grease pencil.
General operations, lookup, etc. for materials.
MaterialGPencilStyle * BKE_gpencil_material_settings(Object *ob, short act)
General operations, lookup, etc. for blender objects.
#define BLI_BITMAP_TEST(_bitmap, _index)
#define BLI_BITMAP_TEST_BOOL(_bitmap, _index)
#define LISTBASE_FOREACH(type, var, list)
MINLINE void mul_v4_fl(float r[4], float f)
MINLINE void copy_v3_v3(float r[3], const float a[3])
MINLINE float dot_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
MINLINE void copy_v3_fl(float r[3], float f)
void BLI_memblock_iternew(BLI_memblock *mblk, BLI_memblock_iter *iter) ATTR_NONNULL()
void BLI_memblock_clear(BLI_memblock *mblk, MemblockValFreeFP free_callback) ATTR_NONNULL(1)
void * BLI_memblock_iterstep(BLI_memblock_iter *iter) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
float DEG_get_ctime(const Depsgraph *graph)
struct GreasePencil GreasePencil
@ GP_LAYER_TREE_NODE_USE_LIGHTS
@ GP_LAYER_TREE_NODE_DISABLE_MASKS_IN_VIEWLAYER
@ GREASE_PENCIL_STROKE_ORDER_3D
struct ViewLayer ViewLayer
struct MaterialGPencilStyle MaterialGPencilStyle
@ GP_MATERIAL_HIDE_ONIONSKIN
@ GP_MATERIAL_STROKE_SHOW
@ OB_MODE_VERTEX_GREASE_PENCIL
@ OB_MODE_PAINT_GREASE_PENCIL
@ OB_MODE_WEIGHT_GREASE_PENCIL
@ GP_USE_MULTI_FRAME_EDITING
@ V3D_SHADING_VERTEX_COLOR
#define V3D_USES_SCENE_WORLD(v3d)
@ V3D_GP_FORCE_STROKE_ORDER_3D
@ V3D_GP_SHOW_MULTIEDIT_LINES
@ V3D_GP_ONION_SKIN_ACTIVE_OBJECT
@ V3D_GP_FADE_NOACTIVE_GPENCIL
@ V3D_GP_FADE_NOACTIVE_LAYERS
#define V3D_USES_SCENE_LIGHTS(v3d)
void DRW_submission_end()
void DRW_submission_start()
bScreen * ED_screen_animation_playing(const wmWindowManager *wm)
#define XRAY_ENABLED(v3d)
void ED_view3d_background_color_get(const Scene *scene, const View3D *v3d, float r_color[3])
static void View(GHOST_IWindow *window, bool stereo, int eye=0)
void GPU_debug_group_end()
void GPU_debug_group_begin(const char *name)
#define GPU_ATTACHMENT_TEXTURE(_texture)
void GPU_framebuffer_clear_depth_stencil(GPUFrameBuffer *fb, float clear_depth, uint clear_stencil)
void GPU_framebuffer_clear_color_depth(GPUFrameBuffer *fb, const float clear_col[4], float clear_depth)
void GPU_framebuffer_bind(GPUFrameBuffer *fb)
void GPU_framebuffer_multi_clear(GPUFrameBuffer *fb, const float(*clear_colors)[4])
void GPU_framebuffer_blit(GPUFrameBuffer *fb_read, int read_slot, GPUFrameBuffer *fb_write, int write_slot, eGPUFrameBufferBits blit_buffers)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_ATTACHMENT
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void foreach_index(Fn &&fn) const
constexpr int64_t size() const
ResourceHandleRange unique_handle(const ObjectRef &ref)
void submit(PassSimple &pass, View &view)
static View & default_get()
const float4x4 & viewinv(int view_id=0) const
void bind_texture(const char *name, GPUTexture *texture, GPUSamplerState state=sampler_auto)
void state_set(DRWState state, int clip_plane_count=0)
void push_constant(const char *name, const float &data)
void draw_procedural(GPUPrimType primitive, uint instance_len, uint vertex_len, uint vertex_first=-1, ResourceHandleRange handle={0}, uint custom_id=0)
void shader_set(GPUShader *shader)
static ShaderCache & get()
const DRWContext * DRW_context_get()
int DRW_object_visibility_in_active_context(const Object *ob)
Mesh & DRW_object_get_data_for_drawing(const Object &object)
blender::draw::Manager * DRW_manager_get()
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
void gpencil_light_ambient_add(LightPool *lightpool, const float color[3])
void gpencil_object_cache_sort(Instance *inst)
void gpencil_material_resources_get(MaterialPool *first_pool, int mat_id, GPUTexture **r_tex_stroke, GPUTexture **r_tex_fill, GPUUniformBuf **r_ubo_mat)
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)
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)
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< float, 3 > float3
GPUFrameBuffer * default_fb
GreasePencilLayerTreeNode base
static void free_static()
DrawEngine * create_instance() final
TextureFromPool smaa_edge_tx
bool do_onion_only_active_object
bool snapshot_buffer_dirty
LightPool * shadeless_light_pool
gpu::Batch * stroke_batch
LightPool * last_light_pool
GPUTexture * scene_depth_tx
struct blender::draw::gpencil::Instance::@025011325033111341345356265074201047356331240361 tobjects
Texture snapshot_depth_tx
struct BLI_memblock * gp_object_pool
TextureFromPool color_object_tx
GPUFrameBuffer * scene_fb
tLayer_Pool * gp_layer_pool
float vertex_paint_opacity
struct blender::draw::gpencil::Instance::@025011325033111341345356265074201047356331240361 tobjects_infront
struct blender::draw::gpencil::Instance::@013145054127325216201074046145305236152130364027 sbuffer_tobjects
TextureFromPool mask_color_tx
struct ViewLayer * view_layer
float fade_3d_object_opacity
bool force_stroke_order_3d
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
TextureFromPool reveal_tx
TextureFromPool reveal_object_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 GPUUniformBuf * ubo
gpLight light_data[GPENCIL_LIGHT_BUFFER_LEN]
gpMaterial mat_data[GPENCIL_MATERIAL_BUFFER_LEN]
struct GPUUniformBuf * ubo
std::unique_ptr< PassSimple > geom_ps
BLI_bitmap * mask_invert_bits
std::unique_ptr< PassSimple > blend_ps