Log in

View Full Version : generate Dot matrix (help)


travolter
2nd August 2014, 19:35
Hi guys!

Im looking for this effect.


scanlines(90)
turnleft().scanlines(90).turnright()


There is any easier way to archive this effect?
Currently turnleft().scanlines(90).turnright() line consumes much cpu for my realtime spripts.

Any other way to overlay these dot matrix or other patterns?

I tested already with static noise generators.. but I prefer an ordered matrix. I find it useful to mask blocks.

Reel.Deel
2nd August 2014, 20:24
Are you talking about something like this? Maybe some mt_lutspa/mt_lutxy magic?

PointResize 3X
http://s11.postimg.org/87cyf2cir/Point_3_X.png (http://postimage.org/)


Dot Matrix 3X from Snes9X
http://s11.postimg.org/6tlbjrd9f/Dot_Matrix_3x.png (http://postimage.org/)

creaothceann
2nd August 2014, 20:54
http://forum.doom9.org/showthread.php?p=1683051 ?

travolter
3rd August 2014, 00:15
@Reel.Deel hey yes!!! this is the effect!!!

@creaothceann Ill check CRT emulation thread.. I hope it will be the solution.

Reel.Deel
3rd August 2014, 00:20
crt_display (http://forum.doom9.org/showthread.php?p=1683051) is indeed excellent, but it's also extremely slow. Maybe this Dot Matrix effect can be done a bit faster?

creaothceann
3rd August 2014, 00:47
I know the dot bloom filter (http://filthypants.blogspot.de/2011/05/more-emulator-pixel-shaders-crt-updated.html) from emulators, but unfortunately not for Avisynth...

travolter
3rd August 2014, 00:54
horizontal+vertical scanlines seem to be the easier way by now. crt_display requires so much


EDIT.- I wonder if any noise generator could be tweaked to create the effect. Avoid the random dots and generate ordered ones

raffriff42
3rd August 2014, 03:09
I experimented with mt_lutspa to make dots a while back, as part of my Avisynth dot crawl effect (https://www.dropbox.com/sh/g5eg0sngmz0l2w5/AACpZSFQPnp1RrNHvz47YNaca/dotcrawlplus.avsi), discussed in this thread (http://forum.doom9.org/showthread.php?t=170433).

https://www.dropbox.com/s/f65ukua4q0yean4/dotcrawlplus_makedots_1.png?raw=1## effect #1 - square dots
## Last = YV12
size=3 ## 1 to 5
mt_lutspa(mode="absolute", chroma="128",
\ expr=("""((((y/(2*$s))%2)>0) ? cos((x/$s)*pi) : -1*(cos((x/$s)*pi)))*108+126""")
\ .StrReplace("$s", String(size)).mt_polish)
return Last


https://www.dropbox.com/s/4swchf5povlp9br/dotcrawlplus_makedots_2.png?raw=1 ## effect #2 - round dots
## Last = YV12
size=3 ## 1 to 5
mt_logic(
\ mt_lutspa(mode="absolute", chroma="128",
\ expr=("""((((y/(2*$s))%2)>0) ? cos((x/$s)*pi) : -1*(cos((x/$s)*pi)))*108+126""")
\ .StrReplace("$s", String(size)).mt_polish),
\ mt_lutspa(mode="absolute", chroma="128",
\ expr=("cos((y/$s)*pi)*108+126")
\ .StrReplace("$s", String(size)).mt_polish),
\ "andn")
return Last



The script (https://www.dropbox.com/sh/g5eg0sngmz0l2w5/AACpZSFQPnp1RrNHvz47YNaca/dotcrawlplus.avsi) also has a function that animates the dots' X-position, to emulate NTSC dot crawl.

Just don't ask me how it works, I've forgotten.

EDIT - requires StrReplace # src = http://avisynth.nl/index.php/HDColorBars
function StrReplace(string base, string findstr, string repstr)
{
pos = FindStr(base, findstr)
return (StrLen(findstr)==0) || (pos==0)
\ ? base
\ : StrReplace(
\ LeftStr(base, pos-1) + repstr +
\ MidStr(base, pos+StrLen(findstr)),
\ findstr, repstr)
}

StainlessS
3rd August 2014, 10:18
RaffRiff42, whenever you post that script (EDIT: StrReplace) it perhaps should be noted that for any resultant string of (n*4096-1) length
(including any temporary substrings produced during recursion) will result in error in Avisynth v2.58.
(Perhaps also should be noted in Wiki).
For your use in that script it would not be an issue as only short strings involved, but if someone uses for other purpose, then could be a problem.
http://forum.doom9.org/showthread.php?p=1566935#post1566935

EDIT: RT_Stats has function RT_StrReplace that does not suffer from this problem on v2.58 (or v2.6a3).
Also has RT_StrReplaceMulti() that simutaneously replaces multiple different strings.
Also, RT_StrReplaceDeep() which allows to eg replace mutliple SPACE characters with a single SPACE.

raffriff42
3rd August 2014, 14:21
Thanks StainlessS, that will be useful for future scripts that use long strings. Hopefully I will never need MaskTools expressions anywhere near that long!

Here's a script that comes close to "Dot Matrix 3X from Snes9X" above: ##Last=YV12

size=1
return Overlay(
\ Overlay(gridmask_square(size), mode="softlight", opacity=0.3),
\ mode="lighten", opacity=1.0)

function gridmask_square(clip C, int size)
{
C
return mt_logic(
\ mt_lutspa(mode="absolute", chroma="-128",
\ expr=("""cos(x / $s * pi) * 108 + 126""")
\ .StrReplace("$s", String(size))
\ .mt_polish ),
\ mt_lutspa(mode="absolute", chroma="-128",
\ expr=("cos(y / $s * pi) * 108 + 126")
\ .StrReplace("$s", String(size))
\ .mt_polish ),
\ "andn")
}

## alternate grid
function gridmask_diag(clip C, int size)
{
C
return mt_logic(
\ mt_lutspa(mode="absolute", chroma="-128",
\ expr=("""(cos(x / $s * pi) * ((y / 2 * $s % 2) > 0) ? 1 : -1) * 108 + 126""")
\ .StrReplace("$s", String(size)).mt_polish),
\ mt_lutspa(mode="absolute", chroma="-128",
\ expr=("cos(y / $s * pi) * 108 + 126")
\ .StrReplace("$s", String(size)).mt_polish),
\ "andn")
}

travolter
3rd August 2014, 16:07
@raffriff42 thanks a lot!! your functions are working really nice!.. A pity that overlay consume so much CPU but the effect over the image looks really nice.

Btw scanlines.dll approach continue being faster for realtime. Ill continue searching alternatives

jmac698
4th August 2014, 09:58
I've run into these issues before, I have a few tips. First, for making your dots mask, trim it to one frame, it will be faster (I'm told). Second, overlay is really slow because it converts and interpolates everything to it's own format before operating. Layer is much faster if you can work around it. There's probably some knowledge in my drawrect function that's useful.

Finally, I wrote that HDcolourbars function. The strreplace was based on avslib.

Reel.Deel
4th August 2014, 12:58
Couldn't Overlay be replaced by mt_lutxy? Small example (http://forum.doom9.org/showpost.php?p=1432971&postcount=2) here.


HI there jmac698, nice to see you around.

fvisagie
4th August 2014, 14:05
In some cases you can substitute Overlay() with mt_merge (http://forum.doom9.org/showthread.php?t=166469) which is much faster.

raffriff42
4th August 2014, 18:29
Yeah, my use of Overlay is purely due to laziness,
Turns out using MaskTools is much faster - or about half the CPU load at the same frame rate. ## OLD WAY:
#return Overlay(
#\ Overlay(gridmask_square(1), mode="softlight", opacity=0.3),
#\ mode="lighten", opacity=1.0)

## NEW WAY:
return mt_blend_lighten(
\ mt_blend_softlight(gridmask_square(1), opacity=0.55),
\ opacity=1.0)

## simplified functions, based on uu_mt_blend
## see "Mask Tools blending modes," http://forum.doom9.org/showthread.php?t=170490

function mt_blend_lighten(clip C, clip D, float "opacity")
{
opacity = Float(Min(Max(0, Default(opacity, 1)), 1))
return mt_lutxy(C, D,
\ yexpr=("max($x, $y) "
\ + "* 256 * $o + (x * (1-$o)) ")
\ .StrReplace("$x", "(x/256.0)" )
\ .StrReplace("$y", "((1-$o)*x/256.0 + $o*y/256.0)" )
\ .StrReplace("$o", String(opacity))
\ .mt_polish(),
\ U=1, V=1)
}

function mt_blend_softlight(clip C, clip D, float "opacity")
{
opacity = Float(Min(Max(0, Default(opacity, 1)), 1))
return mt_lutxy(C, D,
\ yexpr=("((1-$y) * $y * $x + ($y * (1 - (1-$y) * (1-$x)))) "
\ + "* 256 * $o + (x * (1-$o)) ")
\ .StrReplace("$x", "(x/256.0)" )
\ .StrReplace("$y", "((1-$o)*x/256.0 + $o*y/256.0)" )
\ .StrReplace("$o", String(opacity))
\ .mt_polish(),
\ U=1, V=1)
} mt_blend_softlight() is not a perfect replacement for Overlay(mode="softlight"); I had to adjust the opacity a bit.

Tried gridmask_square(1).Trim(0, -1).Loop() but it made no difference. Seems like the Avisynth cache is working very well.

travolter
5th August 2014, 20:06
I tested the new versions using MaskTools, but scanlines.dll continue performing faster for realtime.

I have checked the scanlines package
http://avisynth.nl/users/warpenterprises/files/scanlines_5F25_dll_20031103.zip

and it contains the source. I wonder if it can be tweaked to create dot matrix or just vertical lines to mix along the horz. lines.

I dont have compilers to do myself and test. Anyone?

TheFluff
6th August 2014, 01:22
It's like the simplest Avisynth plugin you could possibly write. If you look at the source file you'll find that it's seventy-two (72) lines long, and 18 of those is the license header. The rendering loop, which multiplies the pixel values on every second line by a given scale factor, is six (6) lines including curly braces. But why write 6 lines of C++ when you can write 60 lines of masktools abuse and run an order of magnitude slower? It's the cool thing to do, apparently!

If you're afraid of compilers you could also do it trivially in Python using VapourSynth but it's probably not going to be very fast. Simple to implement, though.

Reel.Deel
6th August 2014, 03:13
I'm sure writing a plugin for a specific task can yield faster results, unfortunately there are those (like me) who are not programmers and have to rely on existing plugins. Also the script in post #15 (http://forum.doom9.org/showthread.php?p=1688909#post1688909) without the unnecessary comments, StrReplace, and mt_polish() can probably be reduced down to around 10 lines. Regardless, what's the point of MaskTools if it can't be abused? :p

----

FWIW the source code for DotMatrix3X is somewhere here? (https://github.com/snes9xgit/snes9x/blob/master/win32/render.cpp#L1576).

raffriff42
6th August 2014, 06:14
If you can ignore everything but your inner loop and claim your solution is '6 lines of C++', I can say my script is really 4 lines - namely the four MaskTools calls. Mt_lutspa & mt_lutxy are pretty fast, once they are initialized. The rest executes once only, and so has no effect on the 'render loop', any more than your support code does.

Anyway, I normally don't care too much about performance, as I'm not rendering in real time. If the OP does care, this is not the solution for him. Others (it's a big Internet) may prefer the tweakability of a script, rather than having to use someone's canned effect.

Yes the script is an absurd way to generate a simple grid pattern, but Avisynth 'abuse' can be fun, as hanfrunz demonstrates here (http://forum.doom9.org/showthread.php?t=169943) much better than I ever could. I enjoyed fiddling with this script; I learned a few things that may be useful later, and shared them. So in that sense it was kinda 'cool.' People like doing things for the hell of it sometimes (http://esolangs.org/wiki/Lazy_K).

I'm not 'afraid' of compilers, but creating C++ DLL's is just not fun for me, as I don't do it often enough. I do have a strong 'fear' (if you please) of Python and Vapoursynth.

StainlessS
6th August 2014, 23:39
@ TheFluff,

You seem to take things way too personal, like someone insulted you.
Why is that ?
From what I have seen, you are an ex-developer who likes to tell other people what to do, (stop with the -ve vibes)
despite the fact that you dont have more than a single Avisynth plug and a some plug wrapper
to your name in total. I personally think that you need to re-evaluate how you are perceived,
as some kind of constant whining ex dev. If you, (personally are prepared to do something,
well anything really), then people might think that you are actually current, rather than someone who used
to have a clue what was what.
I cant knock everything you say (how could I) but you do not do anything but whine, (a lot of what you say
is totally sensible or 'right-on', but you do come across as a bit of an **** at times, please stop that).
(PS, for those not in the UK area, a Fluff is a Fart, silent but deadly. Most unpleasant most of the time.)
PPS, I'm quite unpleasant also, but not to the same degree.

PPPS, (not totally sober), several hours ago got (Lets not disguss this, Im sure its really quite acceptable), Legally Blond II,
The Girl with the Dragon Tattoo, Sky Captain & World Of Tomorrow (no idea what that was
but 25 pence so who cares), Lock Stock & Two Smoking Barrels, (Pure Genious), and SMASH, the reason for my complete
re-evaluation of Brad Pitt. Total £6.75, can't be bad. (I aint American, but if Ronny can do it then so can Brad, BIG fan now,
also, Inglorious Bastards (Tarentino as guest I think), love that Brad Accent, totally turned around on that guy,). (Mainly Smash).

EDIT: The "Excessivly Jovial Fellow" thing is obviously referrng to TheFluffs reall quite cantakerous (speelling), persona,
wanted to post on TheFluffs post earlier, but waited until had a few beers. (was really quite unhappy with what you/he said,
my post would not have been so measured, somewhat more Fluff like).

EDIT: Above references to SMASH should have read SNATCH. way too much beer.

EDIT: I really should have posted this in JMac's thread in development, it was mainly that post that wound me up.