Sonic Ether
12th October 2005 06:06 UTC
Help with minor code issue
Ok, I'm getting the whole DM thing down. Now, I can create decent DMs. But I do have one question. What would be a basic way to smooth movement? Because I've got alot of jerky presets and I would like to know if there is a way to smooth the movement. Can anyone help me?:D
^..^
12th October 2005 11:44 UTC
There are many ways to make movements smoother. Let me suggest you two quite simple ways. Just try which one fits best to the kind of movement you use. (The beat code is just 'random' code i used in these examples and you can replace it with any kind of music-reaction you want).
frame:
t=t*0.95+tb;
---------------------
beat:
tb=(rand(100)+1)*0.005
or this one:
frame:
t=t+tb;
tb=tb*0.95;
---------------------
beat:
tb=(rand(100)+1)*0.005
Also it might be interesting for you to have a look into some AVS-tutorials and help-documents listed in this
thread.
btw: Please post such questions in the
AVS Troublshooting subforum to help keeping the forum tidy. ;)
hboy
12th October 2005 16:40 UTC
you say that you can do decent DMs and then ask about smooth movements? wow.
^..^
12th October 2005 16:50 UTC
Maybe to him "decent dm" means something else than to us! Perhaps every dm that is more complicated than the example ones are decent to him? But im just guessing... :igor:
StevenRoy
12th October 2005 20:57 UTC
Smooooth motion, the StevenRoy way
Here's the way I do it:
Suppose I had a variable "dx", which I want to set to a random value between -1 and 1 on each beat. The simplest way to do that, of course, is to put this in the Beat code:
dx=(rand(201)-100)*.01
Now that's all well and good, but it does have that jerkiness problem. My favourite way to smooth out the motion is quite similar to what ^..^ described:
Frame:
dx=dx*.9 + tdx*.1
Beat:
tdx=(rand(201)-100)*.01
This causes dx to slide towards tdx (I use the extra t to mean "target"), at a rate proportional to their difference. In other words, it starts out quickly and slows down as it nears its target. To adjust the speed of this transition, you can change the .9 and .1 coefficients to other values, such as .95 and .05, or even .99 and .01 to make it nice and slow. (These coefficient pairs should add up to 1; it's not necessary, but it makes it easier to know what you're getting.)
In most cases, this is pretty good... but every time tdx changes, dx starts homing towards it, and it's a sudden, jerky start. Surprisingly, the way to fix this start is simply to repeat the process; add another target variable and make that the target of our first target variable.
It ends up looking something like this:
Frame:
dx=dx*.9 + tdx*.1;
tdx=tdx*.95 + ttdx*.05;
Beat:
ttdx=(rand(201)-100)*.01
Voila. Smooth motion. (Notice that I gave the tdx->ttdx motion different values to slow it down a little.)
Now, if you're
really anal about code optimization, you may notice that ttdx is being multiplied my the same value once per frame, even though it doesn't change. This multiplication can be moved to the onbeat code for a very, very slight performance boost. (Most of the time, I don't bother.) The same goes for the tdx multiplication, for a similar reason. You can end up with code that looks like this:
Frame:
dx=dx*.9 + tdx;
tdx=tdx*.95 + ttdx;
Beat:
ttdx=(rand(201)-100)*.00005
It's not uncommon for me to use code like this several times in a single Dynamic Movement.
Of course, it usually takes more than smooth motion to make a good AVS preset, but it usually helps.
Warrior of the Light
12th October 2005 22:15 UTC
Sonic Ether: Perhaps you could give us an example preset of what you exactly mean by decent DM's, and perhaps a better explanation of 'smooth movement', before everybody is getting all exited over perhaps the wrong thing.
hboy
13th October 2005 19:04 UTC
yup. by the way, my first dm was a smooth little x=x+0.05. yeah.
Sonic Ether
3rd November 2005 05:52 UTC
Haha, sorry for the late reply, I've been buisy lately. Ok, I'll send you an example, but I want it to be smooth... so check it out. I KNOW IT'S MESSY, I'M NOT PERFECT! Haha, I'm not so anal about clean code :)
Mr_Nudge
5th November 2005 11:06 UTC
i haven't seen the preset..basically because my laptop can't run avs. but smooth movement can be made the way everyone so far has told you..so i might as well give you my version
frame-----
a=a*0.9+a1*1.1
beat------
a1=rand(100)*0.0001
that way 'a' will change values between 1 & -1 smoothly and won't stop instantly..it'll kind of 'slide' for a while and then stop slowly
DummyDDD
9th November 2005 20:59 UTC
I think that the movement looks pretty smooth (and the preset look pretty nice too :)), what you may think of as jerky movement may be caused by a low fps (or worse yet changeing fps), or by the "dark edges".
What i mean by dark edges is just the 4 spectrums at each side of the screen, which are transformed across the screen.
To prevent thoose edges you should reduce the edges by reducing the zooming of the movement. You also could add a virtual effect\AddBorders outside of the effect list (I know it's a crappy solution, but it's used quite often).
If you want to boost the fps of the preset you can set the first convolution filters scaling to 32 (because n^2 scalings are faster, 1, 2, 4, 8, 16...), this will affect the luminance some. You can also integrate the movement into the first dynamic movement, this will affect the luminance even more.
I've attached an altered version of the preset which should have less jerky movement.