diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..d7e326e7 --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: InheritParentConfig +ColumnLimit: 132 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index ce97a7e2..8d05ca0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,10 +51,6 @@ elseif(OS_MACOS) target_compile_options(${PROJECT_NAME} PRIVATE -Wall) endif() -# lines if you want add Qt UI in your plugin -find_qt(COMPONENTS Widgets COMPONENTS_LINUX Gui) -set_target_properties(${PROJECT_NAME} PROPERTIES AUTOMOC ON AUTOUIC ON AUTORCC ON) - target_link_libraries(${PROJECT_NAME} OBS::libobs) diff --git a/obs-shaderfilter.c b/obs-shaderfilter.c index 94117b90..be049315 100644 --- a/obs-shaderfilter.c +++ b/obs-shaderfilter.c @@ -225,8 +225,7 @@ static unsigned int rand_interval(unsigned int min, unsigned int max) return min + (r / buckets); } -static char * -load_shader_from_file(const char *file_name) // add input of visited files +static char *load_shader_from_file(const char *file_name) // add input of visited files { char *file_ptr = os_quick_read_utf8_file(file_name); @@ -250,10 +249,8 @@ load_shader_from_file(const char *file_name) // add input of visited files char *end = strrchr(line, '"'); dstr_ncat(&include_path, start, end - start); - char *abs_include_path = - os_get_abs_path_ptr(include_path.array); - char *file_contents = - load_shader_from_file(abs_include_path); + char *abs_include_path = os_get_abs_path_ptr(include_path.array); + char *file_contents = load_shader_from_file(abs_include_path); dstr_cat(&shader_file, file_contents); dstr_cat(&shader_file, "\n"); bfree(abs_include_path); @@ -304,8 +301,7 @@ static void shader_filter_clear_params(struct shader_filter_data *filter) size_t param_count = filter->stored_param_list.num; for (size_t param_index = 0; param_index < param_count; param_index++) { - struct effect_param_data *param = - (filter->stored_param_list.array + param_index); + struct effect_param_data *param = (filter->stored_param_list.array + param_index); if (param->image) { obs_enter_graphics(); gs_image_file_free(param->image); @@ -315,16 +311,11 @@ static void shader_filter_clear_params(struct shader_filter_data *filter) param->image = NULL; } if (param->source) { - obs_source_t *source = - obs_weak_source_get_source(param->source); + obs_source_t *source = obs_weak_source_get_source(param->source); if (source) { - if ((!filter->transition || - filter->prev_transitioning) && - obs_source_active(filter->context)) + if ((!filter->transition || filter->prev_transitioning) && obs_source_active(filter->context)) obs_source_dec_active(source); - if ((!filter->transition || - filter->prev_transitioning) && - obs_source_showing(filter->context)) + if ((!filter->transition || filter->prev_transitioning) && obs_source_showing(filter->context)) obs_source_dec_showing(source); obs_source_release(source); } @@ -376,18 +367,13 @@ static void load_output_effect(struct shader_filter_data *filter) bfree(shader_text); if (filter->output_effect == NULL) { - blog(LOG_WARNING, - "[obs-shaderfilter] Unable to load output.effect file. Errors:\n%s", - (errors == NULL || strlen(errors) == 0 ? "(None)" - : errors)); + blog(LOG_WARNING, "[obs-shaderfilter] Unable to load output.effect file. Errors:\n%s", + (errors == NULL || strlen(errors) == 0 ? "(None)" : errors)); bfree(errors); } else { - size_t effect_count = - gs_effect_get_num_params(filter->output_effect); - for (size_t effect_index = 0; effect_index < effect_count; - effect_index++) { - gs_eparam_t *param = gs_effect_get_param_by_idx( - filter->output_effect, effect_index); + size_t effect_count = gs_effect_get_num_params(filter->output_effect); + for (size_t effect_index = 0; effect_index < effect_count; effect_index++) { + gs_eparam_t *param = gs_effect_get_param_by_idx(filter->output_effect, effect_index); struct gs_effect_param_info info; gs_effect_get_param_info(param, &info); if (strcmp(info.name, "output_image") == 0) { @@ -414,16 +400,13 @@ static void shader_filter_reload_effect(struct shader_filter_data *filter) // Load text and build the effect from the template, if necessary. char *shader_text = NULL; - bool use_template = - !obs_data_get_bool(settings, "override_entire_effect"); + bool use_template = !obs_data_get_bool(settings, "override_entire_effect"); if (obs_data_get_bool(settings, "from_file")) { - const char *file_name = - obs_data_get_string(settings, "shader_file_name"); + const char *file_name = obs_data_get_string(settings, "shader_file_name"); shader_text = load_shader_from_file(file_name); } else { - shader_text = - bstrdup(obs_data_get_string(settings, "shader_text")); + shader_text = bstrdup(obs_data_get_string(settings, "shader_text")); use_template = true; } @@ -452,8 +435,7 @@ static void shader_filter_reload_effect(struct shader_filter_data *filter) dstr_insert(&effect_text, 0, "#define OPENGL 1\n"); } - if (effect_text.len && - dstr_find(&effect_text, "#define USE_PM_ALPHA 1")) { + if (effect_text.len && dstr_find(&effect_text, "#define USE_PM_ALPHA 1")) { filter->use_pm_alpha = true; } else { filter->use_pm_alpha = false; @@ -465,16 +447,12 @@ static void shader_filter_reload_effect(struct shader_filter_data *filter) obs_leave_graphics(); if (filter->effect == NULL) { - blog(LOG_WARNING, - "[obs-shaderfilter] Unable to create effect. Errors returned from parser:\n%s", - (errors == NULL || strlen(errors) == 0 ? "(None)" - : errors)); + blog(LOG_WARNING, "[obs-shaderfilter] Unable to create effect. Errors returned from parser:\n%s", + (errors == NULL || strlen(errors) == 0 ? "(None)" : errors)); if (errors && strlen(errors)) { obs_data_set_string(settings, "last_error", errors); } else { - obs_data_set_string( - settings, "last_error", - obs_module_text("ShaderFilter.Unknown")); + obs_data_set_string(settings, "last_error", obs_module_text("ShaderFilter.Unknown")); } dstr_free(&effect_text); bfree(errors); @@ -488,10 +466,8 @@ static void shader_filter_reload_effect(struct shader_filter_data *filter) da_free(filter->stored_param_list); size_t effect_count = gs_effect_get_num_params(filter->effect); - for (size_t effect_index = 0; effect_index < effect_count; - effect_index++) { - gs_eparam_t *param = gs_effect_get_param_by_idx(filter->effect, - effect_index); + for (size_t effect_index = 0; effect_index < effect_count; effect_index++) { + gs_eparam_t *param = gs_effect_get_param_by_idx(filter->effect, effect_index); struct gs_effect_param_info info; gs_effect_get_param_info(param, &info); @@ -520,123 +496,66 @@ static void shader_filter_reload_effect(struct shader_filter_data *filter) // Nothing. } else if (strcmp(info.name, "image") == 0) { filter->param_image = param; - } else if (filter->transition && - strcmp(info.name, "image_a") == 0) { + } else if (filter->transition && strcmp(info.name, "image_a") == 0) { filter->param_image_a = param; - } else if (filter->transition && - strcmp(info.name, "image_b") == 0) { + } else if (filter->transition && strcmp(info.name, "image_b") == 0) { filter->param_image_b = param; - } else if (filter->transition && - strcmp(info.name, "transition_time") == 0) { + } else if (filter->transition && strcmp(info.name, "transition_time") == 0) { filter->param_transition_time = param; - } else if (filter->transition && - strcmp(info.name, "convert_linear") == 0) { + } else if (filter->transition && strcmp(info.name, "convert_linear") == 0) { filter->param_convert_linear = param; } else { - struct effect_param_data *cached_data = - da_push_back_new(filter->stored_param_list); + struct effect_param_data *cached_data = da_push_back_new(filter->stored_param_list); dstr_copy(&cached_data->name, info.name); cached_data->type = info.type; cached_data->param = param; da_init(cached_data->option_values); da_init(cached_data->option_labels); - const size_t annotation_count = - gs_param_get_num_annotations(param); - for (size_t annotation_index = 0; - annotation_index < annotation_count; - annotation_index++) { - gs_eparam_t *annotation = - gs_param_get_annotation_by_idx( - param, annotation_index); - void *annotation_default = - gs_effect_get_default_val(annotation); + const size_t annotation_count = gs_param_get_num_annotations(param); + for (size_t annotation_index = 0; annotation_index < annotation_count; annotation_index++) { + gs_eparam_t *annotation = gs_param_get_annotation_by_idx(param, annotation_index); + void *annotation_default = gs_effect_get_default_val(annotation); gs_effect_get_param_info(annotation, &info); - if (strcmp(info.name, "name") == 0 && - info.type == GS_SHADER_PARAM_STRING) { - dstr_copy(&cached_data->display_name, - (const char *) - annotation_default); - } else if (strcmp(info.name, "label") == 0 && - info.type == - GS_SHADER_PARAM_STRING) { - dstr_copy(&cached_data->display_name, - (const char *) - annotation_default); - } else if (strcmp(info.name, "widget_type") == - 0 && - info.type == - GS_SHADER_PARAM_STRING) { - dstr_copy(&cached_data->widget_type, - (const char *) - annotation_default); - } else if (strcmp(info.name, "group") == 0 && - info.type == - GS_SHADER_PARAM_STRING) { - dstr_copy(&cached_data->group, - (const char *) - annotation_default); + if (strcmp(info.name, "name") == 0 && info.type == GS_SHADER_PARAM_STRING) { + dstr_copy(&cached_data->display_name, (const char *)annotation_default); + } else if (strcmp(info.name, "label") == 0 && info.type == GS_SHADER_PARAM_STRING) { + dstr_copy(&cached_data->display_name, (const char *)annotation_default); + } else if (strcmp(info.name, "widget_type") == 0 && info.type == GS_SHADER_PARAM_STRING) { + dstr_copy(&cached_data->widget_type, (const char *)annotation_default); + } else if (strcmp(info.name, "group") == 0 && info.type == GS_SHADER_PARAM_STRING) { + dstr_copy(&cached_data->group, (const char *)annotation_default); } else if (strcmp(info.name, "minimum") == 0) { - if (info.type == - GS_SHADER_PARAM_FLOAT || - info.type == GS_SHADER_PARAM_VEC2 || - info.type == GS_SHADER_PARAM_VEC3 || - info.type == GS_SHADER_PARAM_VEC4) { - cached_data->minimum.f = *( - float *)annotation_default; - } else if (info.type == - GS_SHADER_PARAM_INT) { - cached_data->minimum.i = *( - int *)annotation_default; + if (info.type == GS_SHADER_PARAM_FLOAT || info.type == GS_SHADER_PARAM_VEC2 || + info.type == GS_SHADER_PARAM_VEC3 || info.type == GS_SHADER_PARAM_VEC4) { + cached_data->minimum.f = *(float *)annotation_default; + } else if (info.type == GS_SHADER_PARAM_INT) { + cached_data->minimum.i = *(int *)annotation_default; } } else if (strcmp(info.name, "maximum") == 0) { - if (info.type == - GS_SHADER_PARAM_FLOAT || - info.type == GS_SHADER_PARAM_VEC2 || - info.type == GS_SHADER_PARAM_VEC3 || - info.type == GS_SHADER_PARAM_VEC4) { - cached_data->maximum.f = *( - float *)annotation_default; - } else if (info.type == - GS_SHADER_PARAM_INT) { - cached_data->maximum.i = *( - int *)annotation_default; + if (info.type == GS_SHADER_PARAM_FLOAT || info.type == GS_SHADER_PARAM_VEC2 || + info.type == GS_SHADER_PARAM_VEC3 || info.type == GS_SHADER_PARAM_VEC4) { + cached_data->maximum.f = *(float *)annotation_default; + } else if (info.type == GS_SHADER_PARAM_INT) { + cached_data->maximum.i = *(int *)annotation_default; } } else if (strcmp(info.name, "step") == 0) { - if (info.type == - GS_SHADER_PARAM_FLOAT || - info.type == GS_SHADER_PARAM_VEC2 || - info.type == GS_SHADER_PARAM_VEC3 || - info.type == GS_SHADER_PARAM_VEC4) { - cached_data->step.f = *( - float *)annotation_default; - } else if (info.type == - GS_SHADER_PARAM_INT) { - cached_data->step.i = *( - int *)annotation_default; + if (info.type == GS_SHADER_PARAM_FLOAT || info.type == GS_SHADER_PARAM_VEC2 || + info.type == GS_SHADER_PARAM_VEC3 || info.type == GS_SHADER_PARAM_VEC4) { + cached_data->step.f = *(float *)annotation_default; + } else if (info.type == GS_SHADER_PARAM_INT) { + cached_data->step.i = *(int *)annotation_default; } - } else if (strncmp(info.name, "option_", 7) == - 0) { + } else if (strncmp(info.name, "option_", 7) == 0) { int id = atoi(info.name + 7); if (info.type == GS_SHADER_PARAM_INT) { - int val = *( - int *)annotation_default; - int *cd = da_insert_new( - cached_data - ->option_values, - id); + int val = *(int *)annotation_default; + int *cd = da_insert_new(cached_data->option_values, id); *cd = val; - } else if (info.type == - GS_SHADER_PARAM_STRING) { + } else if (info.type == GS_SHADER_PARAM_STRING) { struct dstr val = {0}; - dstr_copy( - &val, - (const char *) - annotation_default); - struct dstr *cs = da_insert_new( - cached_data - ->option_labels, - id); + dstr_copy(&val, (const char *)annotation_default); + struct dstr *cs = da_insert_new(cached_data->option_labels, id); *cs = val; } } @@ -657,19 +576,15 @@ static const char *shader_filter_get_name(void *unused) static void *shader_filter_create(obs_data_t *settings, obs_source_t *source) { - struct shader_filter_data *filter = - bzalloc(sizeof(struct shader_filter_data)); + struct shader_filter_data *filter = bzalloc(sizeof(struct shader_filter_data)); filter->context = source; filter->reload_effect = true; dstr_init(&filter->last_path); - dstr_copy(&filter->last_path, - obs_data_get_string(settings, "shader_file_name")); + dstr_copy(&filter->last_path, obs_data_get_string(settings, "shader_file_name")); filter->last_from_file = obs_data_get_bool(settings, "from_file"); - filter->rand_instance_f = - (float)((double)rand_interval(0, 10000) / (double)10000); - filter->rand_activation_f = - (float)((double)rand_interval(0, 10000) / (double)10000); + filter->rand_instance_f = (float)((double)rand_interval(0, 10000) / (double)10000); + filter->rand_activation_f = (float)((double)rand_interval(0, 10000) / (double)10000); da_init(filter->stored_param_list); load_output_effect(filter); @@ -701,19 +616,15 @@ static void shader_filter_destroy(void *data) bfree(filter); } -static bool shader_filter_from_file_changed(obs_properties_t *props, - obs_property_t *p, - obs_data_t *settings) +static bool shader_filter_from_file_changed(obs_properties_t *props, obs_property_t *p, obs_data_t *settings) { UNUSED_PARAMETER(p); struct shader_filter_data *filter = obs_properties_get_param(props); bool from_file = obs_data_get_bool(settings, "from_file"); - obs_property_set_visible(obs_properties_get(props, "shader_text"), - !from_file); - obs_property_set_visible(obs_properties_get(props, "shader_file_name"), - from_file); + obs_property_set_visible(obs_properties_get(props, "shader_text"), !from_file); + obs_property_set_visible(obs_properties_get(props, "shader_file_name"), from_file); if (from_file != filter->last_from_file) { filter->reload_effect = true; @@ -723,8 +634,7 @@ static bool shader_filter_from_file_changed(obs_properties_t *props, return true; } -static bool shader_filter_text_changed(obs_properties_t *props, - obs_property_t *p, obs_data_t *settings) +static bool shader_filter_text_changed(obs_properties_t *props, obs_property_t *p, obs_data_t *settings) { UNUSED_PARAMETER(p); struct shader_filter_data *filter = obs_properties_get_param(props); @@ -732,59 +642,43 @@ static bool shader_filter_text_changed(obs_properties_t *props, return false; const char *shader_text = obs_data_get_string(settings, "shader_text"); - bool can_convert = strstr(shader_text, "void mainImage( out vec4") || - strstr(shader_text, "void mainImage(out vec4") || - strstr(shader_text, "void main()") || - strstr(shader_text, "vec4 effect(vec4"); - obs_property_t *shader_convert = - obs_properties_get(props, "shader_convert"); - bool visible = - obs_property_visible(obs_properties_get(props, "shader_text")); + bool can_convert = strstr(shader_text, "void mainImage( out vec4") || strstr(shader_text, "void mainImage(out vec4") || + strstr(shader_text, "void main()") || strstr(shader_text, "vec4 effect(vec4"); + obs_property_t *shader_convert = obs_properties_get(props, "shader_convert"); + bool visible = obs_property_visible(obs_properties_get(props, "shader_text")); if (obs_property_visible(shader_convert) != (can_convert && visible)) { - obs_property_set_visible(shader_convert, - can_convert && visible); + obs_property_set_visible(shader_convert, can_convert && visible); return true; } return false; } -static bool shader_filter_file_name_changed(obs_properties_t *props, - obs_property_t *p, - obs_data_t *settings) +static bool shader_filter_file_name_changed(obs_properties_t *props, obs_property_t *p, obs_data_t *settings) { struct shader_filter_data *filter = obs_properties_get_param(props); - const char *new_file_name = - obs_data_get_string(settings, obs_property_name(p)); + const char *new_file_name = obs_data_get_string(settings, obs_property_name(p)); if ((dstr_is_empty(&filter->last_path) && strlen(new_file_name)) || - (filter->last_path.array && - dstr_cmp(&filter->last_path, new_file_name) != 0)) { + (filter->last_path.array && dstr_cmp(&filter->last_path, new_file_name) != 0)) { filter->reload_effect = true; dstr_copy(&filter->last_path, new_file_name); size_t l = strlen(new_file_name); - if (l > 7 && - strncmp(new_file_name + l - 7, ".effect", 7) == 0) { - obs_data_set_bool(settings, "override_entire_effect", - true); - } else if (l > 7 && - strncmp(new_file_name + l - 7, ".shader", 7) == 0) { - obs_data_set_bool(settings, "override_entire_effect", - false); + if (l > 7 && strncmp(new_file_name + l - 7, ".effect", 7) == 0) { + obs_data_set_bool(settings, "override_entire_effect", true); + } else if (l > 7 && strncmp(new_file_name + l - 7, ".shader", 7) == 0) { + obs_data_set_bool(settings, "override_entire_effect", false); } } return false; } -static bool use_shader_elapsed_time_changed(obs_properties_t *props, - obs_property_t *p, - obs_data_t *settings) +static bool use_shader_elapsed_time_changed(obs_properties_t *props, obs_property_t *p, obs_data_t *settings) { UNUSED_PARAMETER(p); struct shader_filter_data *filter = obs_properties_get_param(props); - bool use_shader_elapsed_time = - obs_data_get_bool(settings, "use_shader_elapsed_time"); + bool use_shader_elapsed_time = obs_data_get_bool(settings, "use_shader_elapsed_time"); if (use_shader_elapsed_time != filter->use_shader_elapsed_time) { filter->reload_effect = true; } @@ -792,9 +686,7 @@ static bool use_shader_elapsed_time_changed(obs_properties_t *props, return false; } -static bool shader_filter_reload_effect_clicked(obs_properties_t *props, - obs_property_t *property, - void *data) +static bool shader_filter_reload_effect_clicked(obs_properties_t *props, obs_property_t *property, void *data) { UNUSED_PARAMETER(props); UNUSED_PARAMETER(property); @@ -813,8 +705,7 @@ static bool add_source_to_list(void *data, obs_source_t *source) const char *name = obs_source_get_name(source); size_t count = obs_property_list_item_count(p); size_t idx = 0; - while (idx < count && - strcmp(name, obs_property_list_item_string(p, idx)) > 0) + while (idx < count && strcmp(name, obs_property_list_item_string(p, idx)) > 0) idx++; obs_property_list_insert_string(p, idx, name, name); return true; @@ -843,8 +734,7 @@ static void convert_atan_single(struct dstr *effect_text) depth--; if (depth == 0 && (!comma || comma < close)) { comma = strstr(close + 1, ","); - } else if (comma && open && comma > open && - comma < close) { + } else if (comma && open && comma > open && comma < close) { comma = NULL; } open = strstr(close + 1, "("); @@ -861,8 +751,7 @@ static void convert_atan_single(struct dstr *effect_text) static bool is_var_char(char ch) { - return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || - (ch >= 'A' && ch <= 'Z') || ch == '_'; + return (ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_'; } static void convert_mul(struct dstr *effect_text) @@ -875,8 +764,7 @@ static void convert_mul(struct dstr *effect_text) while (*end == ' ' && end > effect_text->array) end--; char *start = end; - while ((is_var_char(*start) || *start == '.') && - start > effect_text->array) + while ((is_var_char(*start) || *start == '.') && start > effect_text->array) start--; start++; end++; @@ -899,23 +787,19 @@ static void convert_mul(struct dstr *effect_text) } } -static void insert_begin_of_block(struct dstr *effect_text, size_t diff, - char *insert) +static void insert_begin_of_block(struct dstr *effect_text, size_t diff, char *insert) { int depth = 0; char *ch = effect_text->array + diff; while (ch > effect_text->array && *ch == ' ') ch--; while (ch > effect_text->array) { - while (*ch != '=' && *ch != '(' && *ch != ')' && *ch != '+' && - *ch != '-' && *ch != '/' && *ch != '*' && *ch != ' ' && - ch > effect_text->array) + while (*ch != '=' && *ch != '(' && *ch != ')' && *ch != '+' && *ch != '-' && *ch != '/' && *ch != '*' && + *ch != ' ' && ch > effect_text->array) ch--; if (*ch == '(') { if (depth == 0) { - dstr_insert(effect_text, - ch - effect_text->array + 1, - insert); + dstr_insert(effect_text, ch - effect_text->array + 1, insert); return; } ch--; @@ -924,15 +808,11 @@ static void insert_begin_of_block(struct dstr *effect_text, size_t diff, ch--; depth++; } else if (*ch == '=') { - dstr_insert(effect_text, ch - effect_text->array + 1, - insert); + dstr_insert(effect_text, ch - effect_text->array + 1, insert); return; - } else if (*ch == '+' || *ch == '-' || *ch == '/' || - *ch == '*' || *ch == ' ') { + } else if (*ch == '+' || *ch == '-' || *ch == '/' || *ch == '*' || *ch == ' ') { if (depth == 0) { - dstr_insert(effect_text, - ch - effect_text->array + 1, - insert); + dstr_insert(effect_text, ch - effect_text->array + 1, insert); return; } ch--; @@ -940,38 +820,32 @@ static void insert_begin_of_block(struct dstr *effect_text, size_t diff, } } -static void insert_end_of_block(struct dstr *effect_text, size_t diff, - char *insert) +static void insert_end_of_block(struct dstr *effect_text, size_t diff, char *insert) { int depth = 0; char *ch = effect_text->array + diff; while (*ch == ' ') ch++; while (*ch != 0) { - while (*ch != ';' && *ch != '(' && *ch != ')' && *ch != '+' && - *ch != '-' && *ch != '/' && *ch != '*' && *ch != ' ' && - *ch != 0) + while (*ch != ';' && *ch != '(' && *ch != ')' && *ch != '+' && *ch != '-' && *ch != '/' && *ch != '*' && + *ch != ' ' && *ch != 0) ch++; if (*ch == '(') { ch++; depth++; } else if (*ch == ')') { if (depth == 0) { - dstr_insert(effect_text, - ch - effect_text->array, insert); + dstr_insert(effect_text, ch - effect_text->array, insert); return; } ch++; depth--; } else if (*ch == ';') { - dstr_insert(effect_text, ch - effect_text->array, - insert); + dstr_insert(effect_text, ch - effect_text->array, insert); return; - } else if (*ch == '+' || *ch == '-' || *ch == '/' || - *ch == '*' || *ch == ' ') { + } else if (*ch == '+' || *ch == '-' || *ch == '/' || *ch == '*' || *ch == ' ') { if (depth == 0) { - dstr_insert(effect_text, - ch - effect_text->array, insert); + dstr_insert(effect_text, ch - effect_text->array, insert); return; } ch++; @@ -979,15 +853,12 @@ static void insert_end_of_block(struct dstr *effect_text, size_t diff, } } -static void convert_mat_mul_var(struct dstr *effect_text, - struct dstr *var_function_name) +static void convert_mat_mul_var(struct dstr *effect_text, struct dstr *var_function_name) { char *pos = strstr(effect_text->array, var_function_name->array); while (pos) { - if (is_var_char(*(pos - 1)) || - is_var_char(*(pos + var_function_name->len))) { - pos = strstr(pos + var_function_name->len, - var_function_name->array); + if (is_var_char(*(pos - 1)) || is_var_char(*(pos + var_function_name->len))) { + pos = strstr(pos + var_function_name->len, var_function_name->array); continue; } size_t diff = pos - effect_text->array; @@ -999,29 +870,23 @@ static void convert_mat_mul_var(struct dstr *effect_text, *ch = ','; insert_end_of_block(effect_text, diff3, ")"); dstr_insert(effect_text, diff, "mul("); - pos = strstr(effect_text->array + diff + 4 + - var_function_name->len, - var_function_name->array); + pos = strstr(effect_text->array + diff + 4 + var_function_name->len, var_function_name->array); continue; } ch = pos - 1; while (*ch == ' ') ch--; if (*ch == '*') { - size_t diff2 = ch - effect_text->array; + size_t diff2 = ch - effect_text->array - 1; *ch = ','; - insert_end_of_block(effect_text, - diff + var_function_name->len, ")"); + insert_end_of_block(effect_text, diff + var_function_name->len, ")"); insert_begin_of_block(effect_text, diff2, "mul("); - pos = strstr(effect_text->array + diff + 4 + - var_function_name->len, - var_function_name->array); + pos = strstr(effect_text->array + diff + 4 + var_function_name->len, var_function_name->array); continue; } - pos = strstr(effect_text->array + diff + var_function_name->len, - var_function_name->array); + pos = strstr(effect_text->array + diff + var_function_name->len, var_function_name->array); } } @@ -1042,24 +907,19 @@ static void convert_mat_mul(struct dstr *effect_text, char *var_type) ch--; if (*ch == '*') { // mat constructor with * in front of it - size_t diff2 = ch - effect_text->array; + size_t diff2 = ch - effect_text->array - 1; *ch = ','; - insert_end_of_block(effect_text, diff + len, - ")"); - insert_begin_of_block(effect_text, diff2, - "mul("); - - pos = strstr(effect_text->array + diff + len + - 4, - var_type); + insert_end_of_block(effect_text, diff + len, ")"); + insert_begin_of_block(effect_text, diff2, "mul("); + + pos = strstr(effect_text->array + diff + len + 4, var_type); continue; } int depth = 1; ch = begin + 1; while (*ch != 0) { - while (*ch != ';' && *ch != '(' && *ch != ')' && - *ch != '+' && *ch != '-' && *ch != '/' && + while (*ch != ';' && *ch != '(' && *ch != ')' && *ch != '+' && *ch != '-' && *ch != '/' && *ch != '*' && *ch != 0) ch++; if (*ch == '(') { @@ -1075,13 +935,8 @@ static void convert_mat_mul(struct dstr *effect_text, char *var_type) if (depth == 0) { //mat constructor follow by * *ch = ','; - insert_end_of_block( - effect_text, - ch - effect_text->array + - 1, - ")"); - dstr_insert(effect_text, diff, - "mul("); + insert_end_of_block(effect_text, ch - effect_text->array + 1, ")"); + dstr_insert(effect_text, diff, "mul("); break; } ch++; @@ -1150,8 +1005,7 @@ static void convert_vector_init(struct dstr *effect_text, char *name, int count) } else if (*ch == ';') { only_one = false; break; - } else if (is_var_char(*ch) && - (*ch < '0' || *ch > '9')) { + } else if (is_var_char(*ch) && (*ch < '0' || *ch > '9')) { only_numbers = false; char *begin = ch; while (is_var_char(*ch)) @@ -1166,113 +1020,93 @@ static void convert_vector_init(struct dstr *effect_text, char *name, int count) } else if (function_depth >= 0) { ch--; } else if (*ch == '(' && - (strncmp(begin, "length(", 7) == 0 || - strncmp(begin, "float(", 6) == 0 || - strncmp(begin, "uint(", 5) == 0 || - strncmp(begin, "int(", 4) == 0 || - strncmp(begin, "asfloat(", 8) == - 0 || - strncmp(begin, "asdouble(", 9) == - 0 || - strncmp(begin, "asint(", 6) == 0 || - strncmp(begin, "asuint(", 7) == 0 || - strncmp(begin, "determinant(", - 12) == 0 || - strncmp(begin, "distance(", 9) == - 0 || - strncmp(begin, "dot(", 4) == 0 || - strncmp(begin, "countbits(", 10) == - 0 || - strncmp(begin, "firstbithigh(", - 13) == 0 || - strncmp(begin, "firstbitlow(", - 12) == 0 || - strncmp(begin, "reversebits(", - 12) == 0)) { + (strncmp(begin, "length(", 7) == 0 || strncmp(begin, "float(", 6) == 0 || + strncmp(begin, "uint(", 5) == 0 || strncmp(begin, "int(", 4) == 0 || + strncmp(begin, "asfloat(", 8) == 0 || strncmp(begin, "asdouble(", 9) == 0 || + strncmp(begin, "asint(", 6) == 0 || strncmp(begin, "asuint(", 7) == 0 || + strncmp(begin, "determinant(", 12) == 0 || strncmp(begin, "distance(", 9) == 0 || + strncmp(begin, "dot(", 4) == 0 || strncmp(begin, "countbits(", 10) == 0 || + strncmp(begin, "firstbithigh(", 13) == 0 || strncmp(begin, "firstbitlow(", 12) == 0 || + strncmp(begin, "reversebits(", 12) == 0)) { function_depth = depth; depth++; } else if (*ch == '(' && - (strncmp(begin, "abs(", 4) == 0 || - strncmp(begin, "acos(", 5) == 0 || - strncmp(begin, "asin(", 5) == 0 || - strncmp(begin, "atan(", 5) == 0 || - strncmp(begin, "atan2(", 6) == 0 || - strncmp(begin, "ceil(", 5) == 0 || - strncmp(begin, "clamp(", 6) == 0 || - strncmp(begin, "cos(", 4) == 0 || - strncmp(begin, "cosh(", 5) == 0 || - strncmp(begin, "ddx(", 4) == 0 || - strncmp(begin, "ddy(", 4) == 0 || - strncmp(begin, "degrees(", 8) == - 0 || - strncmp(begin, "exp(", 4) == 0 || - strncmp(begin, "exp2(", 5) == 0 || - strncmp(begin, "floor(", 6) == 0 || - strncmp(begin, "fma(", 4) == 0 || - strncmp(begin, "fmod(", 5) == 0 || - strncmp(begin, "frac(", 5) == 0 || - strncmp(begin, "frexp(", 6) == 0 || - strncmp(begin, "fwidth(", 7) == 0 || - strncmp(begin, "ldexp(", 6) == 0 || - strncmp(begin, "lerp(", 5) == 0 || - strncmp(begin, "log(", 4) == 0 || - strncmp(begin, "log10(", 6) == 0 || - strncmp(begin, "log2(", 5) == 0 || - strncmp(begin, "mad(", 4) == 0 || - strncmp(begin, "max(", 4) == 0 || - strncmp(begin, "min(", 4) == 0 || - strncmp(begin, "modf(", 5) == 0 || - strncmp(begin, "mod(", 4) == 0 || - strncmp(begin, "mul(", 4) == 0 || - strncmp(begin, "normalize(", 10) == - 0 || - strncmp(begin, "pow(", 4) == 0 || - strncmp(begin, "radians(", 8) == - 0 || - strncmp(begin, "rcp(", 4) == 0 || - strncmp(begin, "reflect(", 8) == - 0 || - strncmp(begin, "refract(", 8) == - 0 || - strncmp(begin, "round(", 6) == 0 || - strncmp(begin, "rsqrt(", 6) == 0 || - strncmp(begin, "saturate(", 9) == - 0 || - strncmp(begin, "sign(", 5) == 0 || - strncmp(begin, "sin(", 4) == 0 || - strncmp(begin, "sincos(", 7) == 0 || - strncmp(begin, "sinh(", 5) == 0 || - strncmp(begin, "smoothstep(", 11) == - 0 || - strncmp(begin, "sqrt(", 5) == 0 || - strncmp(begin, "step(", 5) == 0 || - strncmp(begin, "tan(", 4) == 0 || - strncmp(begin, "tanh(", 5) == 0 || - strncmp(begin, "transpose(", 10) == - 0 || + (strncmp(begin, "abs(", 4) == 0 || strncmp(begin, "acos(", 5) == 0 || + strncmp(begin, "asin(", 5) == 0 || strncmp(begin, "atan(", 5) == 0 || + strncmp(begin, "atan2(", 6) == 0 || strncmp(begin, "ceil(", 5) == 0 || + strncmp(begin, "clamp(", 6) == 0 || strncmp(begin, "cos(", 4) == 0 || + strncmp(begin, "cosh(", 5) == 0 || strncmp(begin, "ddx(", 4) == 0 || + strncmp(begin, "ddy(", 4) == 0 || strncmp(begin, "degrees(", 8) == 0 || + strncmp(begin, "exp(", 4) == 0 || strncmp(begin, "exp2(", 5) == 0 || + strncmp(begin, "floor(", 6) == 0 || strncmp(begin, "fma(", 4) == 0 || + strncmp(begin, "fmod(", 5) == 0 || strncmp(begin, "frac(", 5) == 0 || + strncmp(begin, "frexp(", 6) == 0 || strncmp(begin, "fwidth(", 7) == 0 || + strncmp(begin, "ldexp(", 6) == 0 || strncmp(begin, "lerp(", 5) == 0 || + strncmp(begin, "log(", 4) == 0 || strncmp(begin, "log10(", 6) == 0 || + strncmp(begin, "log2(", 5) == 0 || strncmp(begin, "mad(", 4) == 0 || + strncmp(begin, "max(", 4) == 0 || strncmp(begin, "min(", 4) == 0 || + strncmp(begin, "modf(", 5) == 0 || strncmp(begin, "mod(", 4) == 0 || + strncmp(begin, "mul(", 4) == 0 || strncmp(begin, "normalize(", 10) == 0 || + strncmp(begin, "pow(", 4) == 0 || strncmp(begin, "radians(", 8) == 0 || + strncmp(begin, "rcp(", 4) == 0 || strncmp(begin, "reflect(", 8) == 0 || + strncmp(begin, "refract(", 8) == 0 || strncmp(begin, "round(", 6) == 0 || + strncmp(begin, "rsqrt(", 6) == 0 || strncmp(begin, "saturate(", 9) == 0 || + strncmp(begin, "sign(", 5) == 0 || strncmp(begin, "sin(", 4) == 0 || + strncmp(begin, "sincos(", 7) == 0 || strncmp(begin, "sinh(", 5) == 0 || + strncmp(begin, "smoothstep(", 11) == 0 || strncmp(begin, "sqrt(", 5) == 0 || + strncmp(begin, "step(", 5) == 0 || strncmp(begin, "tan(", 4) == 0 || + strncmp(begin, "tanh(", 5) == 0 || strncmp(begin, "transpose(", 10) == 0 || strncmp(begin, "trunc(", 6) == 0)) { depth++; } else { struct dstr find = {0}; bool found = false; dstr_copy(&find, "float "); - dstr_ncat(&find, begin, - ch - begin + - (*ch == '(' ? 1 : 0)); - found = strstr(effect_text->array, - find.array) != NULL; + dstr_ncat(&find, begin, ch - begin + (*ch == '(' ? 1 : 0)); + char *t = strstr(effect_text->array, find.array); + while (t != NULL) { + t += find.len; + if (*ch == '(') { + found = true; + break; + }else if (!is_var_char(*t)) { + found = true; + break; + } + t = strstr(t, find.array); + } if (!found) { dstr_copy(&find, "int "); - dstr_ncat( - &find, begin, - ch - begin + - (*ch == '(' - ? 1 - : 0)); - found = strstr(effect_text - ->array, - find.array) != - NULL; + dstr_ncat(&find, begin, ch - begin + (*ch == '(' ? 1 : 0)); + t = strstr(effect_text->array, find.array); + while (t != NULL) { + t += find.len; + if (*ch == '(') { + found = true; + break; + } else if (!is_var_char(*t)) { + found = true; + break; + } + t = strstr(t, find.array); + } + } + if (!found && *ch != '(') { + dstr_copy(&find, "#define "); + dstr_ncat(&find, begin, ch - begin); + char *t = strstr(effect_text->array, find.array); + while (t != NULL) { + t += find.len; + if (!is_var_char(*t)) { + while (*t == ' ' || *t == '\t') + t++; + if (*t >= '0' && *t <= '9') { + found = true; + break; + } + } + t = strstr(t, find.array); + } } if (!found) { only_float = false; @@ -1282,9 +1116,8 @@ static void convert_vector_init(struct dstr *effect_text, char *name, int count) dstr_free(&find); ch--; } - } else if ((*ch < '0' || *ch > '9') && *ch != '.' && - *ch != ' ' && *ch != '+' && *ch != '-' && - *ch != '*' && *ch != '/') { + } else if ((*ch < '0' || *ch > '9') && *ch != '.' && *ch != ' ' && *ch != '+' && *ch != '-' && *ch != '*' && + *ch != '/') { only_numbers = false; } ch++; @@ -1360,15 +1193,13 @@ static void convert_if1(struct dstr *effect_text) end - el + 6); // #endif end = strstr(effect_text->array + diff, "\n"); if (end) - dstr_remove(effect_text, diff, - end - (effect_text->array + diff)); + dstr_remove(effect_text, diff, end - (effect_text->array + diff)); begin = strstr(effect_text->array + diff, "#if 1"); } else if (!el || el > end) { dstr_remove(effect_text, end - effect_text->array, 6); end = strstr(effect_text->array + diff, "\n"); if (end) - dstr_remove(effect_text, diff, - end - (effect_text->array + diff)); + dstr_remove(effect_text, diff, end - (effect_text->array + diff)); begin = strstr(effect_text->array + diff, "#if 1"); } else { begin = strstr(effect_text->array + diff + 5, "#if 1"); @@ -1402,8 +1233,7 @@ static void convert_define(struct dstr *effect_text) start++; end = start; - while (*end != '\n' && *end != 0 && - (*end != '/' || *(end + 1) != '/')) + while (*end != '\n' && *end != 0 && (*end != '/' || *(end + 1) != '/')) end++; t = strstr(start, "("); @@ -1411,11 +1241,9 @@ static void convert_define(struct dstr *effect_text) struct dstr replacement = {0}; dstr_ncat(&replacement, start, end - start); - dstr_remove(effect_text, diff, - end - (effect_text->array + diff)); + dstr_remove(effect_text, diff, end - (effect_text->array + diff)); - dstr_replace(effect_text, def_name.array, - replacement.array); + dstr_replace(effect_text, def_name.array, replacement.array); dstr_free(&replacement); pos = strstr(effect_text->array + diff, "#define "); @@ -1426,8 +1254,7 @@ static void convert_define(struct dstr *effect_text) } } -static void convert_return(struct dstr *effect_text, struct dstr *var_name, - size_t main_diff) +static void convert_return(struct dstr *effect_text, struct dstr *var_name, size_t main_diff) { size_t count = 0; char *pos = strstr(effect_text->array + main_diff, var_name->array); @@ -1446,14 +1273,11 @@ static void convert_return(struct dstr *effect_text, struct dstr *var_name, while (*ch == ' ') ch++; - if (*ch == '=' || - (*(ch + 1) == '=' && - (*ch == '*' || *ch == '/' || *ch == '+' || *ch == '-'))) { + if (*ch == '=' || (*(ch + 1) == '=' && (*ch == '*' || *ch == '/' || *ch == '+' || *ch == '-'))) { count++; } - pos = strstr(effect_text->array + diff + var_name->len, - var_name->array); + pos = strstr(effect_text->array + diff + var_name->len, var_name->array); } if (count == 0) return; @@ -1461,8 +1285,7 @@ static void convert_return(struct dstr *effect_text, struct dstr *var_name, pos = strstr(effect_text->array + main_diff, var_name->array); while (pos) { if (is_var_char(*(pos - 1))) { - pos = strstr(pos + var_name->len, - var_name->array); + pos = strstr(pos + var_name->len, var_name->array); continue; } size_t diff = pos - effect_text->array; @@ -1480,16 +1303,13 @@ static void convert_return(struct dstr *effect_text, struct dstr *var_name, dstr_remove(effect_text, diff, ch - pos + 1); dstr_insert(effect_text, diff, "return "); return; - } else if (*(ch + 1) == '=' && - (*ch == '*' || *ch == '/' || *ch == '+' || - *ch == '-')) { + } else if (*(ch + 1) == '=' && (*ch == '*' || *ch == '/' || *ch == '+' || *ch == '-')) { dstr_remove(effect_text, diff, ch - pos + 2); dstr_insert(effect_text, diff, "return "); return; } - pos = strstr(effect_text->array + diff + var_name->len, - var_name->array); + pos = strstr(effect_text->array + diff + var_name->len, var_name->array); } return; } @@ -1500,16 +1320,14 @@ static void convert_return(struct dstr *effect_text, struct dstr *var_name, pos = strstr(effect_text->array + main_diff, "{"); if (pos) { size_t insert_diff = pos - effect_text->array + 1; - dstr_insert(effect_text, insert_diff, - " = float4(0.0,0.0,0.0,1.0);\n"); + dstr_insert(effect_text, insert_diff, " = float4(0.0,0.0,0.0,1.0);\n"); dstr_insert(effect_text, insert_diff, var_name->array); dstr_insert(effect_text, insert_diff, "\n\tfloat4 "); declared = true; start_diff = insert_diff - main_diff + 37 + var_name->len; } - pos = strstr(effect_text->array + main_diff + start_diff, - var_name->array); + pos = strstr(effect_text->array + main_diff + start_diff, var_name->array); while (pos) { size_t diff = pos - effect_text->array; char *ch = pos + var_name->len; @@ -1527,17 +1345,12 @@ static void convert_return(struct dstr *effect_text, struct dstr *var_name, replaced++; if (replaced == 1 && !declared) { if (part) { - dstr_insert( - effect_text, diff, - " = float4(0.0,0.0,0.0,1.0);\n"); - dstr_insert(effect_text, diff, - var_name->array); - dstr_insert(effect_text, diff, - "float4 "); + dstr_insert(effect_text, diff, " = float4(0.0,0.0,0.0,1.0);\n"); + dstr_insert(effect_text, diff, var_name->array); + dstr_insert(effect_text, diff, "float4 "); diff += 35 + var_name->len; } else { - dstr_insert(effect_text, diff, - "float4 "); + dstr_insert(effect_text, diff, "float4 "); diff += 7; } } else if (replaced == count) { @@ -1546,24 +1359,18 @@ static void convert_return(struct dstr *effect_text, struct dstr *var_name, ch++; diff = ch - effect_text->array + 1; dstr_insert(effect_text, diff, ";"); - dstr_insert(effect_text, diff, - var_name->array); - dstr_insert(effect_text, diff, - "\n\treturn "); + dstr_insert(effect_text, diff, var_name->array); + dstr_insert(effect_text, diff, "\n\treturn "); } else { - dstr_remove(effect_text, diff, - ch - pos + 1); - dstr_insert(effect_text, diff, - "return "); + dstr_remove(effect_text, diff, ch - pos + 1); + dstr_insert(effect_text, diff, "return "); } return; } - } else if (*(ch + 1) == '=' && (*ch == '*' || *ch == '/' || - *ch == '+' || *ch == '-')) { + } else if (*(ch + 1) == '=' && (*ch == '*' || *ch == '/' || *ch == '+' || *ch == '-')) { replaced++; if (replaced == 1 && !declared) { - dstr_insert(effect_text, diff, - " = float4(0.0,0.0,0.0,1.0);\n"); + dstr_insert(effect_text, diff, " = float4(0.0,0.0,0.0,1.0);\n"); dstr_insert(effect_text, diff, var_name->array); dstr_insert(effect_text, diff, "float4 "); diff += 35 + var_name->len; @@ -1578,13 +1385,11 @@ static void convert_return(struct dstr *effect_text, struct dstr *var_name, } } - pos = strstr(effect_text->array + diff + var_name->len, - var_name->array); + pos = strstr(effect_text->array + diff + var_name->len, var_name->array); } } -static bool shader_filter_convert(obs_properties_t *props, - obs_property_t *property, void *data) +static bool shader_filter_convert(obs_properties_t *props, obs_property_t *property, void *data) { UNUSED_PARAMETER(props); if (!data) @@ -1594,8 +1399,7 @@ static bool shader_filter_convert(obs_properties_t *props, if (!settings) return false; struct dstr effect_text = {0}; - dstr_init_copy(&effect_text, - obs_data_get_string(settings, "shader_text")); + dstr_init_copy(&effect_text, obs_data_get_string(settings, "shader_text")); convert_define(&effect_text); @@ -1604,8 +1408,7 @@ static bool shader_filter_convert(obs_properties_t *props, int uv = 0; char *main_pos = strstr(effect_text.array, "void mainImage(out vec4"); if (!main_pos) { - main_pos = - strstr(effect_text.array, "void mainImage( out vec4"); + main_pos = strstr(effect_text.array, "void mainImage( out vec4"); start_diff++; } if (!main_pos) { @@ -1629,8 +1432,7 @@ static bool shader_filter_convert(obs_properties_t *props, struct dstr coord_name = {0}; if (main_no_args) { - dstr_replace(&effect_text, "void main()", - "float4 mainImage(VertData v_in) : TARGET"); + dstr_replace(&effect_text, "void main()", "float4 mainImage(VertData v_in) : TARGET"); if (strstr(effect_text.array, "varying vec2 position;")) { uv = 1; dstr_init_copy(&coord_name, "position"); @@ -1651,16 +1453,13 @@ static bool shader_filter_convert(obs_properties_t *props, while (*start == ' ') start++; char *end = start; - while (*end != ' ' && *end != ',' && *end != '(' && - *end != ')' && *end != ';' && *end != 0) + while (*end != ' ' && *end != ',' && *end != '(' && *end != ')' && *end != ';' && *end != 0) end++; dstr_ncat(&return_color_name, start, end - start); while (*end == ' ') end++; if (*end == ';') - dstr_remove(&effect_text, - out_start - effect_text.array, - (end + 1) - out_start); + dstr_remove(&effect_text, out_start - effect_text.array, (end + 1) - out_start); } else { dstr_init_copy(&return_color_name, "gl_FragColor"); } @@ -1693,13 +1492,11 @@ static bool shader_filter_convert(obs_properties_t *props, } else if (v2 && close && v2 < close) { start = v2 + 5; } else { - if (*start == 'i' && *(start + 1) == 'n' && - *(start + 2) == ' ') + if (*start == 'i' && *(start + 1) == 'n' && *(start + 2) == ' ') start += 3; while (*start == ' ') start++; - if (*start == 'v' && *(start + 1) == 'e' && - *(start + 2) == 'c' && *(start + 3) == '2' && + if (*start == 'v' && *(start + 1) == 'e' && *(start + 2) == 'c' && *(start + 3) == '2' && *(start + 4) == ' ') start += 5; } @@ -1716,8 +1513,7 @@ static bool shader_filter_convert(obs_properties_t *props, end++; size_t idx = main_pos - effect_text.array; dstr_remove(&effect_text, idx, end - main_pos + 1); - dstr_insert(&effect_text, idx, - "float4 mainImage(VertData v_in) : TARGET"); + dstr_insert(&effect_text, idx, "float4 mainImage(VertData v_in) : TARGET"); } convert_return(&effect_text, &return_color_name, main_diff); @@ -1726,28 +1522,19 @@ static bool shader_filter_convert(obs_properties_t *props, if (dstr_cmp(&coord_name, "fragCoord") != 0) { if (dstr_find(&coord_name, "fragCoord")) { - dstr_replace(&effect_text, coord_name.array, - "fragCoord"); + dstr_replace(&effect_text, coord_name.array, "fragCoord"); } else { char *pos = strstr(effect_text.array, coord_name.array); while (pos) { size_t diff = pos - effect_text.array; - if (((main_no_args || diff < main_diff) || - diff > main_diff + 24) && - !is_var_char(*(pos - 1)) && + if (((main_no_args || diff < main_diff) || diff > main_diff + 24) && !is_var_char(*(pos - 1)) && !is_var_char(*(pos + coord_name.len))) { - dstr_remove(&effect_text, diff, - coord_name.len); - dstr_insert(&effect_text, diff, - "fragCoord"); - pos = strstr(effect_text.array + diff + - 9, - coord_name.array); + dstr_remove(&effect_text, diff, coord_name.len); + dstr_insert(&effect_text, diff, "fragCoord"); + pos = strstr(effect_text.array + diff + 9, coord_name.array); } else { - pos = strstr(effect_text.array + diff + - coord_name.len, - coord_name.array); + pos = strstr(effect_text.array + diff + coord_name.len, coord_name.array); } } } @@ -1758,33 +1545,23 @@ static bool shader_filter_convert(obs_properties_t *props, convert_if1(&effect_text); dstr_replace(&effect_text, "varying vec3", "//varying vec3"); - dstr_replace(&effect_text, "precision highp float;", - "//precision highp float;"); + dstr_replace(&effect_text, "precision highp float;", "//precision highp float;"); if (uv == 1) { dstr_replace(&effect_text, "fragCoord", "v_in.uv"); } else if (uv == 2) { dstr_replace(&effect_text, "fragCoord.xy", "v_in.uv"); dstr_replace(&effect_text, "fragCoord", "float3(v_in.uv,0.0)"); } else { - dstr_replace(&effect_text, "fragCoord.xy/iResolution.xy", - "v_in.uv"); - dstr_replace(&effect_text, "fragCoord.xy / iResolution.xy", - "v_in.uv"); - dstr_replace(&effect_text, "fragCoord/iResolution.xy", - "v_in.uv"); - dstr_replace(&effect_text, "fragCoord / iResolution.xy", - "v_in.uv"); + dstr_replace(&effect_text, "fragCoord.xy/iResolution.xy", "v_in.uv"); + dstr_replace(&effect_text, "fragCoord.xy / iResolution.xy", "v_in.uv"); + dstr_replace(&effect_text, "fragCoord/iResolution.xy", "v_in.uv"); + dstr_replace(&effect_text, "fragCoord / iResolution.xy", "v_in.uv"); dstr_replace(&effect_text, "fragCoord", "(v_in.uv * uv_size)"); - dstr_replace(&effect_text, "gl_FragCoord.xy/iResolution.xy", - "v_in.uv"); - dstr_replace(&effect_text, "gl_FragCoord.xy / iResolution.xy", - "v_in.uv"); - dstr_replace(&effect_text, "gl_FragCoord/iResolution.xy", - "v_in.uv"); - dstr_replace(&effect_text, "gl_FragCoord / iResolution.xy", - "v_in.uv"); - dstr_replace(&effect_text, "gl_FragCoord", - "(v_in.uv * uv_size)"); + dstr_replace(&effect_text, "gl_FragCoord.xy/iResolution.xy", "v_in.uv"); + dstr_replace(&effect_text, "gl_FragCoord.xy / iResolution.xy", "v_in.uv"); + dstr_replace(&effect_text, "gl_FragCoord/iResolution.xy", "v_in.uv"); + dstr_replace(&effect_text, "gl_FragCoord / iResolution.xy", "v_in.uv"); + dstr_replace(&effect_text, "gl_FragCoord", "(v_in.uv * uv_size)"); } dstr_replace(&effect_text, "love_ScreenSize", "uv_size"); dstr_replace(&effect_text, "u_resolution", "uv_size"); @@ -1792,8 +1569,7 @@ static bool shader_filter_convert(obs_properties_t *props, dstr_replace(&effect_text, "iResolution.xy", "uv_size"); dstr_replace(&effect_text, "iResolution.x", "uv_size.x"); dstr_replace(&effect_text, "iResolution.y", "uv_size.y"); - dstr_replace(&effect_text, "iResolution", - "float4(uv_size,uv_pixel_interval)"); + dstr_replace(&effect_text, "iResolution", "float4(uv_size,uv_pixel_interval)"); dstr_replace(&effect_text, "uniform vec2 uv_size;", ""); @@ -1808,6 +1584,10 @@ static bool shader_filter_convert(obs_properties_t *props, dstr_replace(&effect_text, "uniform float elapsed_time;", ""); + dstr_replace(&effect_text, "bvec2", "bool2"); + dstr_replace(&effect_text, "bvec3", "bool3"); + dstr_replace(&effect_text, "bvec4", "bool4"); + dstr_replace(&effect_text, "ivec4", "int4"); dstr_replace(&effect_text, "ivec3", "int3"); dstr_replace(&effect_text, "ivec2", "int2"); @@ -1869,22 +1649,21 @@ static bool shader_filter_convert(obs_properties_t *props, dstr_cat(&insert_text, "#define mat4 float4x4\n"); if (dstr_find(&effect_text, "mod(")) - dstr_cat(&insert_text, - "#define mod(x,y) (x - y * floor(x / y))\n"); + dstr_cat(&insert_text, "#define mod(x,y) (x - y * floor(x / y))\n"); dstr_cat(&insert_text, "#endif\n"); - if (dstr_find(&effect_text, "iMouse") && - !dstr_find(&effect_text, "float2 iMouse")) + if (dstr_find(&effect_text, "iMouse") && !dstr_find(&effect_text, "float2 iMouse")) dstr_cat( &insert_text, "uniform float4 iMouse<\nstring widget_type = \"slider\";\nfloat minimum=0.0;\nfloat maximum=1000.0;\nfloat step=1.0;\n>;\n"); - if (dstr_find(&effect_text, "iSampleRate") && - !dstr_find(&effect_text, "float iSampleRate")) + if (dstr_find(&effect_text, "iFrame") && !dstr_find(&effect_text, "float iFrame")) + dstr_cat(&insert_text, "uniform float iFrame;\n"); + + if (dstr_find(&effect_text, "iSampleRate") && !dstr_find(&effect_text, "float iSampleRate")) dstr_cat(&insert_text, "uniform float iSampleRate;\n"); - if (dstr_find(&effect_text, "iTimeDelta") && - !dstr_find(&effect_text, "float iTimeDelta")) + if (dstr_find(&effect_text, "iTimeDelta") && !dstr_find(&effect_text, "float iTimeDelta")) dstr_cat(&insert_text, "uniform float iTimeDelta;\n"); int num_textures = 0; @@ -1892,8 +1671,7 @@ static bool shader_filter_convert(obs_properties_t *props, struct dstr replacing = {0}; struct dstr replacement = {0}; - char *texture_find[] = {"texture(", "texture2D(", "texelFetch(", - "Texel("}; + char *texture_find[] = {"texture(", "texture2D(", "texelFetch(", "Texel("}; char *texture = NULL; size_t texture_diff = 0; for (size_t i = 0; i < 4; i++) { @@ -1909,9 +1687,7 @@ static bool shader_filter_convert(obs_properties_t *props, texture = NULL; size_t prev_diff = texture_diff; for (size_t i = 0; i < 3; i++) { - char *t = strstr(effect_text.array + diff + - prev_diff, - texture_find[i]); + char *t = strstr(effect_text.array + diff + prev_diff, texture_find[i]); if (t && (!texture || t < texture)) { texture = t; texture_diff = strlen(texture_find[i]); @@ -1923,8 +1699,7 @@ static bool shader_filter_convert(obs_properties_t *props, while (*start == ' ') start++; char *end = start; - while (*end != ' ' && *end != ',' && *end != ')' && - *end != '\n' && *end != 0) + while (*end != ' ' && *end != ',' && *end != ')' && *end != '\n' && *end != 0) end++; dstr_copy(&texture_name, ""); dstr_ncat(&texture_name, start, end - start); @@ -1958,8 +1733,7 @@ static bool shader_filter_convert(obs_properties_t *props, size_t prev_diff = texture_diff; texture = NULL; for (size_t i = 0; i < 4; i++) { - char *t = strstr(effect_text.array + diff + prev_diff, - texture_find[i]); + char *t = strstr(effect_text.array + diff + prev_diff, texture_find[i]); if (t && (!texture || t < texture)) { texture = t; texture_diff = strlen(texture_find[i]); @@ -1988,8 +1762,7 @@ static bool shader_filter_convert(obs_properties_t *props, return true; } -static const char *shader_filter_texture_file_filter = - "Textures (*.bmp *.tga *.png *.jpeg *.jpg *.gif);;"; +static const char *shader_filter_texture_file_filter = "Textures (*.bmp *.tga *.png *.jpeg *.jpg *.gif);;"; static obs_properties_t *shader_filter_properties(void *data) { @@ -1997,79 +1770,50 @@ static obs_properties_t *shader_filter_properties(void *data) struct dstr examples_path = {0}; dstr_init(&examples_path); - dstr_cat(&examples_path, - obs_get_module_data_path(obs_current_module())); + dstr_cat(&examples_path, obs_get_module_data_path(obs_current_module())); dstr_cat(&examples_path, "/examples"); obs_properties_t *props = obs_properties_create(); obs_properties_set_param(props, filter, NULL); if (!filter || !filter->transition) { - obs_properties_add_int( - props, "expand_left", - obs_module_text("ShaderFilter.ExpandLeft"), 0, 9999, 1); - obs_properties_add_int( - props, "expand_right", - obs_module_text("ShaderFilter.ExpandRight"), 0, 9999, - 1); - obs_properties_add_int( - props, "expand_top", - obs_module_text("ShaderFilter.ExpandTop"), 0, 9999, 1); - obs_properties_add_int( - props, "expand_bottom", - obs_module_text("ShaderFilter.ExpandBottom"), 0, 9999, - 1); - } - - obs_properties_add_bool( - props, "override_entire_effect", - obs_module_text("ShaderFilter.OverrideEntireEffect")); - - obs_property_t *from_file = obs_properties_add_bool( - props, "from_file", - obs_module_text("ShaderFilter.LoadFromFile")); - obs_property_set_modified_callback(from_file, - shader_filter_from_file_changed); - - obs_property_t *shader_text = obs_properties_add_text( - props, "shader_text", - obs_module_text("ShaderFilter.ShaderText"), OBS_TEXT_MULTILINE); - obs_property_set_modified_callback(shader_text, - shader_filter_text_changed); - - obs_properties_add_button2(props, "shader_convert", - obs_module_text("ShaderFilter.Convert"), - shader_filter_convert, data); - - obs_property_t *file_name = obs_properties_add_path( - props, "shader_file_name", - obs_module_text("ShaderFilter.ShaderFileName"), OBS_PATH_FILE, - NULL, examples_path.array); - obs_property_set_modified_callback(file_name, - shader_filter_file_name_changed); + obs_properties_add_int(props, "expand_left", obs_module_text("ShaderFilter.ExpandLeft"), 0, 9999, 1); + obs_properties_add_int(props, "expand_right", obs_module_text("ShaderFilter.ExpandRight"), 0, 9999, 1); + obs_properties_add_int(props, "expand_top", obs_module_text("ShaderFilter.ExpandTop"), 0, 9999, 1); + obs_properties_add_int(props, "expand_bottom", obs_module_text("ShaderFilter.ExpandBottom"), 0, 9999, 1); + } + + obs_properties_add_bool(props, "override_entire_effect", obs_module_text("ShaderFilter.OverrideEntireEffect")); + + obs_property_t *from_file = obs_properties_add_bool(props, "from_file", obs_module_text("ShaderFilter.LoadFromFile")); + obs_property_set_modified_callback(from_file, shader_filter_from_file_changed); + + obs_property_t *shader_text = + obs_properties_add_text(props, "shader_text", obs_module_text("ShaderFilter.ShaderText"), OBS_TEXT_MULTILINE); + obs_property_set_modified_callback(shader_text, shader_filter_text_changed); + + obs_properties_add_button2(props, "shader_convert", obs_module_text("ShaderFilter.Convert"), shader_filter_convert, data); + + obs_property_t *file_name = obs_properties_add_path(props, "shader_file_name", + obs_module_text("ShaderFilter.ShaderFileName"), OBS_PATH_FILE, NULL, + examples_path.array); + obs_property_set_modified_callback(file_name, shader_filter_file_name_changed); if (filter) { obs_data_t *settings = obs_source_get_settings(filter->context); - const char *last_error = - obs_data_get_string(settings, "last_error"); + const char *last_error = obs_data_get_string(settings, "last_error"); if (last_error && strlen(last_error)) { - obs_property_t *error = obs_properties_add_text( - props, "last_error", - obs_module_text("ShaderFilter.Error"), - OBS_TEXT_INFO); - obs_property_text_set_info_type(error, - OBS_TEXT_INFO_ERROR); + obs_property_t *error = + obs_properties_add_text(props, "last_error", obs_module_text("ShaderFilter.Error"), OBS_TEXT_INFO); + obs_property_text_set_info_type(error, OBS_TEXT_INFO_ERROR); } obs_data_release(settings); } - obs_property_t *use_shader_elapsed_time = obs_properties_add_bool( - props, "use_shader_elapsed_time", - obs_module_text("ShaderFilter.UseShaderElapsedTime")); - obs_property_set_modified_callback(use_shader_elapsed_time, - use_shader_elapsed_time_changed); + obs_property_t *use_shader_elapsed_time = + obs_properties_add_bool(props, "use_shader_elapsed_time", obs_module_text("ShaderFilter.UseShaderElapsedTime")); + obs_property_set_modified_callback(use_shader_elapsed_time, use_shader_elapsed_time_changed); - obs_properties_add_button(props, "reload_effect", - obs_module_text("ShaderFilter.ReloadEffect"), + obs_properties_add_button(props, "reload_effect", obs_module_text("ShaderFilter.ReloadEffect"), shader_filter_reload_effect_clicked); DARRAY(obs_property_t *) groups; @@ -2077,8 +1821,7 @@ static obs_properties_t *shader_filter_properties(void *data) size_t param_count = filter->stored_param_list.num; for (size_t param_index = 0; param_index < param_count; param_index++) { - struct effect_param_data *param = - (filter->stored_param_list.array + param_index); + struct effect_param_data *param = (filter->stored_param_list.array + param_index); //gs_eparam_t *annot = gs_param_get_annotation_by_idx(param->param, param_index); const char *param_name = param->name.array; const char *label = param->display_name.array; @@ -2094,24 +1837,20 @@ static obs_properties_t *shader_filter_properties(void *data) dstr_ncat(&display_name, param_name, param->name.len); dstr_replace(&display_name, "_", " "); } else { - dstr_ncat(&display_name, label, - param->display_name.len); + dstr_ncat(&display_name, label, param->display_name.len); } obs_properties_t *group = NULL; if (group_name && strlen(group_name)) { for (size_t i = 0; i < groups.num; i++) { - const char *n = - obs_property_name(groups.array[i]); + const char *n = obs_property_name(groups.array[i]); if (strcmp(n, group_name) == 0) { - group = obs_property_group_content( - groups.array[i]); + group = obs_property_group_content(groups.array[i]); } } if (!group) { group = obs_properties_create(); - obs_property_t *p = obs_properties_add_group( - props, group_name, group_name, - OBS_GROUP_NORMAL, group); + obs_property_t *p = + obs_properties_add_group(props, group_name, group_name, OBS_GROUP_NORMAL, group); da_push_back(groups, &p); } } @@ -2119,8 +1858,7 @@ static obs_properties_t *shader_filter_properties(void *data) group = props; switch (param->type) { case GS_SHADER_PARAM_BOOL: - obs_properties_add_bool(group, param_name, - display_name.array); + obs_properties_add_bool(group, param_name, display_name.array); break; case GS_SHADER_PARAM_FLOAT: { double range_min = param->minimum.f; @@ -2132,16 +1870,10 @@ static obs_properties_t *shader_filter_properties(void *data) step = 0.0001; } obs_properties_remove_by_name(props, param_name); - if (widget_type != NULL && - strcmp(widget_type, "slider") == 0) { - obs_properties_add_float_slider( - group, param_name, display_name.array, - range_min, range_max, step); + if (widget_type != NULL && strcmp(widget_type, "slider") == 0) { + obs_properties_add_float_slider(group, param_name, display_name.array, range_min, range_max, step); } else { - obs_properties_add_float(group, param_name, - display_name.array, - range_min, range_max, - step); + obs_properties_add_float(group, param_name, display_name.array, range_min, range_max, step); } break; } @@ -2156,28 +1888,16 @@ static obs_properties_t *shader_filter_properties(void *data) } obs_properties_remove_by_name(props, param_name); - if (widget_type != NULL && - strcmp(widget_type, "slider") == 0) { - obs_properties_add_int_slider( - group, param_name, display_name.array, - range_min, range_max, step); - } else if (widget_type != NULL && - strcmp(widget_type, "select") == 0) { - obs_property_t *plist = obs_properties_add_list( - group, param_name, display_name.array, - OBS_COMBO_TYPE_LIST, - OBS_COMBO_FORMAT_INT); - for (size_t i = 0; i < param->option_values.num; - i++) { - obs_property_list_add_int( - plist, option_labels[i].array, - options[i]); + if (widget_type != NULL && strcmp(widget_type, "slider") == 0) { + obs_properties_add_int_slider(group, param_name, display_name.array, range_min, range_max, step); + } else if (widget_type != NULL && strcmp(widget_type, "select") == 0) { + obs_property_t *plist = obs_properties_add_list(group, param_name, display_name.array, + OBS_COMBO_TYPE_LIST, OBS_COMBO_FORMAT_INT); + for (size_t i = 0; i < param->option_values.num; i++) { + obs_property_list_add_int(plist, option_labels[i].array, options[i]); } } else { - obs_properties_add_int(group, param_name, - display_name.array, - range_min, range_max, - step); + obs_properties_add_int(group, param_name, display_name.array, range_min, range_max, step); } break; } @@ -2194,43 +1914,27 @@ static obs_properties_t *shader_filter_properties(void *data) step = 0.0001; } - bool slider = (widget_type != NULL && - strcmp(widget_type, "slider") == 0); + bool slider = (widget_type != NULL && strcmp(widget_type, "slider") == 0); for (size_t i = 0; i < 2; i++) { - dstr_printf(&sources_name, "%s_%zu", param_name, - i); + dstr_printf(&sources_name, "%s_%zu", param_name, i); if (i < param->option_labels.num) { if (slider) { - obs_properties_add_float_slider( - group, - sources_name.array, - param->option_labels - .array[i] - .array, - range_min, range_max, - step); + obs_properties_add_float_slider(group, sources_name.array, + param->option_labels.array[i].array, range_min, + range_max, step); } else { - obs_properties_add_float( - group, - sources_name.array, - param->option_labels - .array[i] - .array, - range_min, range_max, - step); + obs_properties_add_float(group, sources_name.array, + param->option_labels.array[i].array, range_min, range_max, + step); } } else if (slider) { - obs_properties_add_float_slider( - group, sources_name.array, - display_name.array, range_min, - range_max, step); + obs_properties_add_float_slider(group, sources_name.array, display_name.array, range_min, + range_max, step); } else { - obs_properties_add_float( - group, sources_name.array, - display_name.array, range_min, - range_max, step); + obs_properties_add_float(group, sources_name.array, display_name.array, range_min, + range_max, step); } } dstr_free(&sources_name); @@ -2238,8 +1942,7 @@ static obs_properties_t *shader_filter_properties(void *data) break; } case GS_SHADER_PARAM_VEC3: - if (widget_type != NULL && - strcmp(widget_type, "slider") == 0) { + if (widget_type != NULL && strcmp(widget_type, "slider") == 0) { double range_min = param->minimum.f; double range_max = param->maximum.f; double step = param->step.f; @@ -2249,35 +1952,23 @@ static obs_properties_t *shader_filter_properties(void *data) step = 0.0001; } for (size_t i = 0; i < 3; i++) { - dstr_printf(&sources_name, "%s_%zu", - param_name, i); + dstr_printf(&sources_name, "%s_%zu", param_name, i); if (i < param->option_labels.num) { - obs_properties_add_float_slider( - group, - sources_name.array, - param->option_labels - .array[i] - .array, - range_min, range_max, - step); + obs_properties_add_float_slider(group, sources_name.array, + param->option_labels.array[i].array, range_min, + range_max, step); } else { - obs_properties_add_float_slider( - group, - sources_name.array, - display_name.array, - range_min, range_max, - step); + obs_properties_add_float_slider(group, sources_name.array, display_name.array, + range_min, range_max, step); } } dstr_free(&sources_name); } else { - obs_properties_add_color(group, param_name, - display_name.array); + obs_properties_add_color(group, param_name, display_name.array); } break; case GS_SHADER_PARAM_VEC4: - if (widget_type != NULL && - strcmp(widget_type, "slider") == 0) { + if (widget_type != NULL && strcmp(widget_type, "slider") == 0) { double range_min = param->minimum.f; double range_max = param->maximum.f; double step = param->step.f; @@ -2287,85 +1978,53 @@ static obs_properties_t *shader_filter_properties(void *data) step = 0.0001; } for (size_t i = 0; i < 4; i++) { - dstr_printf(&sources_name, "%s_%zu", - param_name, i); + dstr_printf(&sources_name, "%s_%zu", param_name, i); if (i < param->option_labels.num) { - obs_properties_add_float_slider( - group, - sources_name.array, - param->option_labels - .array[i] - .array, - range_min, range_max, - step); + obs_properties_add_float_slider(group, sources_name.array, + param->option_labels.array[i].array, range_min, + range_max, step); } else { - obs_properties_add_float_slider( - group, - sources_name.array, - display_name.array, - range_min, range_max, - step); + obs_properties_add_float_slider(group, sources_name.array, display_name.array, + range_min, range_max, step); } } dstr_free(&sources_name); } else { - obs_properties_add_color_alpha( - group, param_name, display_name.array); + obs_properties_add_color_alpha(group, param_name, display_name.array); } break; case GS_SHADER_PARAM_TEXTURE: - if (widget_type != NULL && - strcmp(widget_type, "source") == 0) { - dstr_init_copy_dstr(&sources_name, - ¶m->name); + if (widget_type != NULL && strcmp(widget_type, "source") == 0) { + dstr_init_copy_dstr(&sources_name, ¶m->name); dstr_cat(&sources_name, "_source"); - obs_property_t *p = obs_properties_add_list( - group, sources_name.array, - display_name.array, - OBS_COMBO_TYPE_EDITABLE, - OBS_COMBO_FORMAT_STRING); + obs_property_t *p = obs_properties_add_list(group, sources_name.array, display_name.array, + OBS_COMBO_TYPE_EDITABLE, OBS_COMBO_FORMAT_STRING); dstr_free(&sources_name); obs_enum_sources(add_source_to_list, p); obs_enum_scenes(add_source_to_list, p); obs_property_list_insert_string(p, 0, "", ""); - } else if (widget_type != NULL && - strcmp(widget_type, "file") == 0) { - obs_properties_add_path( - group, param_name, display_name.array, - OBS_PATH_FILE, - shader_filter_texture_file_filter, - NULL); + } else if (widget_type != NULL && strcmp(widget_type, "file") == 0) { + obs_properties_add_path(group, param_name, display_name.array, OBS_PATH_FILE, + shader_filter_texture_file_filter, NULL); } else { - dstr_init_copy_dstr(&sources_name, - ¶m->name); + dstr_init_copy_dstr(&sources_name, ¶m->name); dstr_cat(&sources_name, "_source"); - obs_property_t *p = obs_properties_add_list( - group, sources_name.array, - display_name.array, - OBS_COMBO_TYPE_EDITABLE, - OBS_COMBO_FORMAT_STRING); + obs_property_t *p = obs_properties_add_list(group, sources_name.array, display_name.array, + OBS_COMBO_TYPE_EDITABLE, OBS_COMBO_FORMAT_STRING); dstr_free(&sources_name); obs_property_list_add_string(p, "", ""); obs_enum_sources(add_source_to_list, p); obs_enum_scenes(add_source_to_list, p); - obs_properties_add_path( - group, param_name, display_name.array, - OBS_PATH_FILE, - shader_filter_texture_file_filter, - NULL); + obs_properties_add_path(group, param_name, display_name.array, OBS_PATH_FILE, + shader_filter_texture_file_filter, NULL); } break; case GS_SHADER_PARAM_STRING: - if (widget_type != NULL && - strcmp(widget_type, "info") == 0) { - obs_properties_add_text(group, param_name, - display_name.array, - OBS_TEXT_INFO); + if (widget_type != NULL && strcmp(widget_type, "info") == 0) { + obs_properties_add_text(group, param_name, display_name.array, OBS_TEXT_INFO); } else { - obs_properties_add_text(group, param_name, - display_name.array, - OBS_TEXT_MULTILINE); + obs_properties_add_text(group, param_name, display_name.array, OBS_TEXT_MULTILINE); } break; default:; @@ -2392,12 +2051,9 @@ static void shader_filter_update(void *data, obs_data_t *settings) filter->expand_left = (int)obs_data_get_int(settings, "expand_left"); filter->expand_right = (int)obs_data_get_int(settings, "expand_right"); filter->expand_top = (int)obs_data_get_int(settings, "expand_top"); - filter->expand_bottom = - (int)obs_data_get_int(settings, "expand_bottom"); - filter->use_shader_elapsed_time = - (bool)obs_data_get_bool(settings, "use_shader_elapsed_time"); - filter->rand_activation_f = - (float)((double)rand_interval(0, 10000) / (double)10000); + filter->expand_bottom = (int)obs_data_get_int(settings, "expand_bottom"); + filter->use_shader_elapsed_time = (bool)obs_data_get_bool(settings, "use_shader_elapsed_time"); + filter->rand_activation_f = (float)((double)rand_interval(0, 10000) / (double)10000); if (filter->reload_effect) { filter->reload_effect = false; @@ -2407,8 +2063,7 @@ static void shader_filter_update(void *data, obs_data_t *settings) size_t param_count = filter->stored_param_list.num; for (size_t param_index = 0; param_index < param_count; param_index++) { - struct effect_param_data *param = - (filter->stored_param_list.array + param_index); + struct effect_param_data *param = (filter->stored_param_list.array + param_index); //gs_eparam_t *annot = gs_param_get_annotation_by_idx(param->param, param_index); const char *param_name = param->name.array; struct dstr sources_name = {0}; @@ -2417,165 +2072,108 @@ static void shader_filter_update(void *data, obs_data_t *settings) switch (param->type) { case GS_SHADER_PARAM_BOOL: if (default_value != NULL) - obs_data_set_default_bool( - settings, param_name, - *(bool *)default_value); - param->value.i = - obs_data_get_bool(settings, param_name); + obs_data_set_default_bool(settings, param_name, *(bool *)default_value); + param->value.i = obs_data_get_bool(settings, param_name); break; case GS_SHADER_PARAM_FLOAT: if (default_value != NULL) - obs_data_set_default_double( - settings, param_name, - *(float *)default_value); - param->value.f = - obs_data_get_double(settings, param_name); + obs_data_set_default_double(settings, param_name, *(float *)default_value); + param->value.f = obs_data_get_double(settings, param_name); break; case GS_SHADER_PARAM_INT: if (default_value != NULL) - obs_data_set_default_int(settings, param_name, - *(int *)default_value); + obs_data_set_default_int(settings, param_name, *(int *)default_value); param->value.i = obs_data_get_int(settings, param_name); break; case GS_SHADER_PARAM_VEC2: { struct vec2 *xy = default_value; for (size_t i = 0; i < 2; i++) { - dstr_printf(&sources_name, "%s_%zu", param_name, - i); + dstr_printf(&sources_name, "%s_%zu", param_name, i); if (xy != NULL) - obs_data_set_default_double( - settings, sources_name.array, - xy->ptr[i]); - param->value.vec2.ptr[i] = - (float)obs_data_get_double( - settings, sources_name.array); + obs_data_set_default_double(settings, sources_name.array, xy->ptr[i]); + param->value.vec2.ptr[i] = (float)obs_data_get_double(settings, sources_name.array); } dstr_free(&sources_name); break; } case GS_SHADER_PARAM_VEC3: { struct vec3 *rgb = default_value; - if (param->widget_type.array && - strcmp(param->widget_type.array, "slider") == 0) { + if (param->widget_type.array && strcmp(param->widget_type.array, "slider") == 0) { for (size_t i = 0; i < 3; i++) { - dstr_printf(&sources_name, "%s_%zu", - param_name, i); + dstr_printf(&sources_name, "%s_%zu", param_name, i); if (rgb != NULL) - obs_data_set_default_double( - settings, - sources_name.array, - rgb->ptr[i]); - param->value.vec3.ptr[i] = - (float)obs_data_get_double( - settings, - sources_name.array); + obs_data_set_default_double(settings, sources_name.array, rgb->ptr[i]); + param->value.vec3.ptr[i] = (float)obs_data_get_double(settings, sources_name.array); } dstr_free(&sources_name); } else { if (rgb != NULL) { struct vec4 rgba; vec4_from_vec3(&rgba, rgb); - obs_data_set_default_int( - settings, param_name, - vec4_to_rgba(&rgba)); + obs_data_set_default_int(settings, param_name, vec4_to_rgba(&rgba)); } else { // Hack to ensure we have a default...(white) - obs_data_set_default_int(settings, - param_name, - 0xffffffff); + obs_data_set_default_int(settings, param_name, 0xffffffff); } - vec4_from_rgba(¶m->value.vec4, - (uint32_t)obs_data_get_int( - settings, param_name)); + vec4_from_rgba(¶m->value.vec4, (uint32_t)obs_data_get_int(settings, param_name)); } break; } case GS_SHADER_PARAM_VEC4: { struct vec4 *rgba = default_value; - if (param->widget_type.array && - strcmp(param->widget_type.array, "slider") == 0) { + if (param->widget_type.array && strcmp(param->widget_type.array, "slider") == 0) { for (size_t i = 0; i < 4; i++) { - dstr_printf(&sources_name, "%s_%zu", - param_name, i); + dstr_printf(&sources_name, "%s_%zu", param_name, i); if (rgba != NULL) - obs_data_set_default_double( - settings, - sources_name.array, - rgba->ptr[i]); - param->value.vec4.ptr[i] = - (float)obs_data_get_double( - settings, - sources_name.array); + obs_data_set_default_double(settings, sources_name.array, rgba->ptr[i]); + param->value.vec4.ptr[i] = (float)obs_data_get_double(settings, sources_name.array); } dstr_free(&sources_name); } else { if (rgba != NULL) { - obs_data_set_default_int( - settings, param_name, - vec4_to_rgba(rgba)); + obs_data_set_default_int(settings, param_name, vec4_to_rgba(rgba)); } else { // Hack to ensure we have a default...(white) - obs_data_set_default_int(settings, - param_name, - 0xffffffff); + obs_data_set_default_int(settings, param_name, 0xffffffff); } - vec4_from_rgba(¶m->value.vec4, - (uint32_t)obs_data_get_int( - settings, param_name)); + vec4_from_rgba(¶m->value.vec4, (uint32_t)obs_data_get_int(settings, param_name)); } break; } case GS_SHADER_PARAM_TEXTURE: dstr_init_copy_dstr(&sources_name, ¶m->name); dstr_cat(&sources_name, "_source"); - const char *sn = obs_data_get_string( - settings, sources_name.array); + const char *sn = obs_data_get_string(settings, sources_name.array); dstr_free(&sources_name); source = obs_weak_source_get_source(param->source); - if (source && - strcmp(obs_source_get_name(source), sn) != 0) { + if (source && strcmp(obs_source_get_name(source), sn) != 0) { obs_source_release(source); source = NULL; } if (!source) - source = (sn && strlen(sn)) - ? obs_get_source_by_name(sn) - : NULL; + source = (sn && strlen(sn)) ? obs_get_source_by_name(sn) : NULL; if (source) { - if (!obs_weak_source_references_source( - param->source, source)) { - if ((!filter->transition || - filter->prev_transitioning) && + if (!obs_weak_source_references_source(param->source, source)) { + if ((!filter->transition || filter->prev_transitioning) && obs_source_active(filter->context)) obs_source_inc_active(source); - if ((!filter->transition || - filter->prev_transitioning) && + if ((!filter->transition || filter->prev_transitioning) && obs_source_showing(filter->context)) obs_source_inc_showing(source); - obs_source_t *old_source = - obs_weak_source_get_source( - param->source); + obs_source_t *old_source = obs_weak_source_get_source(param->source); if (old_source) { - if ((!filter->transition || - filter->prev_transitioning) && - obs_source_active( - filter->context)) - obs_source_dec_active( - old_source); - if ((!filter->transition || - filter->prev_transitioning) && - obs_source_showing( - filter->context)) - obs_source_dec_showing( - old_source); + if ((!filter->transition || filter->prev_transitioning) && + obs_source_active(filter->context)) + obs_source_dec_active(old_source); + if ((!filter->transition || filter->prev_transitioning) && + obs_source_showing(filter->context)) + obs_source_dec_showing(old_source); obs_source_release(old_source); } obs_weak_source_release(param->source); - param->source = - obs_source_get_weak_source( - source); + param->source = obs_source_get_weak_source(source); } obs_source_release(source); if (param->image) { @@ -2585,79 +2183,52 @@ static void shader_filter_update(void *data, obs_data_t *settings) dstr_free(¶m->path); } else { const char *path = default_value; - if (!obs_data_has_user_value(settings, - param_name) && - path && strlen(path)) { + if (!obs_data_has_user_value(settings, param_name) && path && strlen(path)) { if (os_file_exists(path)) { - char *abs_path = - os_get_abs_path_ptr( - path); - obs_data_set_default_string( - settings, param_name, - abs_path); + char *abs_path = os_get_abs_path_ptr(path); + obs_data_set_default_string(settings, param_name, abs_path); bfree(abs_path); } else { struct dstr texture_path = {0}; dstr_init(&texture_path); - dstr_cat( - &texture_path, - obs_get_module_data_path( - obs_current_module())); - dstr_cat(&texture_path, - "/textures/"); + dstr_cat(&texture_path, obs_get_module_data_path(obs_current_module())); + dstr_cat(&texture_path, "/textures/"); dstr_cat(&texture_path, path); - char *abs_path = - os_get_abs_path_ptr( - texture_path - .array); + char *abs_path = os_get_abs_path_ptr(texture_path.array); if (os_file_exists(abs_path)) { - obs_data_set_default_string( - settings, - param_name, - abs_path); + obs_data_set_default_string(settings, param_name, abs_path); } bfree(abs_path); dstr_free(&texture_path); } } - path = obs_data_get_string(settings, - param_name); + path = obs_data_get_string(settings, param_name); bool n = false; if (param->image == NULL) { - param->image = bzalloc( - sizeof(gs_image_file_t)); + param->image = bzalloc(sizeof(gs_image_file_t)); n = true; } - if (n || !path || !param->path.array || - strcmp(path, param->path.array) != 0) { + if (n || !path || !param->path.array || strcmp(path, param->path.array) != 0) { if (!n) { obs_enter_graphics(); - gs_image_file_free( - param->image); + gs_image_file_free(param->image); obs_leave_graphics(); } gs_image_file_init(param->image, path); dstr_copy(¶m->path, path); obs_enter_graphics(); - gs_image_file_init_texture( - param->image); + gs_image_file_init_texture(param->image); obs_leave_graphics(); } - obs_source_t *old_source = - obs_weak_source_get_source( - param->source); + obs_source_t *old_source = obs_weak_source_get_source(param->source); if (old_source) { - if ((!filter->transition || - filter->prev_transitioning) && + if ((!filter->transition || filter->prev_transitioning) && obs_source_active(filter->context)) - obs_source_dec_active( - old_source); - if ((!filter->transition || - filter->prev_transitioning) && + obs_source_dec_active(old_source); + if ((!filter->transition || filter->prev_transitioning) && obs_source_showing(filter->context)) - obs_source_dec_showing( - old_source); + obs_source_dec_showing(old_source); obs_source_release(old_source); } obs_weak_source_release(param->source); @@ -2666,11 +2237,8 @@ static void shader_filter_update(void *data, obs_data_t *settings) break; case GS_SHADER_PARAM_STRING: if (default_value != NULL) - obs_data_set_default_string( - settings, param_name, - (const char *)default_value); - param->value.string = (char *)obs_data_get_string( - settings, param_name); + obs_data_set_default_string(settings, param_name, (const char *)default_value); + param->value.string = (char *)obs_data_get_string(settings, param_name); break; default:; } @@ -2681,19 +2249,15 @@ static void shader_filter_update(void *data, obs_data_t *settings) static void shader_filter_tick(void *data, float seconds) { struct shader_filter_data *filter = data; - obs_source_t *target = filter->transition - ? filter->context - : obs_filter_get_target(filter->context); + obs_source_t *target = filter->transition ? filter->context : obs_filter_get_target(filter->context); if (!target) return; // Determine offsets from expansion values. int base_width = obs_source_get_base_width(target); int base_height = obs_source_get_base_height(target); - filter->total_width = - filter->expand_left + base_width + filter->expand_right; - filter->total_height = - filter->expand_top + base_height + filter->expand_bottom; + filter->total_width = filter->expand_left + base_width + filter->expand_right; + filter->total_height = filter->expand_top + base_height + filter->expand_bottom; filter->uv_size.x = (float)filter->total_width; filter->uv_size.y = (float)filter->total_height; @@ -2723,8 +2287,7 @@ static void shader_filter_tick(void *data, float seconds) filter->local_time = (float)(os_gettime_ns() / 1000000000.0); // undecided between this and "rand_float(1);" - filter->rand_f = - (float)((double)rand_interval(0, 10000) / (double)10000); + filter->rand_f = (float)((double)rand_interval(0, 10000) / (double)10000); filter->rendered = false; } @@ -2751,47 +2314,36 @@ static void get_input_source(struct shader_filter_data *filter) GS_CS_709_EXTENDED, }; - const enum gs_color_space source_space = obs_source_get_color_space( - obs_filter_get_target(filter->context), - OBS_COUNTOF(preferred_spaces), preferred_spaces); + const enum gs_color_space source_space = + obs_source_get_color_space(obs_filter_get_target(filter->context), OBS_COUNTOF(preferred_spaces), preferred_spaces); - const enum gs_color_format format = - gs_get_format_from_space(source_space); + const enum gs_color_format format = gs_get_format_from_space(source_space); // Set up our input_texrender to catch the output texture. - filter->input_texrender = - create_or_reset_texrender(filter->input_texrender); + filter->input_texrender = create_or_reset_texrender(filter->input_texrender); // Start the rendering process with our correct color space params, // And set up your texrender to recieve the created texture. if (!filter->transition && - !obs_source_process_filter_begin_with_color_space( - filter->context, format, source_space, - OBS_NO_DIRECT_RENDERING)) + !obs_source_process_filter_begin_with_color_space(filter->context, format, source_space, OBS_NO_DIRECT_RENDERING)) return; - if (gs_texrender_begin(filter->input_texrender, filter->total_width, - filter->total_height)) { + if (gs_texrender_begin(filter->input_texrender, filter->total_width, filter->total_height)) { gs_blend_state_push(); gs_reset_blend_state(); gs_enable_blending(false); gs_blend_function(GS_BLEND_ONE, GS_BLEND_ZERO); - gs_ortho(0.0f, (float)filter->total_width, 0.0f, - (float)filter->total_height, -100.0f, 100.0f); + gs_ortho(0.0f, (float)filter->total_width, 0.0f, (float)filter->total_height, -100.0f, 100.0f); // The incoming source is pre-multiplied alpha, so use the // OBS default effect "DrawAlphaDivide" technique to convert // the colors back into non-pre-multiplied space. If the shader // file has #define USE_PM_ALPHA 1, then use normal "Draw" // technique. - const char *technique = - filter->use_pm_alpha ? "Draw" : "DrawAlphaDivide"; + const char *technique = filter->use_pm_alpha ? "Draw" : "DrawAlphaDivide"; if (!filter->transition) - obs_source_process_filter_tech_end(filter->context, - pass_through, - filter->total_width, - filter->total_height, + obs_source_process_filter_tech_end(filter->context, pass_through, filter->total_width, filter->total_height, technique); gs_texrender_end(filter->input_texrender); gs_blend_state_pop(); @@ -2806,30 +2358,23 @@ static void draw_output(struct shader_filter_data *filter) GS_CS_709_EXTENDED, }; - const enum gs_color_space source_space = obs_source_get_color_space( - obs_filter_get_target(filter->context), - OBS_COUNTOF(preferred_spaces), preferred_spaces); + const enum gs_color_space source_space = + obs_source_get_color_space(obs_filter_get_target(filter->context), OBS_COUNTOF(preferred_spaces), preferred_spaces); - const enum gs_color_format format = - gs_get_format_from_space(source_space); + const enum gs_color_format format = gs_get_format_from_space(source_space); - if (!obs_source_process_filter_begin_with_color_space( - filter->context, format, source_space, - OBS_NO_DIRECT_RENDERING)) { + if (!obs_source_process_filter_begin_with_color_space(filter->context, format, source_space, OBS_NO_DIRECT_RENDERING)) { return; } - gs_texture_t *texture = - gs_texrender_get_texture(filter->output_texrender); + gs_texture_t *texture = gs_texrender_get_texture(filter->output_texrender); gs_effect_t *pass_through = filter->output_effect; if (filter->param_output_image) { gs_effect_set_texture(filter->param_output_image, texture); } - obs_source_process_filter_end(filter->context, pass_through, - filter->total_width, - filter->total_height); + obs_source_process_filter_end(filter->context, pass_through, filter->total_width, filter->total_height); } void shader_filter_set_effect_params(struct shader_filter_data *filter) @@ -2842,25 +2387,20 @@ void shader_filter_set_effect_params(struct shader_filter_data *filter) gs_effect_set_vec2(filter->param_uv_offset, &filter->uv_offset); } if (filter->param_uv_pixel_interval != NULL) { - gs_effect_set_vec2(filter->param_uv_pixel_interval, - &filter->uv_pixel_interval); + gs_effect_set_vec2(filter->param_uv_pixel_interval, &filter->uv_pixel_interval); } if (filter->param_elapsed_time != NULL) { if (filter->use_shader_elapsed_time) { - gs_effect_set_float(filter->param_elapsed_time, - filter->elapsed_time - - filter->shader_start_time); + gs_effect_set_float(filter->param_elapsed_time, filter->elapsed_time - filter->shader_start_time); } else { - gs_effect_set_float(filter->param_elapsed_time, - filter->elapsed_time); + gs_effect_set_float(filter->param_elapsed_time, filter->elapsed_time); } } if (filter->param_uv_size != NULL) { gs_effect_set_vec2(filter->param_uv_size, &filter->uv_size); } if (filter->param_local_time != NULL) { - gs_effect_set_float(filter->param_local_time, - filter->local_time); + gs_effect_set_float(filter->param_local_time, filter->local_time); } if (filter->param_loops != NULL) { gs_effect_set_int(filter->param_loops, filter->loops); @@ -2869,18 +2409,15 @@ void shader_filter_set_effect_params(struct shader_filter_data *filter) gs_effect_set_float(filter->param_rand_f, filter->rand_f); } if (filter->param_rand_activation_f != NULL) { - gs_effect_set_float(filter->param_rand_activation_f, - filter->rand_activation_f); + gs_effect_set_float(filter->param_rand_activation_f, filter->rand_activation_f); } if (filter->param_rand_instance_f != NULL) { - gs_effect_set_float(filter->param_rand_instance_f, - filter->rand_instance_f); + gs_effect_set_float(filter->param_rand_instance_f, filter->rand_instance_f); } size_t param_count = filter->stored_param_list.num; for (size_t param_index = 0; param_index < param_count; param_index++) { - struct effect_param_data *param = - (filter->stored_param_list.array + param_index); + struct effect_param_data *param = (filter->stored_param_list.array + param_index); obs_source_t *source = NULL; switch (param->type) { @@ -2888,8 +2425,7 @@ void shader_filter_set_effect_params(struct shader_filter_data *filter) gs_effect_set_bool(param->param, param->value.i); break; case GS_SHADER_PARAM_FLOAT: - gs_effect_set_float(param->param, - (float)param->value.f); + gs_effect_set_float(param->param, (float)param->value.f); break; case GS_SHADER_PARAM_INT: gs_effect_set_int(param->param, (int)param->value.i); @@ -2912,73 +2448,49 @@ void shader_filter_set_effect_params(struct shader_filter_data *filter) GS_CS_709_EXTENDED, }; const enum gs_color_space space = - obs_source_get_color_space( - source, - OBS_COUNTOF(preferred_spaces), - preferred_spaces); - const enum gs_color_format format = - gs_get_format_from_space(space); - if (!param->render || - gs_texrender_get_format(param->render) != - format) { + obs_source_get_color_space(source, OBS_COUNTOF(preferred_spaces), preferred_spaces); + const enum gs_color_format format = gs_get_format_from_space(space); + if (!param->render || gs_texrender_get_format(param->render) != format) { gs_texrender_destroy(param->render); - param->render = gs_texrender_create( - format, GS_ZS_NONE); + param->render = gs_texrender_create(format, GS_ZS_NONE); } else { gs_texrender_reset(param->render); } - uint32_t base_width = - obs_source_get_base_width(source); - uint32_t base_height = - obs_source_get_base_height(source); + uint32_t base_width = obs_source_get_base_width(source); + uint32_t base_height = obs_source_get_base_height(source); gs_blend_state_push(); gs_blend_function(GS_BLEND_ONE, GS_BLEND_ZERO); - if (gs_texrender_begin_with_color_space( - param->render, base_width, - base_height, space)) { + if (gs_texrender_begin_with_color_space(param->render, base_width, base_height, space)) { const float w = (float)base_width; const float h = (float)base_height; - uint32_t flags = - obs_source_get_output_flags( - source); - const bool custom_draw = - (flags & - OBS_SOURCE_CUSTOM_DRAW) != 0; - const bool async = - (flags & OBS_SOURCE_ASYNC) != 0; + uint32_t flags = obs_source_get_output_flags(source); + const bool custom_draw = (flags & OBS_SOURCE_CUSTOM_DRAW) != 0; + const bool async = (flags & OBS_SOURCE_ASYNC) != 0; struct vec4 clear_color; vec4_zero(&clear_color); - gs_clear(GS_CLEAR_COLOR, &clear_color, - 0.0f, 0); - gs_ortho(0.0f, w, 0.0f, h, -100.0f, - 100.0f); + gs_clear(GS_CLEAR_COLOR, &clear_color, 0.0f, 0); + gs_ortho(0.0f, w, 0.0f, h, -100.0f, 100.0f); if (!custom_draw && !async) - obs_source_default_render( - source); + obs_source_default_render(source); else obs_source_video_render(source); gs_texrender_end(param->render); } gs_blend_state_pop(); obs_source_release(source); - gs_texture_t *tex = - gs_texrender_get_texture(param->render); + gs_texture_t *tex = gs_texrender_get_texture(param->render); gs_effect_set_texture(param->param, tex); } else if (param->image) { - gs_effect_set_texture(param->param, - param->image->texture); + gs_effect_set_texture(param->param, param->image->texture); } else { gs_effect_set_texture(param->param, NULL); } break; case GS_SHADER_PARAM_STRING: - gs_effect_set_val(param->param, - (param->value.string - ? param->value.string - : NULL), + gs_effect_set_val(param->param, (param->value.string ? param->value.string : NULL), gs_effect_get_val_size(param->param)); break; default:; @@ -2988,14 +2500,12 @@ void shader_filter_set_effect_params(struct shader_filter_data *filter) static void render_shader(struct shader_filter_data *filter) { - gs_texture_t *texture = - gs_texrender_get_texture(filter->input_texrender); + gs_texture_t *texture = gs_texrender_get_texture(filter->input_texrender); if (!texture) { return; } - filter->output_texrender = - create_or_reset_texrender(filter->output_texrender); + filter->output_texrender = create_or_reset_texrender(filter->output_texrender); if (filter->param_image) { gs_effect_set_texture(filter->param_image, texture); @@ -3007,13 +2517,10 @@ static void render_shader(struct shader_filter_data *filter) gs_enable_blending(false); gs_blend_function(GS_BLEND_ONE, GS_BLEND_ZERO); - if (gs_texrender_begin(filter->output_texrender, filter->total_width, - filter->total_height)) { - gs_ortho(0.0f, (float)filter->total_width, 0.0f, - (float)filter->total_height, -100.0f, 100.0f); + if (gs_texrender_begin(filter->output_texrender, filter->total_width, filter->total_height)) { + gs_ortho(0.0f, (float)filter->total_width, 0.0f, (float)filter->total_height, -100.0f, 100.0f); while (gs_effect_loop(filter->effect, "Draw")) - gs_draw_sprite(texture, 0, filter->total_width, - filter->total_height); + gs_draw_sprite(texture, 0, filter->total_width, filter->total_height); gs_texrender_end(filter->output_texrender); } @@ -3060,13 +2567,10 @@ static uint32_t shader_filter_getheight(void *data) static void shader_filter_defaults(obs_data_t *settings) { - obs_data_set_default_string(settings, "shader_text", - effect_template_default_image_shader); + obs_data_set_default_string(settings, "shader_text", effect_template_default_image_shader); } -static enum gs_color_space -shader_filter_get_color_space(void *data, size_t count, - const enum gs_color_space *preferred_spaces) +static enum gs_color_space shader_filter_get_color_space(void *data, size_t count, const enum gs_color_space *preferred_spaces) { UNUSED_PARAMETER(count); UNUSED_PARAMETER(preferred_spaces); @@ -3077,22 +2581,18 @@ shader_filter_get_color_space(void *data, size_t count, GS_CS_SRGB_16F, GS_CS_709_EXTENDED, }; - return obs_source_get_color_space(target, OBS_COUNTOF(potential_spaces), - potential_spaces); + return obs_source_get_color_space(target, OBS_COUNTOF(potential_spaces), potential_spaces); } -void shader_filter_param_source_action(void *data, - void (*action)(obs_source_t *source)) +void shader_filter_param_source_action(void *data, void (*action)(obs_source_t *source)) { struct shader_filter_data *filter = data; size_t param_count = filter->stored_param_list.num; for (size_t param_index = 0; param_index < param_count; param_index++) { - struct effect_param_data *param = - (filter->stored_param_list.array + param_index); + struct effect_param_data *param = (filter->stored_param_list.array + param_index); if (!param->source) continue; - obs_source_t *source = - obs_weak_source_get_source(param->source); + obs_source_t *source = obs_weak_source_get_source(param->source); if (!source) continue; action(source); @@ -3123,8 +2623,7 @@ void shader_filter_hide(void *data) struct obs_source_info shader_filter = { .id = "shader_filter", .type = OBS_SOURCE_TYPE_FILTER, - .output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_SRGB | - OBS_SOURCE_CUSTOM_DRAW, + .output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_SRGB | OBS_SOURCE_CUSTOM_DRAW, .create = shader_filter_create, .destroy = shader_filter_destroy, .update = shader_filter_update, @@ -3143,23 +2642,18 @@ struct obs_source_info shader_filter = { .hide = shader_filter_hide, }; -static void *shader_transition_create(obs_data_t *settings, - obs_source_t *source) +static void *shader_transition_create(obs_data_t *settings, obs_source_t *source) { - struct shader_filter_data *filter = - bzalloc(sizeof(struct shader_filter_data)); + struct shader_filter_data *filter = bzalloc(sizeof(struct shader_filter_data)); filter->context = source; filter->reload_effect = true; filter->transition = true; dstr_init(&filter->last_path); - dstr_copy(&filter->last_path, - obs_data_get_string(settings, "shader_file_name")); + dstr_copy(&filter->last_path, obs_data_get_string(settings, "shader_file_name")); filter->last_from_file = obs_data_get_bool(settings, "from_file"); - filter->rand_instance_f = - (float)((double)rand_interval(0, 10000) / (double)10000); - filter->rand_activation_f = - (float)((double)rand_interval(0, 10000) / (double)10000); + filter->rand_instance_f = (float)((double)rand_interval(0, 10000) / (double)10000); + filter->rand_activation_f = (float)((double)rand_interval(0, 10000) / (double)10000); da_init(filter->stored_param_list); @@ -3186,20 +2680,14 @@ static float mix_b(void *data, float t) return t; } -static bool shader_transition_audio_render(void *data, uint64_t *ts_out, - struct obs_source_audio_mix *audio, - uint32_t mixers, size_t channels, - size_t sample_rate) +static bool shader_transition_audio_render(void *data, uint64_t *ts_out, struct obs_source_audio_mix *audio, uint32_t mixers, + size_t channels, size_t sample_rate) { struct shader_filter_data *filter = data; - return obs_transition_audio_render(filter->context, ts_out, audio, - mixers, channels, sample_rate, mix_a, - mix_b); + return obs_transition_audio_render(filter->context, ts_out, audio, mixers, channels, sample_rate, mix_a, mix_b); } -static void shader_transition_video_callback(void *data, gs_texture_t *a, - gs_texture_t *b, float t, - uint32_t cx, uint32_t cy) +static void shader_transition_video_callback(void *data, gs_texture_t *a, gs_texture_t *b, float t, uint32_t cx, uint32_t cy) { if (!a && !b) return; @@ -3210,11 +2698,9 @@ static void shader_transition_video_callback(void *data, gs_texture_t *a, if (!filter->prev_transitioning) { if (obs_source_active(filter->context)) - shader_filter_param_source_action( - data, obs_source_inc_active); + shader_filter_param_source_action(data, obs_source_inc_active); if (obs_source_showing(filter->context)) - shader_filter_param_source_action( - data, obs_source_inc_showing); + shader_filter_param_source_action(data, obs_source_inc_showing); } filter->transitioning = true; @@ -3227,8 +2713,7 @@ static void shader_transition_video_callback(void *data, gs_texture_t *a, if (filter->param_image_b != NULL) gs_effect_set_texture(filter->param_image_b, b); if (filter->param_image != NULL) - gs_effect_set_texture(filter->param_image, - t < 0.5 ? a : b); + gs_effect_set_texture(filter->param_image, t < 0.5 ? a : b); if (filter->param_convert_linear) gs_effect_set_bool(filter->param_convert_linear, true); } else { @@ -3237,8 +2722,7 @@ static void shader_transition_video_callback(void *data, gs_texture_t *a, if (filter->param_image_b != NULL) gs_effect_set_texture_srgb(filter->param_image_b, b); if (filter->param_image != NULL) - gs_effect_set_texture_srgb(filter->param_image, - t < 0.5 ? a : b); + gs_effect_set_texture_srgb(filter->param_image, t < 0.5 ? a : b); if (filter->param_convert_linear) gs_effect_set_bool(filter->param_convert_linear, false); } @@ -3261,15 +2745,12 @@ static void shader_transition_video_render(void *data, gs_effect_t *effect) struct shader_filter_data *filter = data; filter->transitioning = false; - obs_transition_video_render2(filter->context, - shader_transition_video_callback, NULL); + obs_transition_video_render2(filter->context, shader_transition_video_callback, NULL); if (!filter->transitioning && filter->prev_transitioning) { if (obs_source_active(filter->context)) - shader_filter_param_source_action( - data, obs_source_dec_active); + shader_filter_param_source_action(data, obs_source_dec_active); if (obs_source_showing(filter->context)) - shader_filter_param_source_action( - data, obs_source_dec_showing); + shader_filter_param_source_action(data, obs_source_dec_showing); } filter->prev_transitioning = filter->transitioning; gs_set_linear_srgb(previous); @@ -3277,18 +2758,13 @@ static void shader_transition_video_render(void *data, gs_effect_t *effect) static void shader_transition_defaults(obs_data_t *settings) { - obs_data_set_default_string( - settings, "shader_text", - effect_template_default_transition_image_shader); + obs_data_set_default_string(settings, "shader_text", effect_template_default_transition_image_shader); } -static enum gs_color_space -shader_transition_get_color_space(void *data, size_t count, - const enum gs_color_space *preferred_spaces) +static enum gs_color_space shader_transition_get_color_space(void *data, size_t count, const enum gs_color_space *preferred_spaces) { struct shader_filter_data *filter = data; - const enum gs_color_space transition_space = - obs_transition_video_get_color_space(filter->context); + const enum gs_color_space transition_space = obs_transition_video_get_color_space(filter->context); enum gs_color_space space = transition_space; for (size_t i = 0; i < count; ++i) {