26 PassSimple edit_grease_pencil_ps_ = {
"GPencil Edit"};
32 bool show_points_ =
false;
33 bool show_lines_ =
false;
34 bool show_grid_ =
false;
35 bool show_weight_ =
false;
39 View view_edit_cage = {
"view_edit_cage"};
40 float view_dist = 0.0f;
42 bool enabled_ =
false;
53 view_dist =
state.view_dist_get(view.winmat());
63 show_points_ = show_lines_ = show_weight_ =
false;
65 switch (
state.object_mode) {
74 show_points_ = show_edit_point;
75 show_lines_ = show_lines;
80 show_lines_ = show_lines;
93 edit_points_ =
nullptr;
94 edit_lines_ =
nullptr;
97 auto &pass = edit_grease_pencil_ps_;
101 state.clipping_plane_count);
104 auto &sub = pass.sub(
"Points");
108 sub.push_constant(
"useWeight", show_weight_);
109 sub.push_constant(
"useGreasePencil",
true);
110 sub.push_constant(
"doStrokeEndpoints", show_direction);
115 auto &sub = pass.
sub(
"Lines");
119 sub.push_constant(
"useWeight", show_weight_);
120 sub.push_constant(
"useGreasePencil",
true);
133 auto &pass = grid_ps_;
136 state.clipping_plane_count);
138 const float4 col_grid(0.5f, 0.5f, 0.5f,
state.overlay.gpencil_grid_opacity);
141 pass.push_constant(
"color", col_grid);
158 gpu::Batch *geom = show_weight_ ?
200 const int grid_lines = 4;
201 const int line_count = grid_lines * 4 + 2;
219 manager.
submit(grid_ps_, view);
231 manager.
submit(edit_grease_pencil_ps_, view_edit_cage);
246 if (is_perspective) {
268 depth_plane_get(ob, view);
269 pass.push_constant(
"gpDepthPlane", plane);
272 const Vector<DrawingInfo> drawings = retrieve_visible_drawings(*scene, grease_pencil,
true);
276 const float object_scale =
mat4_to_scale(ob->object_to_world().ptr());
282 pass.push_constant(
"gpStrokeOrder3d", is_stroke_order_3d);
283 pass.push_constant(
"gpThicknessScale", object_scale);
284 pass.push_constant(
"gpThicknessOffset", 0.0f);
285 pass.push_constant(
"gpThicknessWorldScale", thickness_scale);
286 pass.bind_texture(
"gp_pos_tx", position_tx);
287 pass.bind_texture(
"gp_col_tx",
color_tx);
292 const VArray<int> stroke_materials = *attributes.lookup_or_default<
int>(
294 const VArray<bool> cyclic = *attributes.lookup_or_default<
bool>(
299 *ob, info.drawing, memory);
302 const IndexRange points = points_by_curve[stroke_i];
303 const int material_index = stroke_materials[stroke_i];
306 const bool hide_onion = info.onion_id != 0;
309 const int num_stroke_triangles = (points.size() >= 3) ? (points.size() - 2) : 0;
310 const int num_stroke_vertices = (points.size() +
311 int(cyclic[stroke_i] && (points.size() >= 3)));
313 if (hide_material || hide_onion) {
314 t_offset += num_stroke_triangles;
315 t_offset += num_stroke_vertices * 2;
322 const bool show_fill = (points.size() >= 3) &&
326 int v_first = t_offset * 3;
327 int v_count = num_stroke_triangles * 3;
328 pass.draw(geom, 1, v_count, v_first, res_handle, select_id.get());
331 t_offset += num_stroke_triangles;
334 int v_first = t_offset * 3;
335 int v_count = num_stroke_vertices * 2 * 3;
336 pass.draw(geom, 1, v_count, v_first, res_handle, select_id.get());
338 t_offset += num_stroke_vertices * 2;
345 static float4 depth_plane_get(
const Object *ob,
const ViewParameters &view)
358 float3 size = (bounds->max - bounds->min) * 0.5f;
363 float4x4 bbox_to_world = ob->object_to_world() * bbox_to_object;
366 float3 view_vector = (view.is_perspective) ? view.location - bbox_center : view.z_axis;
377 return float4(plane_direction, -
dot(plane_direction, bbox_center));
384 const ::GreasePencil &grease_pencil = *
static_cast<::
GreasePencil *
>(
object.data);
387 float4x4 mat =
object.object_to_world();
389 mat = layer.to_world_space(
object);
396 std::swap(mat[0], mat[2]);
399 std::swap(mat[1], mat[2]);
420 mat.
location() = layer.to_world_space(
object).location();
Low-level operations for curves.
Low-level operations for grease pencil.
struct MaterialGPencilStyle * BKE_gpencil_material_settings(struct Object *ob, short act)
General operations, lookup, etc. for blender objects.
std::optional< blender::Bounds< blender::float3 > > BKE_object_boundbox_get(const Object *ob)
float mat4_to_scale(const float mat[4][4])
@ GREASE_PENCIL_STROKE_ORDER_3D
@ GP_MATERIAL_STROKE_SHOW
@ OB_MODE_VERTEX_GREASE_PENCIL
@ OB_MODE_PAINT_GREASE_PENCIL
@ OB_MODE_SCULPT_GREASE_PENCIL
@ OB_MODE_WEIGHT_GREASE_PENCIL
@ GP_PROJECT_DEPTH_STROKE
@ V3D_GP_SHOW_STROKE_DIRECTION
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
btMatrix3x3 transpose() const
Return the transpose of the matrix.
SIMD_FORCE_INLINE btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
ResourceHandle unique_handle(const ObjectRef &ref)
void submit(PassSimple &pass, View &view)
void sync(const float4x4 &view_mat, const float4x4 &win_mat, int view_id=0)
void draw(gpu::Batch *batch, uint instance_len=-1, uint vertex_len=-1, uint vertex_first=-1, ResourceHandle handle={0}, uint custom_id=0)
void draw_procedural(GPUPrimType primitive, uint instance_len, uint vertex_len, uint vertex_first=-1, ResourceHandle handle={0}, uint custom_id=0)
PassBase< DrawCommandBufType > & sub(const char *name)
void push_constant(const char *name, const float &data)
void shader_set(GPUShader *shader)
void object_sync(const ObjectRef &ob_ref, Resources &, State &state)
void sculpt_object_sync(Manager &manager, const ObjectRef &ob_ref, const State &state, Resources &res)
static void draw_grease_pencil(PassMain::Sub &pass, const ViewParameters &view, const Scene *scene, Object *ob, ResourceHandle res_handle, select::ID select_id=select::SelectMap::select_invalid_id())
void paint_object_sync(Manager &manager, const ObjectRef &ob_ref, const State &state, Resources &res)
void draw(Framebuffer &framebuffer, Manager &manager, View &view)
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, const State &state, Resources &)
void draw_color_only(Framebuffer &framebuffer, Manager &manager, View &view)
void begin_sync(Resources &res, const State &state, const View &view)
ShaderPtr curve_edit_line
ShaderPtr curve_edit_points
ShaderPtr grid_grease_pencil
void foreach_index(Fn &&fn) const
void DRW_view_viewmat_get(const DRWView *view, float mat[4][4], bool inverse)
@ DRW_STATE_DEPTH_LESS_EQUAL
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
blender::bke::AttrDomain ED_grease_pencil_edit_selection_domain_get(const ToolSettings *tool_settings)
constexpr float LEGACY_RADIUS_CONVERSION_FACTOR
static float4x4 winmat_polygon_offset(float4x4 winmat, float view_dist, float offset)
blender::gpu::Batch * DRW_cache_grease_pencil_get(const Scene *scene, Object *ob)
gpu::VertBuf * DRW_cache_grease_pencil_position_buffer_get(const Scene *scene, Object *ob)
blender::gpu::Batch * DRW_cache_grease_pencil_edit_lines_get(const Scene *scene, Object *ob)
blender::gpu::Batch * DRW_cache_grease_pencil_weight_lines_get(const Scene *scene, Object *ob)
blender::gpu::Batch * DRW_cache_grease_pencil_edit_points_get(const Scene *scene, Object *ob)
blender::gpu::Batch * DRW_cache_grease_pencil_weight_points_get(const Scene *scene, Object *ob)
gpu::VertBuf * DRW_cache_grease_pencil_color_buffer_get(const Scene *scene, Object *ob)
IndexMask retrieve_visible_strokes(Object &object, const bke::greasepencil::Drawing &drawing, IndexMaskMemory &memory)
MatT from_loc_scale(const typename MatT::loc_type &location, const VecBase< typename MatT::base_type, ScaleDim > &scale)
CartesianBasis invert(const CartesianBasis &basis)
T midpoint(const T &a, const T &b)
VecBase< T, 3 > transform_direction(const MatBase< T, 3, 3 > &mat, const VecBase< T, 3 > &direction)
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
MatBase< float, 3, 3 > float3x3
VecBase< float, 3 > float3
const c_style_mat & ptr() const
ViewParameters(bool is_perspective, const float4x4 &viewinv)
TextureRef weight_ramp_tx
GPUUniformBuf * globals_buf
static const ID select_invalid_id()