obs-shaderfilter icon indicating copy to clipboard operation
obs-shaderfilter copied to clipboard

Request for Normalized Float Uniform Parameter for Loop Animations

Open yanorei32 opened this issue 10 months ago • 4 comments

Original Issue: https://github.com/exeldro/obs-shaderfilter/issues/64

I appreciate the idea of using an integer to represent absolute time, especially for time-dependent applications. However, in my shader code, I have been using elapsed_time for short loop animations. I realized it would be ideal to have a normalized float uniform parameter that loops between 0.0 and 1.0 over a specified number of seconds.

Using non-normalized seconds makes it challenging to handle the continuity during the rollover, as the transition timing can be tricky to manage.

I apologize for the lack of explanation in the original issue and any inconvenience it may have caused.

Therefore, I kindly request the addition of such a uniform parameter to enhance the functionality of short loop animations and better support time-dependent applications.

The fake rotation animation ( for top-right "LIVE" )

float4 mainImage(VertData v_in) : TARGET {
	v_in.uv.x -= 0.5;
	v_in.uv.x *= rcp(sin(elapsed_time * 2));
	v_in.uv.x += 0.5;
	return image.Sample(textureSampler, v_in.uv) + float4(1, 1, 1, 0) * 0.3 * sin(elapsed_time * 4 + 3.14 / 4 - 3.14 / 8);
}

Expected Behaviour

https://github.com/user-attachments/assets/c9227912-2ae1-42a2-8e23-3aecc6103ce1

Actual Behaviour (After few days)

https://github.com/user-attachments/assets/e7ad95ee-45d6-49ba-a061-1caeb4d89841

yanorei32 avatar Feb 16 '25 02:02 yanorei32

Can't you use loop_second and loop instead of elapsed_time?

exeldro avatar Feb 16 '25 05:02 exeldro

Using loop_second and loop seems like a great idea!

However, I couldn't understand how to implement them from the current documentation. Specifically, I'm unclear on the relationship between loop_second and loops, and how to determine the duration in seconds for the loop.

Could you please provide more detailed guidance or examples on this?

yanorei32 avatar Feb 16 '25 14:02 yanorei32

ah, loop_second was broken, I fixed it now, you can find a test build at the bottom of this page when logged in: https://github.com/exeldro/obs-shaderfilter/actions/runs/13356749210

I tested with this, have not had it running for days yet

float4 mainImage(VertData v_in) : TARGET {
	float t = (loops - 314 * floor(loops /  314) + loop_second);
	v_in.uv.x -= 0.5;
	v_in.uv.x *= rcp(sin(t *2));
	v_in.uv.x += 0.5;
	return image.Sample(textureSampler, v_in.uv) + float4(1, 1, 1, 0) * 0.3 * sin(t * 4 + 3.14 / 4 - 3.14 / 8);
}

loop_second is a float going from 0.0 to 1.0 each second loops is incremented by 1 each second so the code above loops every 314 seconds

exeldro avatar Feb 16 '25 16:02 exeldro

Thank you!

In my case, that problem is completely resolved, because I don't stream longer than 48.545 days.

And I simplified example code as the following:

float t = loops % 314 + loop_second;

Is there any side-effects?

P.S. I think, users can face the stuttering each 48.545 days if streams more than 48.545 days. https://github.com/exeldro/obs-shaderfilter/blob/40886208c618733521cd5832e430db00e76f80b2/obs-shaderfilter.c#L2571-L2574

yanorei32 avatar Mar 05 '25 05:03 yanorei32