Changeset View
Changeset View
Standalone View
Standalone View
source/blender/draw/engines/overlay/overlay_paint.cc
- This file was moved from source/blender/draw/engines/overlay/overlay_paint.c.
| /* SPDX-License-Identifier: GPL-2.0-or-later | /* SPDX-License-Identifier: GPL-2.0-or-later | ||||
| * Copyright 2019 Blender Foundation. */ | * Copyright 2019 Blender Foundation. */ | ||||
| /** \file | /** \file | ||||
| * \ingroup draw_engine | * \ingroup draw_engine | ||||
| */ | */ | ||||
| #include "DRW_render.h" | #include "DRW_render.h" | ||||
| #include "BKE_image.h" | #include "BKE_image.h" | ||||
| #include "DNA_mesh_types.h" | #include "DNA_mesh_types.h" | ||||
| #include "DEG_depsgraph_query.h" | #include "DEG_depsgraph_query.h" | ||||
| #include "overlay_private.h" | #include "overlay_private.hh" | ||||
| /* Check if the given object is rendered (partially) transparent */ | /* Check if the given object is rendered (partially) transparent */ | ||||
| static bool paint_object_is_rendered_transparent(View3D *v3d, Object *ob) | static bool paint_object_is_rendered_transparent(View3D *v3d, Object *ob) | ||||
| { | { | ||||
| if (v3d->shading.type == OB_WIRE) { | if (v3d->shading.type == OB_WIRE) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (v3d->shading.type == OB_SOLID) { | if (v3d->shading.type == OB_SOLID) { | ||||
| if (v3d->shading.flag & V3D_SHADING_XRAY) { | if (v3d->shading.flag & V3D_SHADING_XRAY) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| if (ob && v3d->shading.color_type == V3D_SHADING_OBJECT_COLOR) { | if (ob && v3d->shading.color_type == V3D_SHADING_OBJECT_COLOR) { | ||||
| return ob->color[3] < 1.0f; | return ob->color[3] < 1.0f; | ||||
| } | } | ||||
| if (ob && ob->type == OB_MESH && ob->data && | if (ob && ob->type == OB_MESH && ob->data && | ||||
| v3d->shading.color_type == V3D_SHADING_MATERIAL_COLOR) { | v3d->shading.color_type == V3D_SHADING_MATERIAL_COLOR) { | ||||
| Mesh *me = ob->data; | Mesh *me = static_cast<Mesh *>(ob->data); | ||||
| for (int i = 0; i < me->totcol; i++) { | for (int i = 0; i < me->totcol; i++) { | ||||
| Material *mat = BKE_object_material_get_eval(ob, i + 1); | Material *mat = BKE_object_material_get_eval(ob, i + 1); | ||||
| if (mat && mat->a < 1.0f) { | if (mat && mat->a < 1.0f) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| Show All 26 Lines | void OVERLAY_paint_cache_init(OVERLAY_Data *vedata) | ||||
| struct GPUShader *sh; | struct GPUShader *sh; | ||||
| DRWShadingGroup *grp; | DRWShadingGroup *grp; | ||||
| DRWState state; | DRWState state; | ||||
| const bool is_edit_mode = (pd->ctx_mode == CTX_MODE_EDIT_MESH); | const bool is_edit_mode = (pd->ctx_mode == CTX_MODE_EDIT_MESH); | ||||
| const bool draw_contours = !is_edit_mode && | const bool draw_contours = !is_edit_mode && | ||||
| (pd->overlay.wpaint_flag & V3D_OVERLAY_WPAINT_CONTOURS) != 0; | (pd->overlay.wpaint_flag & V3D_OVERLAY_WPAINT_CONTOURS) != 0; | ||||
| float opacity = 0.0f; | float opacity = 0.0f; | ||||
| pd->paint_depth_grp = NULL; | pd->paint_depth_grp = nullptr; | ||||
| psl->paint_depth_ps = NULL; | psl->paint_depth_ps = nullptr; | ||||
| switch (pd->ctx_mode) { | switch (pd->ctx_mode) { | ||||
| case CTX_MODE_POSE: | case CTX_MODE_POSE: | ||||
| case CTX_MODE_EDIT_MESH: | case CTX_MODE_EDIT_MESH: | ||||
| case CTX_MODE_PAINT_WEIGHT: { | case CTX_MODE_PAINT_WEIGHT: { | ||||
| opacity = is_edit_mode ? 1.0 : pd->overlay.weight_paint_mode_opacity; | opacity = is_edit_mode ? 1.0 : pd->overlay.weight_paint_mode_opacity; | ||||
| if (opacity > 0.0f) { | if (opacity > 0.0f) { | ||||
| state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND_ALPHA; | state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND_ALPHA; | ||||
| Show All 38 Lines | case CTX_MODE_PAINT_VERTEX: { | ||||
| DRW_shgroup_uniform_bool_copy(grp, "useAlphaBlend", pd->painting.alpha_blending); | DRW_shgroup_uniform_bool_copy(grp, "useAlphaBlend", pd->painting.alpha_blending); | ||||
| DRW_shgroup_uniform_float_copy(grp, "opacity", opacity); | DRW_shgroup_uniform_float_copy(grp, "opacity", opacity); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| case CTX_MODE_PAINT_TEXTURE: { | case CTX_MODE_PAINT_TEXTURE: { | ||||
| const ImagePaintSettings *imapaint = &draw_ctx->scene->toolsettings->imapaint; | const ImagePaintSettings *imapaint = &draw_ctx->scene->toolsettings->imapaint; | ||||
| const bool mask_enabled = imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL && | const bool mask_enabled = imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL && | ||||
| imapaint->stencil != NULL; | imapaint->stencil != nullptr; | ||||
| opacity = mask_enabled ? pd->overlay.texture_paint_mode_opacity : 0.0f; | opacity = mask_enabled ? pd->overlay.texture_paint_mode_opacity : 0.0f; | ||||
| if (opacity > 0.0f) { | if (opacity > 0.0f) { | ||||
| state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND_ALPHA; | state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND_ALPHA; | ||||
| DRW_PASS_CREATE(psl->paint_color_ps, state | pd->clipping_state); | DRW_PASS_CREATE(psl->paint_color_ps, state | pd->clipping_state); | ||||
| GPUTexture *tex = BKE_image_get_gpu_texture(imapaint->stencil, NULL, NULL); | GPUTexture *tex = BKE_image_get_gpu_texture(imapaint->stencil, nullptr, nullptr); | ||||
| const bool mask_premult = (imapaint->stencil->alpha_mode == IMA_ALPHA_PREMUL); | const bool mask_premult = (imapaint->stencil->alpha_mode == IMA_ALPHA_PREMUL); | ||||
| const bool mask_inverted = (imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL_INV) != 0; | const bool mask_inverted = (imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL_INV) != 0; | ||||
| sh = OVERLAY_shader_paint_texture(); | sh = OVERLAY_shader_paint_texture(); | ||||
| pd->paint_surf_grp = grp = DRW_shgroup_create(sh, psl->paint_color_ps); | pd->paint_surf_grp = grp = DRW_shgroup_create(sh, psl->paint_color_ps); | ||||
| DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | ||||
| DRW_shgroup_uniform_float_copy(grp, "opacity", opacity); | DRW_shgroup_uniform_float_copy(grp, "opacity", opacity); | ||||
| DRW_shgroup_uniform_bool_copy(grp, "maskPremult", mask_premult); | DRW_shgroup_uniform_bool_copy(grp, "maskPremult", mask_premult); | ||||
| DRW_shgroup_uniform_vec3_copy(grp, "maskColor", imapaint->stencil_col); | DRW_shgroup_uniform_vec3_copy(grp, "maskColor", imapaint->stencil_col); | ||||
| DRW_shgroup_uniform_bool_copy(grp, "maskInvertStencil", mask_inverted); | DRW_shgroup_uniform_bool_copy(grp, "maskInvertStencil", mask_inverted); | ||||
| DRW_shgroup_uniform_texture(grp, "maskImage", tex); | DRW_shgroup_uniform_texture(grp, "maskImage", tex); | ||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| default: | default: | ||||
| BLI_assert(0); | BLI_assert(0); | ||||
| break; | break; | ||||
| } | } | ||||
| if (opacity <= 0.0f) { | if (opacity <= 0.0f) { | ||||
| psl->paint_color_ps = NULL; | psl->paint_color_ps = nullptr; | ||||
| pd->paint_surf_grp = NULL; | pd->paint_surf_grp = nullptr; | ||||
| } | } | ||||
| { | { | ||||
| state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL; | state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL; | ||||
| DRW_PASS_CREATE(psl->paint_overlay_ps, state | pd->clipping_state); | DRW_PASS_CREATE(psl->paint_overlay_ps, state | pd->clipping_state); | ||||
| sh = OVERLAY_shader_paint_face(); | sh = OVERLAY_shader_paint_face(); | ||||
| pd->paint_face_grp = grp = DRW_shgroup_create(sh, psl->paint_overlay_ps); | pd->paint_face_grp = grp = DRW_shgroup_create(sh, psl->paint_overlay_ps); | ||||
| DRW_shgroup_uniform_vec4_copy(grp, "color", (float[4]){1.0f, 1.0f, 1.0f, 0.2f}); | const float4 color = {1.0f, 1.0f, 1.0f, 0.2f}; | ||||
| DRW_shgroup_uniform_vec4_copy(grp, "color", color); | |||||
| DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA); | DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA); | ||||
| sh = OVERLAY_shader_paint_wire(); | sh = OVERLAY_shader_paint_wire(); | ||||
| pd->paint_wire_selected_grp = grp = DRW_shgroup_create(sh, psl->paint_overlay_ps); | pd->paint_wire_selected_grp = grp = DRW_shgroup_create(sh, psl->paint_overlay_ps); | ||||
| DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | ||||
| DRW_shgroup_uniform_bool_copy(grp, "useSelect", true); | DRW_shgroup_uniform_bool_copy(grp, "useSelect", true); | ||||
| DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA); | DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA); | ||||
| pd->paint_wire_grp = grp = DRW_shgroup_create(sh, psl->paint_overlay_ps); | pd->paint_wire_grp = grp = DRW_shgroup_create(sh, psl->paint_overlay_ps); | ||||
| DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | ||||
| DRW_shgroup_uniform_bool_copy(grp, "useSelect", false); | DRW_shgroup_uniform_bool_copy(grp, "useSelect", false); | ||||
| DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA); | DRW_shgroup_state_enable(grp, DRW_STATE_BLEND_ALPHA); | ||||
| sh = OVERLAY_shader_paint_point(); | sh = OVERLAY_shader_paint_point(); | ||||
| pd->paint_point_grp = grp = DRW_shgroup_create(sh, psl->paint_overlay_ps); | pd->paint_point_grp = grp = DRW_shgroup_create(sh, psl->paint_overlay_ps); | ||||
| DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | DRW_shgroup_uniform_block(grp, "globalsBlock", G_draw.block_ubo); | ||||
| } | } | ||||
| } | } | ||||
| void OVERLAY_paint_texture_cache_populate(OVERLAY_Data *vedata, Object *ob) | void OVERLAY_paint_texture_cache_populate(OVERLAY_Data *vedata, Object *ob) | ||||
| { | { | ||||
| OVERLAY_PrivateData *pd = vedata->stl->pd; | OVERLAY_PrivateData *pd = vedata->stl->pd; | ||||
| struct GPUBatch *geom = NULL; | struct GPUBatch *geom = nullptr; | ||||
| const Mesh *me_orig = DEG_get_original_object(ob)->data; | const Mesh *me_orig = static_cast<Mesh *>(DEG_get_original_object(ob)->data); | ||||
| const bool use_face_sel = (me_orig->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; | const bool use_face_sel = (me_orig->editflag & ME_EDIT_PAINT_FACE_SEL) != 0; | ||||
| if (pd->paint_surf_grp) { | if (pd->paint_surf_grp) { | ||||
| geom = DRW_cache_mesh_surface_texpaint_single_get(ob); | geom = DRW_cache_mesh_surface_texpaint_single_get(ob); | ||||
| DRW_shgroup_call(pd->paint_surf_grp, geom, ob); | DRW_shgroup_call(pd->paint_surf_grp, geom, ob); | ||||
| } | } | ||||
| if (use_face_sel) { | if (use_face_sel) { | ||||
| geom = DRW_cache_mesh_surface_get(ob); | geom = DRW_cache_mesh_surface_get(ob); | ||||
| DRW_shgroup_call(pd->paint_face_grp, geom, ob); | DRW_shgroup_call(pd->paint_face_grp, geom, ob); | ||||
| } | } | ||||
| } | } | ||||
| void OVERLAY_paint_vertex_cache_populate(OVERLAY_Data *vedata, Object *ob) | void OVERLAY_paint_vertex_cache_populate(OVERLAY_Data *vedata, Object *ob) | ||||
| { | { | ||||
| OVERLAY_PrivateData *pd = vedata->stl->pd; | OVERLAY_PrivateData *pd = vedata->stl->pd; | ||||
| struct GPUBatch *geom = NULL; | struct GPUBatch *geom = nullptr; | ||||
| const Mesh *me_orig = DEG_get_original_object(ob)->data; | const Mesh *me_orig = static_cast<Mesh *>(DEG_get_original_object(ob)->data); | ||||
| const bool is_edit_mode = (pd->ctx_mode == CTX_MODE_EDIT_MESH); | const bool is_edit_mode = (pd->ctx_mode == CTX_MODE_EDIT_MESH); | ||||
| const bool use_wire = !is_edit_mode && (pd->overlay.paint_flag & V3D_OVERLAY_PAINT_WIRE); | const bool use_wire = !is_edit_mode && (pd->overlay.paint_flag & V3D_OVERLAY_PAINT_WIRE); | ||||
| const bool use_face_sel = !is_edit_mode && (me_orig->editflag & ME_EDIT_PAINT_FACE_SEL); | const bool use_face_sel = !is_edit_mode && (me_orig->editflag & ME_EDIT_PAINT_FACE_SEL); | ||||
| const bool use_vert_sel = !is_edit_mode && (me_orig->editflag & ME_EDIT_PAINT_VERT_SEL); | const bool use_vert_sel = !is_edit_mode && (me_orig->editflag & ME_EDIT_PAINT_VERT_SEL); | ||||
| if (ELEM(ob->mode, OB_MODE_WEIGHT_PAINT, OB_MODE_EDIT)) { | if (ELEM(ob->mode, OB_MODE_WEIGHT_PAINT, OB_MODE_EDIT)) { | ||||
| if (pd->paint_surf_grp) { | if (pd->paint_surf_grp) { | ||||
| geom = DRW_cache_mesh_surface_weights_get(ob); | geom = DRW_cache_mesh_surface_weights_get(ob); | ||||
| ▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines | |||||