Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] follow with filter target scaling changes #2

Closed
yuniruyuni opened this issue Nov 26, 2024 · 6 comments
Closed

[feature request] follow with filter target scaling changes #2

yuniruyuni opened this issue Nov 26, 2024 · 6 comments

Comments

@yuniruyuni
Copy link
Contributor

Hiya. Thank you for creating good obs filter! 👍

But unfortunately, this filter seems not follow parent(or target) source or scene's transform changes. Currently, if filter target was scaled, this filter's output image is just scaled with normal algorithms.
If this is implemented, user can use image as like a "component" and very smooth to use it.
(i.e. users can manage the "component" size with just scaling on OBS UI.)

So I want to request the feature to follow parent source transform.

@nitz
Copy link
Contributor

nitz commented Nov 26, 2024

Hey yuni, thanks for the kind words.

I ran into a fair amount of issues with sizing when I was originally working on this filter. Unfortunately, as best as I could determine (and best as I can remember at this moment, there was a fair amount of information I was unable to access at the stage in rendering that the filter applies. I recall being unable to determine the size of the eventual render target (which would be needed in order to calculate how much to scale in your example there.) This is the same thing that stopped me from working on trying to get "pixel perfect" outputs to work nicely as well.

If there's something I've missed and someone with more OBS knowledge wanted to take a whack at it, I'd be wildly appreciative; I just don't see a path forward as it currently stands.

@yuniruyuni
Copy link
Contributor Author

Thank you. I have also checked libobs code and get same conclusion 😢

The points are followings:

  1. We need obs_transform_info value from obs_scene object to decide the last rendering size. But we cannot access it from module(plugin) system because we can define each filter as a source and it cannot access to scene.
  2. Sometimes, OBS (parent/target) source uses filter_texrender mode and it hide video texture and effect from filter's source video_render method.

In this case, it is desired to implement rendering mode on libobs side. Especially, extend scene's scaling engine is better...

@yuniruyuni
Copy link
Contributor Author

yuniruyuni commented Nov 26, 2024

ah... wait, just I have an idea for getting obs_transform_info from scene.

maybe we can use obs_enum_scenes() and check which scene contains ourselves...(by recursive check to find it.)
But it's just an idea, I have not yet checked it... I'll try it tomorrow.

(Anyway, if we use this way, we cannot put same(duplicated) source onto two scenes...)

@yuniruyuni
Copy link
Contributor Author

yuniruyuni commented Nov 27, 2024

maybe, we can obtain the scene info from following code (But I'm not sure because I cannot build this plugin on my environment...)

struct cb_data {
	obs_source_t *parent;
	obs_sceneitem_t *found;
};
typedef struct cb_data cb_data_t;

static bool enum_scenes_callback(void *data_ptr, obs_source_t *scene_source)
{
	cb_data_t *data = data_ptr;

	obs_source_t *scene = obs_group_or_scene_from_source(scene_source);
	if (!scene)
		return true;

	obs_sceneitem_t *found = obs_scene_find_source_recursive(
		scene, obs_source_get_name(data->parent));
	if (!found)
		return true;

	// found the scene-item that contain our source!
	data->found = found;
	return false;
}

static void filter_render(void *data, gs_effect_t *effect)
{
	UNUSED_PARAMETER(effect);

	struct filter_9slice *context = data;
	if (!context) {
		return;
	}

	obs_source_t *parent = obs_filter_get_parent(context->source);

	struct cb_data target = {
		.parent = parent,
		.found = NULL,
	};
	obs_enum_scenes(enum_scenes_callback, &target);

	struct vec2 scale = {.x = 1.0f, .y = 1.0f};
	if (target.found) {
		scale = target.found->scale;
	}

	const float width = obs_source_get_width(parent) * scale.x;
	const float height = obs_source_get_height(parent) * scale.y;

	context->last_source_size.x = (float)width;
	context->last_source_size.y = (float)height;

	const struct vec2 output_size = {
		.x = width * context->output_pixel_scale.x,
		.y = height * context->output_pixel_scale.y};

	if (!obs_source_process_filter_begin(context->source, GS_RGBA,
					     OBS_ALLOW_DIRECT_RENDERING))
		return;

	struct filter_9slice_params_t *params = &context->params;

	gs_effect_set_vec4(params->border, &context->border);
	gs_effect_set_vec2(params->source_size, &context->last_source_size);
	gs_effect_set_vec2(params->output_size, &output_size);
	gs_effect_set_bool(params->show_uvs, context->show_uvs);
	gs_effect_set_bool(params->use_linear_filtering,
			   context->use_linear_filtering);

	obs_source_process_filter_end(context->source, context->effect, width,
				      height);
}

how do you think about it...? @nitz

@yuniruyuni
Copy link
Contributor Author

@nitz I have created a pull request related with this: #3
Could you please check it 🙇

And sorry for huge patch size because of build pipeline fix (by importing latest obs-plugintemplate).
If you want to split the implementation and update, take easy to tell me about that, I'll split the PR.

nitz pushed a commit that referenced this issue Dec 2, 2024
bugfix: too strong slice restriction for first open
@yuniruyuni
Copy link
Contributor Author

I'll close this issue because the feature is now implemented. Thank you review and advice about it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants