62 const float pixels[1][4] = {{1.0f, 0.0f, 1.0f, 1.0f}};
67 const float pixels[1] = {1.0f};
104 bool use_scene_lights =
false;
105 bool use_scene_world =
false;
127 const bool shmode_xray_support =
v3d->shading.type <=
OB_SOLID;
132 use_scene_lights =
true;
133 use_scene_world =
true;
146 if (world !=
nullptr && use_scene_world) {
150 float world_light[3];
176 const bool use_viewport_compositor =
draw_ctx->is_viewport_compositor_enabled();
177 const bool has_grease_pencil_pass =
179 this->
use_separate_pass = use_viewport_compositor ? has_grease_pencil_pass :
false;
200 const bool is_fade_layer = ((!hide_overlay) && (!this->
is_render) &&
205 const bool is_fade_object = ((!hide_overlay) && (!this->
is_render) &&
209 draw_ctx->v3d->overlay.gpencil_paper_opacity :
213 draw_ctx->v3d->overlay.gpencil_paper_opacity :
261 float fstop = cam->dof.aperture_fstop;
264 float focal_len = cam->lens;
266 const float scale_camera = 0.001f;
268 float aperture = 0.5f * scale_camera * focal_len / fstop;
269 float focal_len_scaled = scale_camera * focal_len;
270 float sensor_scaled = scale_camera * sensor;
273 sensor_scaled *=
draw_ctx->rv3d->viewcamtexcofac[0];
276 this->
dof_params[1] = aperture *
fabsf(focal_len_scaled / (focus_dist - focal_len_scaled));
277 this->
dof_params[1] *= vp_size[0] / sensor_scaled;
286#define DISABLE_BATCHING 0
288bool Instance::is_used_as_layer_mask_in_viewlayer(
const GreasePencil &grease_pencil,
289 const bke::greasepencil::Layer &mask_layer,
292 using namespace bke::greasepencil;
293 for (
const Layer *layer : grease_pencil.layers()) {
294 if (layer->view_layer_name().is_empty() ||
305 if (
STREQ(
mask->layer_name, mask_layer.name().c_str())) {
313bool Instance::use_layer_in_render(
const GreasePencil &grease_pencil,
314 const bke::greasepencil::Layer &layer,
316 bool &r_is_used_as_mask)
318 if (!layer.view_layer_name().is_empty() &&
323 if (is_used_as_layer_mask_in_viewlayer(grease_pencil, layer,
view_layer)) {
324 r_is_used_as_mask =
true;
333tObject *Instance::object_sync_do(
Object *ob, ResourceHandleRange res_handle)
335 using namespace ed::greasepencil;
336 using namespace bke::greasepencil;
339 const Bounds<float3> bounds = grease_pencil.bounds_min_max_eval().value_or(Bounds(
float3(0)));
343 const bool do_multi_frame = (((this->
scene->toolsettings->gpencil_flags &
353 gpu::Texture *tex_fill = this->
dummy_tx;
354 gpu::Texture *tex_stroke = this->
dummy_tx;
356 gpu::Batch *iter_geom =
nullptr;
361 const auto drawcall_flush = [&](
PassSimple &pass) {
363 if (iter_geom !=
nullptr) {
364 pass.draw(iter_geom, 1, vcount, vfirst, res_handle);
372 const auto drawcall_add =
373 [&](
PassSimple &pass, gpu::Batch *draw_geom,
const int v_first,
const int v_count) {
375 pass.draw(iter_geom, 1, vcount, vfirst, res_handle);
378 int last = vfirst + vcount;
380 if ((draw_geom != iter_geom) || (v_first -
last > 0)) {
381 drawcall_flush(pass);
383 iter_geom = draw_geom;
387 vcount = v_first + v_count - vfirst;
394 *this->
scene, grease_pencil,
true);
395 const Span<const Layer *> layers = grease_pencil.layers();
396 for (
const DrawingInfo
info : drawings) {
397 const Layer &layer = *layers[
info.layer_index];
399 const bke::CurvesGeometry &curves =
info.drawing.strokes();
400 const OffsetIndices<int> points_by_curve = curves.evaluated_points_by_curve();
401 const bke::AttributeAccessor attributes = curves.attributes();
402 const VArray<bool> cyclic = *attributes.lookup_or_default<
bool>(
405 IndexMaskMemory memory;
407 *ob,
info.drawing, memory);
412 Array<int> num_triangles_per_stroke(visible_strokes.
size());
413 Array<int> num_vertices_per_stroke(visible_strokes.
size());
414 int total_num_triangles = 0;
415 int total_num_vertices = 0;
417 const IndexRange points = points_by_curve[stroke_i];
418 const int num_stroke_triangles = (points.
size() >= 3) ? (points.
size() - 2) : 0;
419 const int num_stroke_vertices = (points.
size() +
420 int(cyclic[stroke_i] && (points.
size() >= 3)));
421 num_triangles_per_stroke[
pos] = num_stroke_triangles;
422 num_vertices_per_stroke[
pos] = num_stroke_vertices;
423 total_num_triangles += num_stroke_triangles;
424 total_num_vertices += num_stroke_vertices;
427 bool is_layer_used_as_mask =
false;
428 const bool show_drawing_in_render = use_layer_in_render(
429 grease_pencil, layer, *this->
view_layer, is_layer_used_as_mask);
430 if (!show_drawing_in_render) {
432 t_offset += total_num_triangles;
433 t_offset += total_num_vertices * 2;
438 drawcall_flush(*last_pass);
442 this, ob, layer,
info.onion_id, is_layer_used_as_mask, tgp_ob);
453 gpu::UniformBuf *ubo_mat;
456 pass.bind_ubo(
"gp_lights", lights_ubo);
457 pass.bind_ubo(
"gp_materials", ubo_mat);
458 pass.bind_texture(
"gp_fill_tx", tex_fill);
459 pass.bind_texture(
"gp_stroke_tx", tex_stroke);
460 pass.push_constant(
"gp_material_offset", mat_ofs);
462 pass.push_constant(
"gp_stroke_index_offset", 0.0f);
463 pass.push_constant(
"viewport_size",
float2(
draw_ctx->viewport_size_get()));
465 const VArray<int> stroke_materials = *attributes.lookup_or_default<
int>(
467 const VArray<bool> is_fill_guide = *attributes.lookup_or_default<
bool>(
470 const bool only_lines = !
ELEM(ob->
mode,
476 const bool is_onion =
info.onion_id != 0;
479 const IndexRange points = points_by_curve[stroke_i];
483 const int material_index = std::max(stroke_materials[stroke_i], 0);
486 const bool is_fill_guide_stroke = is_fill_guide[stroke_i];
490 is_fill_guide_stroke;
491 const bool show_fill = (points.
size() >= 3) &&
496 const bool skip_stroke = hide_material || (!show_stroke && !show_fill) ||
497 (only_lines && !
do_onion && is_onion) || hide_onion;
500 t_offset += num_triangles_per_stroke[
pos];
501 t_offset += num_vertices_per_stroke[
pos] * 2;
505 gpu::UniformBuf *new_ubo_mat;
506 gpu::Texture *new_tex_fill =
nullptr;
507 gpu::Texture *new_tex_stroke =
nullptr;
509 matpool, mat_ofs + material_index, &new_tex_stroke, &new_tex_fill, &new_ubo_mat);
511 const bool resource_changed = (ubo_mat != new_ubo_mat) ||
512 (new_tex_fill && (new_tex_fill != tex_fill)) ||
513 (new_tex_stroke && (new_tex_stroke != tex_stroke));
515 if (resource_changed) {
516 drawcall_flush(pass);
518 if (new_ubo_mat != ubo_mat) {
519 pass.bind_ubo(
"gp_materials", new_ubo_mat);
520 ubo_mat = new_ubo_mat;
523 pass.bind_texture(
"gp_fill_tx", new_tex_fill);
524 tex_fill = new_tex_fill;
526 if (new_tex_stroke) {
527 pass.bind_texture(
"gp_stroke_tx", new_tex_stroke);
528 tex_stroke = new_tex_stroke;
533 if (iter_geom != geom) {
534 drawcall_flush(pass);
538 pass.bind_texture(
"gp_pos_tx", position_tx);
539 pass.bind_texture(
"gp_col_tx",
color_tx);
543 const int v_first = t_offset * 3;
544 const int v_count = num_triangles_per_stroke[
pos] * 3;
545 drawcall_add(pass, geom, v_first, v_count);
548 t_offset += num_triangles_per_stroke[
pos];
551 const int v_first = t_offset * 3;
552 const int v_count = num_vertices_per_stroke[
pos] * 2 * 3;
553 drawcall_add(pass, geom, v_first, v_count);
556 t_offset += num_vertices_per_stroke[
pos] * 2;
561 drawcall_flush(*last_pass);
579 tObject *tgp_ob = object_sync_do(ob, res_handle);
580 vfx_sync(ob, tgp_ob);
608 if (this->
tobjects.first ==
nullptr) {
616 gpu::TextureFormat::SFLOAT_16_16_16_16 :
617 gpu::TextureFormat::UNORM_10_10_10_2;
619 this->
depth_tx.acquire(
size, gpu::TextureFormat::SFLOAT_32_DEPTH_UINT_8);
620 this->color_tx.acquire(
size, format_color);
648 gpu::TextureFormat::UNORM_8;
663 output_pass_texture.
acquire(
size, gpu::TextureFormat::SFLOAT_16_16_16_16);
671 this->color_tx.release();
688 const float clear_col[4] = {1.0f, 1.0f, 1.0f, 1.0f};
690 bool inverted =
false;
693 bool cleared =
false;
708 inverted = !inverted;
718 if (mask_layer ==
nullptr) {
737 const float clear_cols[2][4] = {{0.0f, 0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}};
752 draw_mask(
view, ob, layer);
773 manager->submit(*vfx->vfx_ps);
802 float clear_cols[2][4] = {{0.0f, 0.0f, 0.0f, 0.0f}, {1.0f, 1.0f, 1.0f, 1.0f}};
808 float background_color[3];
819 if (this->
tobjects.first ==
nullptr) {
837 draw_object(
view, ob);
841 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()
T & DRW_object_get_data_for_drawing(const Object &object)
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(blender::gpu::FrameBuffer *fb, float clear_depth, uint clear_stencil)
void GPU_framebuffer_multi_clear(blender::gpu::FrameBuffer *fb, const float(*clear_colors)[4])
#define GPU_ATTACHMENT_NONE
void GPU_framebuffer_clear_color_depth(blender::gpu::FrameBuffer *fb, const float clear_col[4], float clear_depth)
void GPU_framebuffer_bind(blender::gpu::FrameBuffer *fb)
@ GPU_TEXTURE_USAGE_SHADER_READ
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
void foreach_index(Fn &&fn) const
constexpr int64_t size() const
bool contains(const Key &key) const
ResourceHandleRange unique_handle(const ObjectRef &ref)
void submit(PassSimple &pass, View &view)
void acquire(int2 extent, blender::gpu::TextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL)
static View & default_get()
const float4x4 & viewinv(int view_id=0) const
void shader_set(gpu::Shader *shader)
void bind_texture(const char *name, gpu::Texture *texture, GPUSamplerState state=sampler_auto)
void draw_procedural(GPUPrimType primitive, uint instance_len, uint vertex_len, uint vertex_first=-1, ResourceIndexRange res_index={}, uint custom_id=0)
void state_set(DRWState state, int clip_plane_count=0)
void push_constant(const char *name, const float &data)
static ShaderCache & get()
const DRWContext * DRW_context_get()
blender::draw::TextureFromPool & DRW_viewport_pass_texture_get(const char *pass_name)
int DRW_object_visibility_in_active_context(const Object *ob)
blender::draw::Manager * DRW_manager_get()
ccl_device_inline float2 mask(const MaskType mask, const float2 a)
Set< std::string > get_used_passes(const Scene &scene, const ViewLayer *view_layer)
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)
MatBase< float, 4, 4 > float4x4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< float, 3 > float3
blender::gpu::FrameBuffer * default_fb
blender::gpu::Texture * depth
GreasePencilLayerTreeNode base
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
gpu::Batch * stroke_batch
LightPool * last_light_pool
Texture snapshot_depth_tx
struct BLI_memblock * gp_object_pool
TextureFromPool color_object_tx
tLayer_Pool * gp_layer_pool
float vertex_paint_opacity
TextureFromPool mask_color_tx
struct ViewLayer * view_layer
float fade_3d_object_opacity
struct blender::draw::gpencil::Instance::@053346266241271021036107110366172237215334041065 sbuffer_tobjects
bool force_stroke_order_3d
gpu::FrameBuffer * scene_fb
struct BLI_memblock * gp_material_pool
const DRWContext * draw_ctx
PassSimple mask_invert_ps
struct blender::draw::gpencil::Instance::@236154265015220156065132174366266070164251065066 tobjects
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]
struct blender::draw::gpencil::Instance::@236154265015220156065132174366266070164251065066 tobjects_infront
Texture snapshot_color_tx
void object_sync(ObjectRef &ob_ref, Manager &manager) final
TextureFromPool reveal_layer_tx
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
gpLight light_data[GPENCIL_LIGHT_BUFFER_LEN]
gpMaterial mat_data[GPENCIL_MATERIAL_BUFFER_LEN]
std::unique_ptr< PassSimple > geom_ps
BLI_bitmap * mask_invert_bits
std::unique_ptr< PassSimple > blend_ps