38 PassSimple edit_mesh_normals_ps_ = {
"Normals"};
45 PassSimple edit_mesh_analysis_ps_ = {
"Mesh Analysis"};
46 PassSimple edit_mesh_weight_ps_ = {
"Edit Weight"};
52 PassSimple edit_mesh_facedots_ps_ = {
"FaceDots"};
53 PassSimple edit_mesh_skin_roots_ps_ = {
"SkinRoots"};
56 PassSimple edit_mesh_prepass_ps_ = {
"Prepass"};
58 bool xray_enabled =
false;
60 bool show_retopology =
false;
61 bool show_mesh_analysis =
false;
62 bool show_face =
false;
63 bool show_face_dots =
false;
64 bool show_weight =
false;
66 bool select_edge =
false;
67 bool select_face =
false;
68 bool select_vert =
false;
72 View view_edit_cage = {
"view_edit_cage"};
73 View view_edit_edge = {
"view_edit_edge"};
74 View view_edit_vert = {
"view_edit_vert"};
75 float view_dist = 0.0f;
77 bool enabled_ =
false;
88 view_dist =
state.view_dist_get(view.winmat());
89 xray_enabled =
state.xray_enabled;
96 int edit_flag =
state.v3d->overlay.edit_flag;
108 const bool is_wire_shading_mode = (
state.v3d->shading.type ==
OB_WIRE);
110 uint4 data_mask = data_mask_get(edit_flag);
112 float backwire_opacity = (
state.xray_enabled) ? 0.5f : 1.0f;
113 float face_alpha = (show_face) ? 1.0f : 0.0f;
122 auto &pass = edit_mesh_prepass_ps_;
125 state.clipping_plane_count);
127 pass.push_constant(
"retopologyOffset", retopology_offset);
137 if (
state.xray_enabled) {
141 auto &pass = edit_mesh_normals_ps_;
143 pass.state_set(pass_state,
state.clipping_plane_count);
145 auto shader_pass = [&](
GPUShader *shader,
const char *name) {
146 auto &sub = pass.sub(name);
147 sub.shader_set(shader);
149 sub.bind_texture(
"depthTex", depth_tex);
150 sub.push_constant(
"alpha", backwire_opacity);
151 sub.push_constant(
"isConstantScreenSizeNormals", use_screen_size);
152 sub.push_constant(
"normalSize",
state.overlay.normals_length);
153 sub.push_constant(
"normalScreenSize",
state.overlay.normals_constant_screen_size);
154 sub.push_constant(
"retopologyOffset", retopology_offset);
155 sub.push_constant(
"hq_normals", use_hq_normals);
159 face_normals_ = loop_normals_ = vert_normals_ =
nullptr;
178 auto &pass = edit_mesh_weight_ps_;
181 state.clipping_plane_count);
186 pass.push_constant(
"drawContours",
false);
187 pass.push_constant(
"opacity",
state.overlay.weight_paint_mode_opacity);
194 auto &pass = edit_mesh_analysis_ps_;
197 state.clipping_plane_count);
202 auto mesh_edit_common_resource_bind = [&](
PassSimple &pass,
float alpha) {
203 pass.bind_texture(
"depthTex", depth_tex);
205 pass.push_constant(
"wireShading", is_wire_shading_mode);
206 pass.push_constant(
"selectFace", select_face);
207 pass.push_constant(
"selectEdge", select_edge);
208 pass.push_constant(
"alpha", alpha);
209 pass.push_constant(
"retopologyOffset", retopology_offset);
210 pass.push_constant(
"dataMask",
int4(data_mask));
215 auto &pass = edit_mesh_edges_ps_;
220 state.clipping_plane_count);
222 pass.push_constant(
"do_smooth_wire", do_smooth_wire);
223 pass.push_constant(
"use_vertex_selection", select_vert);
224 mesh_edit_common_resource_bind(pass, backwire_opacity);
227 auto &pass = edit_mesh_faces_ps_;
231 state.clipping_plane_count);
233 mesh_edit_common_resource_bind(pass, face_alpha);
236 auto &pass = edit_mesh_cages_ps_;
239 state.clipping_plane_count);
241 mesh_edit_common_resource_bind(pass, face_alpha);
244 auto &pass = edit_mesh_verts_ps_;
248 state.clipping_plane_count);
250 mesh_edit_common_resource_bind(pass, backwire_opacity);
253 auto &pass = edit_mesh_facedots_ps_;
257 state.clipping_plane_count);
259 mesh_edit_common_resource_bind(pass, backwire_opacity);
262 auto &pass = edit_mesh_skin_roots_ps_;
266 state.clipping_plane_count);
268 pass.push_constant(
"retopologyOffset", retopology_offset);
289 const bool draw_as_solid = (ob->
dt >
OB_WIRE);
291 if (show_retopology) {
293 edit_mesh_prepass_ps_.
draw(geom, res_handle);
297 edit_mesh_prepass_ps_.
draw(geom, res_handle);
300 if (show_mesh_analysis) {
302 edit_mesh_analysis_ps_.
draw(geom, res_handle);
307 edit_mesh_weight_ps_.
draw(geom, res_handle);
312 (use_gpu_subdiv ? face_normals_subdiv_ : face_normals_)
317 (use_gpu_subdiv ? loop_normals_subdiv_ : loop_normals_)
332 ->
draw(geom, res_handle);
336 edit_mesh_verts_ps_.
draw(geom, res_handle);
338 if (show_face_dots) {
340 edit_mesh_facedots_ps_.
draw(geom, res_handle);
343 if (mesh_has_skin_roots(ob)) {
361 manager.
submit(edit_mesh_prepass_ps_, view);
362 manager.
submit(edit_mesh_analysis_ps_, view);
363 manager.
submit(edit_mesh_weight_ps_, view);
374 manager.
submit(edit_mesh_normals_ps_, view);
375 manager.
submit(edit_mesh_faces_ps_, view);
376 manager.
submit(edit_mesh_cages_ps_, view_edit_cage);
377 manager.
submit(edit_mesh_edges_ps_, view_edit_edge);
378 manager.
submit(edit_mesh_verts_ps_, view_edit_vert);
379 manager.
submit(edit_mesh_skin_roots_ps_, view_edit_vert);
380 manager.
submit(edit_mesh_facedots_ps_, view_edit_vert);
402 manager.
submit(edit_mesh_normals_ps_, view);
403 manager.
submit(edit_mesh_faces_ps_, view);
404 manager.
submit(edit_mesh_cages_ps_, view_edit_cage);
405 manager.
submit(edit_mesh_edges_ps_, view_edit_edge);
406 manager.
submit(edit_mesh_verts_ps_, view_edit_vert);
407 manager.
submit(edit_mesh_skin_roots_ps_, view_edit_vert);
408 manager.
submit(edit_mesh_facedots_ps_, view_edit_vert);
415 const Mesh &mesh = *
static_cast<const Mesh *
>(ob->
data);
416 if (mesh.runtime->edit_mesh.get() !=
nullptr) {
420 return (editmesh_eval_cage !=
nullptr) && (editmesh_eval_cage != editmesh_eval_final);
428 uint4 mask = {0xFF, 0xFF, 0x00, 0x00};
439 static bool mesh_has_skin_roots(
const Object *ob)
441 const Mesh &mesh = *
static_cast<const Mesh *
>(ob->
data);
442 if (
BMEditMesh *em = mesh.runtime->edit_mesh.get()) {
462 PassSimple image_border_ps_ = {
"ImageBorder"};
465 PassSimple brush_stencil_ps_ = {
"BrushStencil"};
470 bool show_vert =
false;
471 bool show_face =
false;
472 bool show_face_dots =
false;
473 bool show_uv_edit =
false;
478 bool show_wireframe =
false;
482 bool show_stencil =
false;
486 bool show_mask =
false;
488 Mask *mask_id =
nullptr;
489 Texture mask_texture_ = {
"mask_texture_"};
492 bool show_mesh_analysis =
false;
501 float total_area_ratio_;
504 bool show_tiled_image_active =
false;
505 bool show_tiled_image_border =
false;
506 bool show_tiled_image_label =
false;
511 bool enabled_ =
false;
525 const bool is_tiled_image = image && (image->source ==
IMA_SRC_TILED);
529 enabled_ = !is_viewer;
545 show_uv_edit = space_mode_is_uv && object_mode_is_edit;
551 show_face_dots =
false;
558 show_face = !show_mesh_analysis && !hide_faces;
570 if (show_mesh_analysis) {
579 if (space_mode_is_uv && object_mode_is_edit) {
580 show_wireframe = show_wireframe_uv_edit;
582 else if (space_mode_is_uv && object_mode_is_paint) {
583 show_wireframe = show_wireframe_tex_paint;
585 else if (space_mode_is_paint && (object_mode_is_paint || object_mode_is_edit)) {
586 show_wireframe = show_wireframe_tex_paint;
588 else if (space_mode_is_view && object_mode_is_paint) {
589 show_wireframe = show_wireframe_tex_paint;
592 show_wireframe =
false;
598 show_stencil = space_mode_is_paint && brush &&
604 show_mask = space_mode_is_mask && space_image->
mask_info.
mask &&
617 show_tiled_image_border = is_tiled_image;
618 show_tiled_image_active = is_tiled_image;
619 show_tiled_image_label = is_tiled_image;
625 if (show_wireframe) {
626 auto &pass = wireframe_ps_;
632 pass.push_constant(
"alpha", space_image->
uv_opacity);
633 pass.push_constant(
"doSmoothWire", do_smooth_wire);
637 auto &pass = edges_ps_;
643 pass.specialize_constant(sh,
"use_edge_select", !show_vert);
646 pass.push_constant(
"lineStyle",
int(edit_uv_line_style_from_space_image(space_image)));
647 pass.push_constant(
"alpha", space_image->
uv_opacity);
648 pass.push_constant(
"dashLength", dash_length);
649 pass.push_constant(
"doSmoothWire", do_smooth_wire);
658 auto &pass = verts_ps_;
664 pass.push_constant(
"pointSize", (point_size + 1.5f) *
float(
M_SQRT2));
665 pass.push_constant(
"outlineWidth", 0.75f);
666 pass.push_constant(
"color", theme_color);
669 if (show_face_dots) {
672 auto &pass = facedots_ps_;
678 pass.push_constant(
"pointSize", (point_size + 1.5f) *
float(
M_SQRT2));
682 auto &pass = faces_ps_;
687 pass.push_constant(
"uvOpacity", space_image->
uv_opacity);
690 if (show_mesh_analysis) {
691 auto &pass = analysis_ps_;
698 pass.push_constant(
"aspect",
state.image_uv_aspect);
700 pass.push_constant(
"totalAreaRatio", &total_area_ratio_);
703 per_mesh_area_3d.
clear();
704 per_mesh_area_2d.
clear();
706 drawn_object_set_.
clear();
723 if (drawn_object_set_.
contains(object_orig)) {
726 drawn_object_set_.
add(object_orig);
730 Object &ob = *object_eval;
733 if (object_eval != ob_ref.
object) {
745 verts_ps_.
draw(geom, res_handle);
747 if (show_face_dots) {
749 facedots_ps_.
draw(geom, res_handle);
753 faces_ps_.
draw(geom, res_handle);
756 if (show_mesh_analysis) {
757 int index_3d, index_2d;
767 ob, mesh, &per_mesh_area_3d[index_3d], &per_mesh_area_2d[index_2d]);
769 analysis_ps_.
draw(geom, res_handle);
772 if (show_wireframe) {
777 if (object_eval != ob_ref.
object) {
790 float total_3d = 0.0f;
791 float total_2d = 0.0f;
792 for (
const float *mesh_area_2d : per_mesh_area_2d) {
793 total_2d += *mesh_area_2d;
795 for (
const float *mesh_area_3d : per_mesh_area_3d) {
796 total_3d += *mesh_area_3d;
805 if (show_tiled_image_border) {
817 auto &pass = image_border_ps_;
823 const int tile_x = ((
tile->tile_number - 1001) % 10);
824 const int tile_y = ((
tile->tile_number - 1001) / 10);
825 const float3 tile_location(tile_x, tile_y, 0.0f);
826 pass.push_constant(
"tile_pos", tile_location);
827 pass.push_constant(
"ucolor", is_active ? selected_color : theme_color);
831 if (show_tiled_image_label && !is_active) {
832 std::string text = std::to_string(
tile->tile_number);
850 if (show_tiled_image_active) {
856 auto &pass = brush_stencil_ps_;
871 pass.bind_texture(
"imgTexture", stencil_texture);
872 pass.push_constant(
"imgPremultiplied",
true);
873 pass.push_constant(
"imgAlphaBlend",
true);
876 pass.push_constant(
"brush_scale",
float2(stencil_texture.
size().
xy()) / size_image);
882 paint_mask_texture_ensure(mask_id,
state.image_size,
state.image_aspect);
887 auto &pass = paint_mask_ps_;
892 pass.bind_texture(
"imgTexture", mask_texture_);
893 pass.push_constant(
"color",
float4(1.0f, 1.0f, 1.0f, 1.0f));
894 pass.push_constant(
"opacity", opacity);
895 pass.push_constant(
"brush_offset",
float2(0.0f));
896 pass.push_constant(
"brush_scale",
float2(1.0f));
911 manager.
submit(paint_mask_ps_, view);
913 if (show_tiled_image_border) {
914 manager.
submit(image_border_ps_, view);
916 if (show_wireframe) {
917 manager.
submit(wireframe_ps_, view);
919 if (show_mesh_analysis) {
920 manager.
submit(analysis_ps_, view);
923 manager.
submit(faces_ps_, view);
926 manager.
submit(edges_ps_, view);
928 if (show_face_dots) {
929 manager.
submit(facedots_ps_, view);
932 manager.
submit(verts_ps_, view);
935 manager.
submit(brush_stencil_ps_, view);
952 manager.
submit(paint_mask_ps_, view);
961 switch (sima->
dt_uv) {
980 void paint_mask_texture_ensure(
Mask *mask,
const int2 &resolution,
const float2 &aspect)
982 const int width = resolution.
x;
983 const int height =
floor(
float(resolution.
y) * (aspect.
y / aspect.
x));
984 float *buffer =
static_cast<float *
>(
MEM_mallocN(
sizeof(
float) * height * width, __func__));
991 mask_texture_.
free();
CustomData interface, see also DNA_customdata_types.h.
int CustomData_get_offset(const CustomData *data, eCustomDataType type)
void BKE_image_get_size_fl(Image *image, ImageUser *iuser, float r_size[2])
GPUTexture * BKE_image_get_gpu_texture(Image *image, ImageUser *iuser)
void BKE_maskrasterize_handle_free(MaskRasterHandle *mr_handle)
MaskRasterHandle * BKE_maskrasterize_handle_new(void)
void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle, struct Mask *mask, int width, int height, bool do_aspect_correct, bool do_mask_aa, bool do_feather)
void BKE_maskrasterize_buffer(MaskRasterHandle *mr_handle, unsigned int width, unsigned int height, float *buffer)
Rasterize a buffer from a single mask (threaded execution).
const Mesh * BKE_object_get_editmesh_eval_cage(const Object *object)
const Mesh * BKE_object_get_editmesh_eval_final(const Object *object)
const Brush * BKE_paint_brush_for_read(const Paint *paint)
bool BKE_subsurf_modifier_has_gpu_subdiv(const Mesh *mesh)
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
#define SET_FLAG_FROM_TEST(value, test, flag)
Object * DEG_get_original_object(Object *object)
ID * DEG_get_evaluated_id(const Depsgraph *depsgraph, ID *id)
Object * DEG_get_evaluated_object(const Depsgraph *depsgraph, Object *object)
@ IMAGE_PAINT_BRUSH_TYPE_CLONE
@ MASK_OVERLAY_ALPHACHANNEL
@ USER_GPU_FLAG_OVERLAY_SMOOTH_WIRE
@ USER_GPU_FLAG_NO_EDIT_MODE_SMOOTH_WIRE
@ V3D_OVERLAY_EDIT_VERT_NORMALS
@ V3D_OVERLAY_EDIT_INDICES
@ V3D_OVERLAY_EDIT_FREESTYLE_FACE
@ V3D_OVERLAY_EDIT_RETOPOLOGY
@ V3D_OVERLAY_EDIT_LOOP_NORMALS
@ V3D_OVERLAY_EDIT_FACE_NORMALS
@ V3D_OVERLAY_EDIT_CREASES
@ V3D_OVERLAY_EDIT_FREESTYLE_EDGE
@ V3D_OVERLAY_EDIT_CONSTANT_SCREEN_SIZE_NORMALS
@ V3D_OVERLAY_EDIT_FACE_AREA
@ V3D_OVERLAY_EDIT_EDGE_ANG
@ V3D_OVERLAY_EDIT_FACE_DOT
@ V3D_OVERLAY_EDIT_FACE_ANG
@ V3D_OVERLAY_EDIT_STATVIS
@ V3D_OVERLAY_EDIT_BWEIGHTS
@ V3D_OVERLAY_EDIT_WEIGHT
@ V3D_OVERLAY_EDIT_EDGE_LEN
#define RETOPOLOGY_OFFSET(v3d)
bool GPU_use_hq_normals_workaround()
void GPU_debug_group_end()
void GPU_debug_group_begin(const char *name)
void GPU_framebuffer_bind(GPUFrameBuffer *framebuffer)
@ GPU_TEXTURE_USAGE_SHADER_READ
void UI_GetThemeColor4fv(int colorid, float col[4])
void UI_GetThemeColorShade4fv(int colorid, int offset, float col[4])
void UI_GetThemeColorShade4ubv(int colorid, int offset, unsigned char col[4])
float UI_GetThemeValuef(int colorid)
static void draw_tile(const float2 &zoom, const int texcoord_attribute, const int position_attribute, const DrawTile &draw_tile)
struct GPUShader GPUShader
bool contains(const Key &key) const
int64_t append_and_get_index(const T &value)
ResourceHandle unique_handle(const ObjectRef &ref)
void submit(PassSimple &pass, View &view)
void wrap(GPUTexture *tex)
bool ensure_2d(eGPUTextureFormat format, int2 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
int3 size(int miplvl=0) const
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_expand(gpu::Batch *batch, GPUPrimType primitive_type, uint primitive_len, uint instance_len, uint vertex_len=-1, uint vertex_first=-1, ResourceHandle handle={0}, uint custom_id=0)
void draw(Framebuffer &framebuffer, Manager &manager, View &view)
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, const State &state)
void begin_sync(Resources &res, const State &state)
void draw_on_render(GPUFrameBuffer *framebuffer, Manager &manager, View &view)
void end_sync(Resources &res, ShapeCache &shapes, const State &state)
void draw_color_only(Framebuffer &framebuffer, Manager &manager, View &view)
void draw(Framebuffer &framebuffer, Manager &manager, View &view)
static bool mesh_has_edit_cage(const Object *ob)
void begin_sync(Resources &res, const State &state, const View &view)
void edit_object_sync(Manager &manager, const ObjectRef &ob_ref, const State &state, Resources &)
ShaderPtr uv_brush_stencil
ShaderPtr uv_edit_facedot
ShaderPtr paint_weight_fake_shading
ShaderPtr mesh_loop_normal
ShaderPtr mesh_face_normal_subdiv
ShaderPtr uv_image_borders
ShaderPtr uv_analysis_stretch_angle
ShaderPtr mesh_vert_normal
ShaderPtr mesh_face_normal
ShaderPtr mesh_edit_skin_root
ShaderPtr mesh_edit_depth
ShaderPtr mesh_loop_normal_subdiv
ShaderPtr uv_analysis_stretch_area
ShaderPtr mesh_edit_facedot
blender::gpu::Batch * DRW_cache_mesh_surface_weights_get(Object *ob)
blender::gpu::Batch * DRW_cache_mesh_surface_get(Object *ob)
void drw_batch_cache_generate_requested_delayed(Object *ob)
blender::gpu::Batch * DRW_cache_mesh_surface_mesh_analysis_get(Object *ob)
bool DRW_state_show_text()
void DRW_text_cache_add(DRWTextStore *dt, const float co[3], const char *str, const int str_len, short xoffs, short yoffs, short flag, const uchar col[4], const bool shadow, const bool align_center)
void DRW_text_edit_mesh_measure_stats(const ARegion *region, const View3D *v3d, const Object *ob, const UnitSettings *unit, DRWTextStore *dt)
@ DRW_TEXT_CACHE_GLOBALSPACE
@ DRW_STATE_DEPTH_LESS_EQUAL
@ DRW_STATE_FIRST_VERTEX_CONVENTION
@ DRW_STATE_BLEND_ALPHA_PREMUL
ccl_gpu_kernel_postfix ccl_global KernelWorkTile * tiles
ccl_global const KernelWorkTile * tile
void *(* MEM_mallocN)(size_t len, const char *str)
void MEM_freeN(void *vmemh)
ccl_device_inline float4 mask(const int4 mask, const float4 a)
constexpr int overlay_edit_text
static float4x4 winmat_polygon_offset(float4x4 winmat, float view_dist, float offset)
blender::gpu::Batch * DRW_mesh_batch_cache_get_edituv_faces_stretch_angle(Object &object, Mesh &mesh)
blender::gpu::Batch * DRW_mesh_batch_cache_get_edituv_edges(Object &object, Mesh &mesh)
blender::gpu::Batch * DRW_mesh_batch_cache_get_edit_edges(Mesh &mesh)
blender::gpu::Batch * DRW_mesh_batch_cache_get_edituv_facedots(Object &object, Mesh &mesh)
blender::gpu::Batch * DRW_mesh_batch_cache_get_edit_facedots(Mesh &mesh)
blender::gpu::Batch * DRW_mesh_batch_cache_get_edituv_verts(Object &object, Mesh &mesh)
blender::gpu::Batch * DRW_mesh_batch_cache_get_edituv_faces(Object &object, Mesh &mesh)
blender::gpu::Batch * DRW_mesh_batch_cache_get_edit_loop_normals(Mesh &mesh)
blender::gpu::Batch * DRW_mesh_batch_cache_get_edit_triangles(Mesh &mesh)
blender::gpu::Batch * DRW_mesh_batch_cache_get_edit_vertices(Mesh &mesh)
blender::gpu::Batch * DRW_mesh_batch_cache_get_uv_edges(Object &object, Mesh &mesh)
void DRW_mesh_batch_cache_validate(Object &object, Mesh &mesh)
blender::gpu::Batch * DRW_mesh_batch_cache_get_edit_vert_normals(Mesh &mesh)
blender::gpu::Batch * DRW_mesh_batch_cache_get_edituv_faces_stretch_area(Object &object, Mesh &mesh, float **tot_area, float **tot_uv_area)
blender::gpu::Batch * DRW_mesh_batch_cache_get_edit_skin_roots(Mesh &mesh)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
VecBase< int32_t, 4 > int4
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< float, 3 > float3
@ OVERLAY_UV_LINE_STYLE_DASH
@ OVERLAY_UV_LINE_STYLE_SHADOW
@ OVERLAY_UV_LINE_STYLE_WHITE
@ OVERLAY_UV_LINE_STYLE_OUTLINE
@ OVERLAY_UV_LINE_STYLE_BLACK
VecBase< T, 2 > xy() const
TextureRef weight_ramp_tx
GPUUniformBuf * globals_buf