'Silhouette-bleeding' for alpha'd mipmaps
Posted: 2019-05-09T08:08:07-07:00
I've been working on a pretty convoluted script (typical of me) for doing what I call "silhouette bleeding", which essentially bleeds-out colour from the peripheries of an alpha-channel outward, so the texture can be mipped without the black "background" causing trouble at lower mip-map stages, which can cause artifacts.
As seen on this page (*although it's using Photoshop script):-
https://docs.unity3d.com/Manual/HOWTO-alphamaps.html
And here is my chunky-ass BAT, although it's only using 20 'runs', ideally it would be more like 100+:-
I was just wondering if there's a better way this could be done with ImageMagick?
I'm basically dilating and blurring both RGB and alpha over and over in the first chunk, the composing everything back in together in reverse, and finally putting the original image back in to that and restoring the original alpha. The outcome is more or less the same, so far, but it takes a damn long time and as you can see it's already chunky at just 20.
As seen on this page (*although it's using Photoshop script):-
https://docs.unity3d.com/Manual/HOWTO-alphamaps.html
And here is my chunky-ass BAT, although it's only using 20 'runs', ideally it would be more like 100+:-
Code: Select all
::----------------------------
:: silhouette-bleeding
::----------------------------
convert input.tga -channel alpha -separate -define png:format=png24 alpha.png
convert input.tga -channel RGB -separate -define png:format=png24 color_chn.png
::----------------------------
convert color_chn-0.png color_chn-1.png color_chn-2.png -channel RGB -combine -define png:format=png24 rgb.png
::----------------------------
convert alpha.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl01.png
convert rgb.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl01.png
convert alpha_dl01.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl02.png
convert rgb_dl01.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl02.png
convert alpha_dl02.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl03.png
convert rgb_dl02.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl03.png
convert alpha_dl03.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl04.png
convert rgb_dl03.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl04.png
convert alpha_dl04.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl05.png
convert rgb_dl04.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl05.png
convert alpha_dl05.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl06.png
convert rgb_dl05.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl06.png
convert alpha_dl06.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl07.png
convert rgb_dl06.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl07.png
convert alpha_dl07.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl08.png
convert rgb_dl07.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl08.png
convert alpha_dl08.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl09.png
convert rgb_dl08.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl09.png
convert alpha_dl09.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl10.png
convert rgb_dl09.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl10.png
convert alpha_dl10.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl11.png
convert rgb_dl10.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl11.png
convert alpha_dl11.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl12.png
convert rgb_dl11.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl12.png
convert alpha_dl12.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl13.png
convert rgb_dl12.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl13.png
convert alpha_dl13.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl14.png
convert rgb_dl13.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl14.png
convert alpha_dl14.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl15.png
convert rgb_dl14.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl15.png
convert alpha_dl15.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl16.png
convert rgb_dl15.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl16.png
convert alpha_dl16.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl17.png
convert rgb_dl16.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl17.png
convert alpha_dl17.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl18.png
convert rgb_dl17.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl18.png
convert alpha_dl18.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl19.png
convert rgb_dl18.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl19.png
convert alpha_dl19.png -morphology dilate octagon:1 -gaussian-blur 1x1 alpha_dl20.png
convert rgb_dl19.png -morphology dilate octagon:1 -gaussian-blur 1x1 rgb_dl20.png
::----------------------------
convert rgb_dl20.png rgb_dl19.png alpha_dl19.png -compose over -composite cmb_dl19.png
convert cmb_dl19.png rgb_dl18.png alpha_dl18.png -compose over -composite cmb_dl18.png
convert cmb_dl18.png rgb_dl17.png alpha_dl17.png -compose over -composite cmb_dl17.png
convert cmb_dl17.png rgb_dl16.png alpha_dl16.png -compose over -composite cmb_dl16.png
convert cmb_dl16.png rgb_dl15.png alpha_dl15.png -compose over -composite cmb_dl15.png
convert cmb_dl15.png rgb_dl14.png alpha_dl14.png -compose over -composite cmb_dl14.png
convert cmb_dl14.png rgb_dl13.png alpha_dl13.png -compose over -composite cmb_dl13.png
convert cmb_dl13.png rgb_dl12.png alpha_dl12.png -compose over -composite cmb_dl12.png
convert cmb_dl12.png rgb_dl11.png alpha_dl11.png -compose over -composite cmb_dl11.png
convert cmb_dl11.png rgb_dl10.png alpha_dl10.png -compose over -composite cmb_dl10.png
convert cmb_dl10.png rgb_dl09.png alpha_dl09.png -compose over -composite cmb_dl09.png
convert cmb_dl09.png rgb_dl08.png alpha_dl08.png -compose over -composite cmb_dl08.png
convert cmb_dl08.png rgb_dl07.png alpha_dl07.png -compose over -composite cmb_dl07.png
convert cmb_dl07.png rgb_dl06.png alpha_dl06.png -compose over -composite cmb_dl06.png
convert cmb_dl06.png rgb_dl05.png alpha_dl05.png -compose over -composite cmb_dl05.png
convert cmb_dl05.png rgb_dl04.png alpha_dl04.png -compose over -composite cmb_dl04.png
convert cmb_dl04.png rgb_dl03.png alpha_dl03.png -compose over -composite cmb_dl03.png
convert cmb_dl03.png rgb_dl02.png alpha_dl02.png -compose over -composite cmb_dl02.png
convert cmb_dl02.png rgb_dl01.png alpha_dl01.png -compose over -composite cmb_dl01.png
::----------------------------
convert cmb_dl01.png rgb.png alpha.png -compose over -composite final.png
::----------------------------
convert final.png -channel RGB -separate -define png:format=png24 final_chn.png
convert final_chn-0.png final_chn-1.png final_chn-2.png alpha.png -channel RGBA -combine ouput.tga
::----------------------------
::del rgb*.png
::del alpha*.png
::del color*.png
::del final*.png
::del cmb*.png
pause
pause
pause
I was just wondering if there's a better way this could be done with ImageMagick?
I'm basically dilating and blurring both RGB and alpha over and over in the first chunk, the composing everything back in together in reverse, and finally putting the original image back in to that and restoring the original alpha. The outcome is more or less the same, so far, but it takes a damn long time and as you can see it's already chunky at just 20.