Anim: Time Offset Slider #110540

Merged
Christoph Lendenfeld merged 21 commits from ChrisLend/blender:time_offset_slider into main 2023-09-21 15:11:25 +02:00
19 changed files with 306 additions and 45 deletions
Showing only changes of commit f4d201e3ba - Show all commits

View File

@ -786,6 +786,7 @@ macro(remove_strict_flags)
if(CMAKE_COMPILER_IS_GNUCC)
remove_cc_flag(
"-Wstrict-prototypes"
"-Wsuggest-attribute=format"
"-Wmissing-prototypes"
"-Wmissing-declarations"
"-Wmissing-format-attribute"

View File

@ -1392,6 +1392,11 @@ static void ghost_wl_display_report_error(wl_display *display)
::exit(-1);
}
#ifdef __GNUC__
static void ghost_wayland_log_handler(const char *msg, va_list arg)
__attribute__((format(printf, 1, 0)));
#endif
/**
* Callback for WAYLAND to run when there is an error.
*

View File

@ -301,6 +301,7 @@ class GRAPH_MT_key_blending(Menu):
layout.operator("graph.ease", text="Ease")
layout.operator("graph.blend_offset", text="Blend Offset")
layout.operator("graph.blend_to_ease", text="Blend to Ease")
layout.operator("graph.match_slope", text="Match Slope")
layout.operator("graph.time_offset", text="Time Offset")

View File

@ -774,6 +774,58 @@ void blend_to_ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const flo
/* ---------------- */
bool match_slope_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float factor)
{
const BezTriple *left_key = fcurve_segment_start_get(fcu, segment->start_index);
const BezTriple *right_key = fcurve_segment_end_get(fcu, segment->start_index + segment->length);
BezTriple beyond_key;
const BezTriple *reference_key;
if (factor >= 0) {
/* Stop the function if there is no key beyond the the right neighboring one. */
if (segment->start_index + segment->length >= fcu->totvert - 1) {
return false;
}
reference_key = right_key;
beyond_key = fcu->bezt[segment->start_index + segment->length + 1];
}
else {
/* Stop the function if there is no key beyond the left neighboring one. */
if (segment->start_index <= 1) {
return false;
}
reference_key = left_key;
beyond_key = fcu->bezt[segment->start_index - 2];
}
/* This delta values are used to get the relationship between the bookend keys and the
* reference keys beyong those. */
const float y_delta = beyond_key.vec[1][1] - reference_key->vec[1][1];
const float x_delta = beyond_key.vec[1][0] - reference_key->vec[1][0];
/* Avoids dividing by 0. */
if (x_delta == 0) {
return false;
}
for (int i = segment->start_index; i < segment->start_index + segment->length; i++) {
/* These new deltas are used to determine the relationship between the current key and the
* bookend ones. */
const float new_x_delta = fcu->bezt[i].vec[1][0] - reference_key->vec[1][0];
const float new_y_delta = new_x_delta * y_delta / x_delta;
const float delta = reference_key->vec[1][1] + new_y_delta - fcu->bezt[i].vec[1][1];
const float key_y_value = fcu->bezt[i].vec[1][1] + delta * fabs(factor);
BKE_fcurve_keyframe_move_value_with_handles(&fcu->bezt[i], key_y_value);
}
return true;
}
/* ---------------- */
void time_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, const float frame_offset)
{
/* Two bookend keys of the fcurve are needed to be able to cycle the values. */

View File

@ -469,6 +469,7 @@ void blend_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, float fact
void blend_to_ease_fcurve_segment(FCurve *fcu, FCurveSegment *segment, float factor);
void time_offset_fcurve_segment(FCurve *fcu, FCurveSegment *segment, float frame_offset);
bool decimate_fcurve(bAnimListElem *ale, float remove_ratio, float error_sq_max);
bool match_slope_fcurve_segment(FCurve *fcu, FCurveSegment *segment, float factor);
/**
* Blends the selected keyframes to the default value of the property the F-curve drives.

View File

@ -1405,6 +1405,8 @@ static int make_links_scene_exec(bContext *C, wmOperator *op)
}
CTX_DATA_END;
DEG_id_tag_update(&collection_to->id, ID_RECALC_HIERARCHY);
DEG_relations_tag_update(bmain);
/* redraw the 3D view because the object center points are colored differently */

View File

@ -121,6 +121,7 @@ void GRAPH_OT_breakdown(struct wmOperatorType *ot);
void GRAPH_OT_ease(struct wmOperatorType *ot);
void GRAPH_OT_blend_offset(struct wmOperatorType *ot);
void GRAPH_OT_blend_to_ease(struct wmOperatorType *ot);
void GRAPH_OT_match_slope(struct wmOperatorType *ot);
void GRAPH_OT_time_offset(struct wmOperatorType *ot);
void GRAPH_OT_decimate(struct wmOperatorType *ot);
void GRAPH_OT_blend_to_default(struct wmOperatorType *ot);

View File

@ -471,6 +471,7 @@ void graphedit_operatortypes()
WM_operatortype_append(GRAPH_OT_ease);
WM_operatortype_append(GRAPH_OT_blend_offset);
WM_operatortype_append(GRAPH_OT_blend_to_ease);
WM_operatortype_append(GRAPH_OT_match_slope);
WM_operatortype_append(GRAPH_OT_time_offset);
WM_operatortype_append(GRAPH_OT_blend_to_default);
WM_operatortype_append(GRAPH_OT_gaussian_smooth);

View File

@ -1166,6 +1166,126 @@ void GRAPH_OT_blend_to_ease(wmOperatorType *ot)
1.0f);
}
/* -------------------------------------------------------------------- */
/** \name Match Slope
* \{ */
static void match_slope_graph_keys(bAnimContext *ac, const float factor)
{
ListBase anim_data = {NULL, NULL};
bool all_segments_valid = true;
ANIM_animdata_filter(
ac, &anim_data, OPERATOR_DATA_FILTER, ac->data, eAnimCont_Types(ac->datatype));
LISTBASE_FOREACH (bAnimListElem *, ale, &anim_data) {
FCurve *fcu = (FCurve *)ale->key_data;
ListBase segments = find_fcurve_segments(fcu);
LISTBASE_FOREACH (FCurveSegment *, segment, &segments) {
all_segments_valid = match_slope_fcurve_segment(fcu, segment, factor);
}
ale->update |= ANIM_UPDATE_DEFAULT;
BLI_freelistN(&segments);
}
if (!all_segments_valid) {
if (factor >= 0) {
WM_report(RPT_WARNING, "You need at least 2 keys to the right side of the selection.");
}
else {
WM_report(RPT_WARNING, "You need at least 2 keys to the left side of the selection.");
}
}
ANIM_animdata_update(ac, &anim_data);
ANIM_animdata_freelist(&anim_data);
}
static void match_slope_draw_status_header(bContext *C, tGraphSliderOp *gso)
{
common_draw_status_header(C, gso, "Match Slope");
}
static void match_slope_modal_update(bContext *C, wmOperator *op)
{
tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
match_slope_draw_status_header(C, gso);
/* Reset keyframes to the state at invoke. */
reset_bezts(gso);
const float factor = slider_factor_get_and_remember(op);
match_slope_graph_keys(&gso->ac, factor);
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
}
static int match_slope_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
const int invoke_result = graph_slider_invoke(C, op, event);
if (invoke_result == OPERATOR_CANCELLED) {
return invoke_result;
}
tGraphSliderOp *gso = static_cast<tGraphSliderOp *>(op->customdata);
gso->modal_update = match_slope_modal_update;
gso->factor_prop = RNA_struct_find_property(op->ptr, "factor");
match_slope_draw_status_header(C, gso);
ED_slider_allow_overshoot_set(gso->slider, false, false);
ED_slider_factor_bounds_set(gso->slider, -1, 1);
ED_slider_factor_set(gso->slider, 0.0f);
return invoke_result;
}
static int match_slope_exec(bContext *C, wmOperator *op)
{
bAnimContext ac;
/* Get editor data. */
if (ANIM_animdata_get_context(C, &ac) == 0) {
return OPERATOR_CANCELLED;
}
const float factor = RNA_float_get(op->ptr, "factor");
match_slope_graph_keys(&ac, factor);
/* Set notifier that keyframes have changed. */
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
void GRAPH_OT_match_slope(wmOperatorType *ot)
{
/* Identifiers. */
ot->name = "Match Slope";
ot->idname = "GRAPH_OT_match_slope";
ot->description = "Blend selected keys to the slope of neighboring ones";
/* API callbacks. */
ot->invoke = match_slope_invoke;
ot->modal = graph_slider_modal;
ot->exec = match_slope_exec;
ot->poll = graphop_editable_keyframes_poll;
/* Flags. */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_float_factor(ot->srna,
"factor",
0.0f,
-FLT_MAX,
FLT_MAX,
"Factor",
"Defines which keys to use as slope and how much to blend towards them",
-1.0f,
1.0f);
}
/* -------------------------------------------------------------------- */
/** \name Time Offset
* \{ */

View File

@ -33,6 +33,64 @@ using InterfaceDictionnary = Map<StringRef, StageInterfaceInfo *>;
static CreateInfoDictionnary *g_create_infos = nullptr;
static InterfaceDictionnary *g_interfaces = nullptr;
/* -------------------------------------------------------------------- */
/** \name Check Backend Support
*
* \{ */
static bool is_vulkan_compatible_interface(const StageInterfaceInfo &iface)
{
if (iface.instance_name.is_empty()) {
return true;
}
bool use_flat = false;
bool use_smooth = false;
bool use_noperspective = false;
for (const StageInterfaceInfo::InOut &attr : iface.inouts) {
switch (attr.interp) {
case Interpolation::FLAT:
use_flat = true;
break;
case Interpolation::SMOOTH:
use_smooth = true;
break;
case Interpolation::NO_PERSPECTIVE:
use_noperspective = true;
break;
}
}
int num_used_interpolation_types = (use_flat ? 1 : 0) + (use_smooth ? 1 : 0) +
(use_noperspective ? 1 : 0);
#if 0
if (num_used_interpolation_types > 1) {
std::cout << "'" << iface.name << "' uses multiple interpolation types\n";
}
#endif
return num_used_interpolation_types <= 1;
}
bool ShaderCreateInfo::is_vulkan_compatible() const
{
/* Vulkan doesn't support setting an interpolation mode per attribute in a struct. */
for (const StageInterfaceInfo *iface : vertex_out_interfaces_) {
if (!is_vulkan_compatible_interface(*iface)) {
return false;
}
}
for (const StageInterfaceInfo *iface : geometry_out_interfaces_) {
if (!is_vulkan_compatible_interface(*iface)) {
return false;
}
}
return true;
}
/** \} */
void ShaderCreateInfo::finalize()
{
if (finalized_) {

View File

@ -882,6 +882,7 @@ struct ShaderCreateInfo {
void finalize();
std::string check_error() const;
bool is_vulkan_compatible() const;
/** Error detection that some backend compilers do not complain about. */
void validate_merge(const ShaderCreateInfo &other_info);

View File

@ -221,7 +221,7 @@ void Shader::print_log(Span<const char *> sources,
if (log_item.severity == Severity::Error) {
BLI_dynstr_appendf(dynstr, "%s%s%s: ", err_col, "Error", info_col);
}
else if (log_item.severity == Severity::Error) {
else if (log_item.severity == Severity::Warning) {
BLI_dynstr_appendf(dynstr, "%s%s%s: ", warn_col, "Warning", info_col);
}
else if (log_item.severity == Severity::Note) {

View File

@ -9,7 +9,8 @@ void main()
#endif
fragColor = interp.final_color;
if (lineSmooth) {
fragColor.a *= clamp((lineWidth + SMOOTH_WIDTH) * 0.5 - abs(interp.smoothline), 0.0, 1.0);
fragColor.a *= clamp(
(lineWidth + SMOOTH_WIDTH) * 0.5 - abs(interp_noperspective.smoothline), 0.0, 1.0);
}
fragColor = blender_srgb_to_framebuffer_space(fragColor);
}

View File

@ -32,12 +32,12 @@ void do_vertex(const int i, vec4 pos, vec2 ofs)
interp_out.clip = interp_in[i].clip;
#endif
interp_out.smoothline = (lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5;
interp_noperspective_out.smoothline = (lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5;
gl_Position = pos;
gl_Position.xy += ofs * pos.w;
EmitVertex();
interp_out.smoothline = -(lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5;
interp_noperspective_out.smoothline = -(lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5;
gl_Position = pos;
gl_Position.xy -= ofs * pos.w;
EmitVertex();

View File

@ -45,7 +45,7 @@ void do_vertex(int index, vec4 pos, vec2 ofs, float flip)
interp.clip = clip_g[index];
#endif
interp.smoothline = flip * (lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5;
interp_noperspective.smoothline = flip * (lineWidth + SMOOTH_WIDTH * float(lineSmooth)) * 0.5;
gl_Position = pos;
gl_Position.xy += flip * ofs * pos.w;
}

View File

@ -11,7 +11,9 @@
GPU_SHADER_INTERFACE_INFO(gpu_shader_3D_polyline_iface, "interp")
.smooth(Type::VEC4, "final_color")
.smooth(Type::FLOAT, "clip")
.smooth(Type::FLOAT, "clip");
GPU_SHADER_INTERFACE_INFO(gpu_shader_3D_polyline_noperspective_iface, "interp_noperspective")
.no_perspective(Type::FLOAT, "smoothline");
GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline)
@ -22,8 +24,10 @@ GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline)
.push_constant(Type::BOOL, "lineSmooth")
.vertex_in(0, Type::VEC3, "pos")
.vertex_out(gpu_shader_3D_polyline_iface)
.vertex_out(gpu_shader_3D_polyline_noperspective_iface)
.geometry_layout(PrimitiveIn::LINES, PrimitiveOut::TRIANGLE_STRIP, 4)
.geometry_out(gpu_shader_3D_polyline_iface)
.geometry_out(gpu_shader_3D_polyline_noperspective_iface)
.fragment_out(0, Type::VEC4, "fragColor")
.vertex_source("gpu_shader_3D_polyline_vert.glsl")
.geometry_source("gpu_shader_3D_polyline_geom.glsl")
@ -38,6 +42,7 @@ GPU_SHADER_CREATE_INFO(gpu_shader_3D_polyline_no_geom)
.push_constant(Type::BOOL, "lineSmooth")
.vertex_in(0, Type::VEC3, "pos")
.vertex_out(gpu_shader_3D_polyline_iface)
.vertex_out(gpu_shader_3D_polyline_noperspective_iface)
.fragment_out(0, Type::VEC4, "fragColor")
.vertex_source("gpu_shader_3D_polyline_vert_no_geom.glsl")
.fragment_source("gpu_shader_3D_polyline_frag.glsl")

View File

@ -399,6 +399,47 @@ inline int get_location_count(const Type &type)
return 1;
}
static void print_interface_as_attributes(std::ostream &os,
const std::string &prefix,
const StageInterfaceInfo &iface,
int &location)
{
for (const StageInterfaceInfo::InOut &inout : iface.inouts) {
os << "layout(location=" << location << ") " << prefix << " " << to_string(inout.interp) << " "
<< to_string(inout.type) << " " << inout.name << ";\n";
location += get_location_count(inout.type);
}
}
static void print_interface_as_struct(std::ostream &os,
const std::string &prefix,
const StageInterfaceInfo &iface,
int &location,
const StringRefNull &suffix)
{
std::string struct_name = prefix + iface.name;
Interpolation qualifier = iface.inouts[0].interp;
/* Workaround for shader that have not been converted yet. */
for (const StageInterfaceInfo::InOut &inout : iface.inouts) {
if (inout.interp == Interpolation::FLAT) {
qualifier = Interpolation::FLAT;
}
}
os << "struct " << struct_name << " {\n";
for (const StageInterfaceInfo::InOut &inout : iface.inouts) {
os << " " << to_string(inout.type) << " " << inout.name << ";\n";
}
os << "};\n";
os << "layout(location=" << location << ") " << prefix << " " << to_string(qualifier) << " "
<< struct_name << " " << iface.instance_name << suffix << ";\n";
for (const StageInterfaceInfo::InOut &inout : iface.inouts) {
location += get_location_count(inout.type);
}
}
static void print_interface(std::ostream &os,
const std::string &prefix,
const StageInterfaceInfo &iface,
@ -406,44 +447,10 @@ static void print_interface(std::ostream &os,
const StringRefNull &suffix = "")
{
if (iface.instance_name.is_empty()) {
for (const StageInterfaceInfo::InOut &inout : iface.inouts) {
os << "layout(location=" << location << ") " << prefix << " " << to_string(inout.interp)
<< " " << to_string(inout.type) << " " << inout.name << ";\n";
location += get_location_count(inout.type);
}
print_interface_as_attributes(os, prefix, iface, location);
}
else {
std::string struct_name = prefix + iface.name;
std::string iface_attribute;
if (iface.instance_name.is_empty()) {
iface_attribute = "iface_";
}
else {
iface_attribute = iface.instance_name;
}
std::string flat = "";
if (prefix == "in") {
flat = "flat ";
}
const bool add_defines = iface.instance_name.is_empty();
os << "struct " << struct_name << " {\n";
for (const StageInterfaceInfo::InOut &inout : iface.inouts) {
os << " " << to_string(inout.type) << " " << inout.name << ";\n";
}
os << "};\n";
os << "layout(location=" << location << ") " << prefix << " " << flat << struct_name << " "
<< iface_attribute << suffix << ";\n";
if (add_defines) {
for (const StageInterfaceInfo::InOut &inout : iface.inouts) {
os << "#define " << inout.name << " (" << iface_attribute << "." << inout.name << ")\n";
}
}
for (const StageInterfaceInfo::InOut &inout : iface.inouts) {
location += get_location_count(inout.type);
}
print_interface_as_struct(os, prefix, iface, location, suffix);
}
}
@ -656,6 +663,11 @@ bool VKShader::finalize(const shader::ShaderCreateInfo *info)
if (compilation_failed_) {
return false;
}
#if DEBUG
if (!info->is_vulkan_compatible()) {
std::cout << "'" << info->name_ << "' stage interfaces are not compatible with Vulkan.\n";
}
#endif
VKShaderInterface *vk_interface = new VKShaderInterface();
vk_interface->init(*info);

View File

@ -1355,7 +1355,7 @@ bool IMB_colormanagement_space_is_data(ColorSpace *colorspace)
static void colormanage_ensure_srgb_scene_linear_info(ColorSpace *colorspace)
{
if (!colorspace->info.cached) {
if (colorspace && !colorspace->info.cached) {
OCIO_ConstConfigRcPtr *config = OCIO_getCurrentConfig();
OCIO_ConstColorSpaceRcPtr *ocio_colorspace = OCIO_configGetColorSpace(config,
colorspace->name);

View File

@ -83,10 +83,10 @@ static void window_manager_foreach_id(ID *id, LibraryForeachIDData *data)
if (BKE_lib_query_foreachid_iter_stop(data)) {
return;
}
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, win->unpinned_scene, IDWALK_CB_NOP);
}
BKE_LIB_FOREACHID_PROCESS_IDSUPER(data, win->unpinned_scene, IDWALK_CB_NOP);
if (BKE_lib_query_foreachid_process_flags_get(data) & IDWALK_INCLUDE_UI) {
LISTBASE_FOREACH (ScrArea *, area, &win->global_areas.areabase) {
BKE_LIB_FOREACHID_PROCESS_FUNCTION_CALL(data,