Blender V4.3
overlay_mode_transfer.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2021 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BKE_object_types.hh"
10#include "BKE_paint.hh"
11
12#include "BLI_math_color.h"
13#include "BLI_time.h"
14
15#include "DRW_render.hh"
16
17#include "ED_view3d.hh"
18
19#include "UI_resources.hh"
20
21#include "overlay_private.hh"
22
24{
25 OVERLAY_PassList *psl = vedata->psl;
26 OVERLAY_PrivateData *pd = vedata->stl->pd;
27
29
30 for (int i = 0; i < 2; i++) {
31 /* Non Meshes Pass (Camera, empties, lights ...) */
34 }
35}
36
37#define MODE_TRANSFER_FLASH_LENGTH 0.55f
38/* TODO(pablodp606): Remove this option for 3.0 if fade in/out is not used. */
39#define MODE_TRANSFER_FLASH_FADE 0.0f
40#define MODE_TRANSFER_FLASH_MAX_ALPHA 0.25f
41
42static bool mode_transfer_is_animation_running(const float anim_time)
43{
44 return anim_time >= 0.0f && anim_time <= MODE_TRANSFER_FLASH_LENGTH;
45}
46
47static float mode_transfer_alpha_for_action_slot_time_get(const float anim_time)
48{
49 if (anim_time > MODE_TRANSFER_FLASH_LENGTH) {
50 return 0.0f;
51 }
52
53 if (anim_time < 0.0f) {
54 return 0.0f;
55 }
56
57 if (MODE_TRANSFER_FLASH_FADE <= 0.0f) {
58 return (1.0f - (anim_time / MODE_TRANSFER_FLASH_LENGTH)) * MODE_TRANSFER_FLASH_MAX_ALPHA;
59 }
60
61 const float flash_fade_in_time = MODE_TRANSFER_FLASH_LENGTH * MODE_TRANSFER_FLASH_FADE;
62 const float flash_fade_out_time = MODE_TRANSFER_FLASH_LENGTH - flash_fade_in_time;
63
64 float alpha = 0.0f;
65 if (anim_time < flash_fade_in_time) {
66 alpha = anim_time / flash_fade_in_time;
67 }
68 else {
69 const float fade_out_anim_time = anim_time - flash_fade_in_time;
70 alpha = 1.0f - (fade_out_anim_time / flash_fade_out_time);
71 }
72
73 return alpha * MODE_TRANSFER_FLASH_MAX_ALPHA;
74}
75
77{
78 OVERLAY_PrivateData *pd = vedata->stl->pd;
79 OVERLAY_PassList *psl = vedata->psl;
80
81 if (pd->xray_enabled) {
82 return;
83 }
84
85 const float animation_time = pd->mode_transfer.time -
86 ob->runtime->overlay_mode_transfer_start_time;
87
88 if (!mode_transfer_is_animation_running(animation_time)) {
89 return;
90 }
91
92 const DRWContextState *draw_ctx = DRW_context_state_get();
93 const bool use_sculpt_pbvh = BKE_sculptsession_use_pbvh_draw(ob, draw_ctx->rv3d) &&
95 const bool is_xray = (ob->dtx & OB_DRAW_IN_FRONT) != 0;
96
97 DRWShadingGroup *mode_transfer_grp[2];
98
99 for (int i = 0; i < 2; i++) {
101 mode_transfer_grp[i] = DRW_shgroup_create(sh, psl->mode_transfer_ps[i]);
102 DRW_shgroup_uniform_block(mode_transfer_grp[i], "globalsBlock", G_draw.block_ubo);
103
104 float color[4];
108 /* Alpha pre-multiply. */
109 mul_v3_fl(color, color[3]);
110 DRW_shgroup_uniform_vec4_copy(mode_transfer_grp[i], "ucolor", color);
111 }
112
113 if (!pd->use_in_front) {
114 mode_transfer_grp[IN_FRONT] = mode_transfer_grp[NOT_IN_FRONT];
115 }
116
117 pd->mode_transfer.any_animated = true;
118
119 if (use_sculpt_pbvh) {
120 DRW_shgroup_call_sculpt(mode_transfer_grp[is_xray], ob, false, false, false, false, false);
121 }
122 else {
123 blender::gpu::Batch *geom = DRW_cache_object_surface_get(ob);
124 if (geom) {
125 DRW_shgroup_call(mode_transfer_grp[is_xray], geom, ob);
126 }
127 }
128}
129
136
143
bool BKE_sculptsession_use_pbvh_draw(const Object *ob, const RegionView3D *rv3d)
Definition paint.cc:2862
MINLINE void srgb_to_linearrgb_v4(float linear[4], const float srgb[4])
MINLINE void mul_v3_fl(float r[3], float f)
Platform independent time functions.
double BLI_time_now_seconds(void)
Definition time.c:65
@ OB_DRAW_IN_FRONT
#define DRW_PASS_CREATE(pass, state)
#define DRW_shgroup_uniform_block(shgroup, name, ubo)
#define DRW_shgroup_call(shgroup, geom, ob)
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert Invert a color
void UI_GetThemeColor3fv(int colorid, float col[3])
@ TH_VERTEX_SELECT
struct GPUShader GPUShader
blender::gpu::Batch * DRW_cache_object_surface_get(Object *ob)
DRW_Global G_draw
bool DRW_state_is_image_render()
const DRWContextState * DRW_context_state_get()
void DRW_viewport_request_redraw()
DRWShadingGroup * DRW_shgroup_create(GPUShader *shader, DRWPass *pass)
void DRW_shgroup_call_sculpt(DRWShadingGroup *shgroup, Object *ob, bool use_wire, bool use_mask, bool use_fset, bool use_color, bool use_uv)
void DRW_shgroup_uniform_vec4_copy(DRWShadingGroup *shgroup, const char *name, const float *value)
void DRW_draw_pass(DRWPass *pass)
DRWState
Definition draw_state.hh:25
@ DRW_STATE_WRITE_DEPTH
Definition draw_state.hh:29
@ DRW_STATE_WRITE_COLOR
Definition draw_state.hh:30
@ DRW_STATE_DEPTH_LESS_EQUAL
Definition draw_state.hh:38
static ulong state[N]
void OVERLAY_mode_transfer_cache_init(OVERLAY_Data *vedata)
#define MODE_TRANSFER_FLASH_LENGTH
static bool mode_transfer_is_animation_running(const float anim_time)
static float mode_transfer_alpha_for_action_slot_time_get(const float anim_time)
#define MODE_TRANSFER_FLASH_FADE
void OVERLAY_mode_transfer_cache_finish(OVERLAY_Data *vedata)
#define MODE_TRANSFER_FLASH_MAX_ALPHA
void OVERLAY_mode_transfer_cache_populate(OVERLAY_Data *vedata, Object *ob)
void OVERLAY_mode_transfer_infront_draw(OVERLAY_Data *vedata)
void OVERLAY_mode_transfer_draw(OVERLAY_Data *vedata)
GPUShader * OVERLAY_shader_uniform_color()
#define IN_FRONT
#define NOT_IN_FRONT
RegionView3D * rv3d
OVERLAY_PassList * psl
OVERLAY_StorageList * stl
DRWPass * mode_transfer_ps[2]
struct OVERLAY_PrivateData::@302134015166353136115217061342247117056032154062 mode_transfer
OVERLAY_PrivateData * pd
ObjectRuntimeHandle * runtime