set blur strength to sprite speed

For questions about using Classic.

Post » Tue Oct 23, 2012 3:56 pm

Well, yes, you are missing 2 things

1) FormatDecimal is a function that outputs a string, I used it to format the string in the text box. Just omit it.
2) Sprite('dist') / 20 will be a relative number [0, 1] If the blur shader you're using accepts a strength value in that range, then everything's ok. Else you need to transform the value just like in the first cap, I uploaded here, but for the value range the blur shader expects.

You are close to a result. Step by step we will get it right.
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Oct 23, 2012 9:20 pm

i have to admit i really suck at this...

after a few hours and big pile of ripped hair on my keyboard, i admit defeat. theres just something i cant figure out for the life of me and i dont even know what it is

though i fear its something really simple and in your face- stuff. i tried like a million different things, resulting in pretty much me placing random stuff with my eyes closed hoping to get it.

but no such luck, maybe im just stupid.    clodius6662012-10-23 21:23:32
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Wed Oct 24, 2012 4:35 pm

[QUOTE=clodius666]but no such luck, maybe im just stupid.    [/QUOTE] You definitely are not!

There's so many things that could prevent a desired result. For example, whatever the blur effect is you're using, it might not expect the value range that you use. Or it might be programmed to not be reliably alterable in runtime. There is a lot that might not work.

I extended my "speed measurement" example. This time the sprite has a "pattern" effect and the left scale of the sprite is changed from 100% to 0% while gaining speed (from 0 to 80 px/s). It uses nothing more than the calculations and rules I explained in this thread.

http://db.tt/nnzTp9e5
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Wed Oct 24, 2012 7:21 pm

turned out i wasnt THAT far off yesterday when i gave up

i managed to finally produce somewhat satisfying results, using "Blur motion" effect on a layer. didnt try any other blur methods yet, but it looks atleast promising. although one extra question came to my head(not really surprising issue since i kinda knew to expect it):

since all this you have shown me takes notice of the sprites movement, whatever the direction, there needs to be some sort of "leeway" at the beginning of the calculation for the sprite's speed. for example:

when the player jumps, it causes slight blur to be applied and i would assume that would start to cause a strain for the eyes. so i got to think. how would all this be calculated NOT from the start, but allowing some speed to build up before the blur starts appearing?

for example, the speed value is calculated at the moment from 0px/s to, say 100px/s. to prevent the blur flickering, it would have to be within the values of for example from 20px/s to 100px/s. just to allow some starting movement and jumping in place without the blur?
B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Wed Oct 24, 2012 8:05 pm

If you carefully look at some of the older posts, you will find the almost appropriate formula

relative value = (current - min) / (max - min)

If we test this with values, the results are almost right. For current = 20 and current = 100, while max = 100 and min = 20 we get

rv = (20 - 20) / (100 - 20) = 0 / 80 = 0
rv = (100 - 20) / (100 - 20) = 80 / 80 = 1

The only problem is that current could become less than 20, e.g. 0:

rv = (0 - 20) / (100 - 20) = -20 / 80 = -0.25

To avoid that there are a few solutions. The easiest from my point of view is to just cut out everything below 0 by making it being 0 too:

rv = max((current - min) / (max - min), 0)

max(a, b) will return the higher of the two values. For the example of current being 0 it would result in

rv = max((0 - 20) / (100 - 20), 0) = max(-20 / 80, 0) = max(-0.25, 0) = 0


EDIT
You can also limit everything to certain angles. Angle detection works almost the same as speed detection, just exchange the "distance between points" expression with the "angle between points" expression. You'd store the current angle in a pv and use a condition that compares this pv with the allowed angles before calculating the blur strength and else set the blur strength to 0.tulamide2012-10-24 20:12:02
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Wed Oct 24, 2012 10:25 pm

i read that through about a hundred times and i feel i sprained something in my head

"rv = max((current - min) / (max - min), 0)"

so. i need to add a new calculation before the old calc?.
if we go by the latest of your .caps:

100 - ((Sprite('dist') / TimeDelta / 80) * 100)

start value would be for example 20 px/s and max would be 80px/s in this case.

dist/TimeDelta/80

you'd think it would be easy to just throw the 20 somewhere there after dist, but i cant get it to work

using 20 and 80 would result in a negative value, correct?

im just not sure what and exactly where i should be adding something in that dist/timedelta/80 formula.



B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Wed Oct 24, 2012 11:47 pm

Welcome to tula's school of mathematics! ( sorry, I couldn't resist)

Always remember the formula and then think about what parts belong to what name in the formula. For example:

Sprite('dist') / TimeDelta / 80

Here we use real values and variables instead of the names in the formula. Also don't forget that we omitted 'min', because it is always 0 in this example. The formula here was just 'current / max'.

Let's first assign the real values to the names of the formula:

Sprite('dist') / TimeDelta / 80

where red = current, and blue = max. Now we have to add 'min' back into the formula:

(current - min) / (max - min)

Replace the colored parts with the real values. You get

(Sprite('dist') / TimeDelta - min) / (80 - min)

Next step is to replace min by a value of your choice, for example 20 px/s:

(Sprite('dist') / TimeDelta - 20) / (80 - 20)

And last but not least you have to use max(a, b):

max( (Sprite('dist') / TimeDelta - 20) / (80 - 20), 0 )

Done

Extended the cap again, this time using globals that match the names of the formula (like 'current', 'maximum', 'minimum' and 'relative_value'). The scale effect will not start until the sprite is 20 px/s fast (or whatever value you set the global 'minimum' to): http://db.tt/8OB13G0C
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Oct 25, 2012 4:54 pm

well sh*t, it works beautifully!

finally i get it. at least i think i do
now its just a matter of trial and error to get the blur values just right but thats easily and quickly done. i already started thinking that i could make a top layer, scroll 0, stretch a sprite over the layer, make a transparent hole in the center, set position to player, use that blurmask effect someone made here, then apply this code to be used on the blurmask opacity, for example, sprite speed less than 20 px/s ---> set blurmask opacity to 0, and so on.. that could work really well!

this also raised another question:
could this be implemented on making 2 layers with different scroll rates communicate with each other, considering the collisions and overlapping? i remember seeing a thread long ago where this was briefly discussed, but couldnt find it.

another thing: do you have any idea why the built in motion blur is so frigging heavy? its kind of a shame too, since it looks really good.

the reason i got caught up on this was because i recently bought the new doom 3 bfg edition, and while it may not be as solid as all the mods for the original(i wouldnt know, i havent gotten the best mods to work), what really struck me was the added motion blur, that looks just absolutely stunning and delicious, combined with the rock solid no less than 60 fps. the fact that the blur affects everything else but the players hands and weapons gives the picture a surprising amount of depth
and looks really great.

but anyway, thank you so much for educating me on this matter, instead of just giving me a simple code, now i understand what it does

ill be sure to give you credit whenever i get something finished with construct, once again its nice to see theres helpful people around here!


B
4
S
2
G
2
Posts: 109
Reputation: 1,318

Post » Fri Oct 26, 2012 1:31 pm

You're welcome

Motion blurring in display size involves several frames to be morphed. There might be a rendering of 8 or 16 frames in display size for just one output frame. I'm not sure though if this is the way Ashley implemented it.

I look forward to seeing your results!
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Previous

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 4 guests