Old 18th June 2020, 06:10   #1
NeonAngel
Junior Member
 
Join Date: Jun 2020
Posts: 7
Aspect Ratio for Preset Sampler Images

I have a problem trying to get sampler images used in presets to display without any stretching. In the example below (see .milk file attached), the image displays correctly if it is a SQUARE image - so it will just touch each side, with no distortion, and the top and bottom are correctly cropped. (see first image - the white area illustrates what screen will look like in widescreen). Perfect.



If it is a wide or tall image though, it will be horribly distorted and will only look perfect when the image's aspect ratio matches EXACTLY the screen's aspect ratio. What am I doing wrong?

warp_1=`sampler sampler_mandala;
warp_2=`
warp_3=`shader_body
warp_4=`{
warp_5=` // sample previous frame
warp_6=` ret = tex2D( sampler_mandala, uv);
warp_7=`}
comp_1=`shader_body
comp_2=`{
comp_3=` ret = tex2D(sampler_main, (uv-0.5)*aspect.xy+0.5).xyz; //Works OK only if image ratio is SQUARE
comp_4=` ret *= 1.00; //gamma
comp_5=`}

Image is very distorted on a square screen:


Original tall image - the white area shows what it should look like on a square screen:


Widescreen image - the white area shows what it should look like on a square screen:


I am busy preparing a comprehensive set of sampler presets for a new MilkDrop based VJ application called NestDrop. It will also include a new sprite function that is going surprise quite a few people! 8196x8196 at 60fps x 4 screens is possible - all with full spout output to any compatible application - and free!
Attached Files
File Type: milk SAMPLER-xmuzack + cope - milkboom.milk (2.0 KB, 107 views)
NeonAngel is offline   Reply With Quote
Old 18th June 2020, 18:02   #2
Nitorami
Major Dude
 
Join Date: Mar 2008
Location: Erlangen
Posts: 888
Read the milkdrop preset authoring guide to understand how to map Images to the screen.
Btw you better sample your image in the comp shader, unless you have a specific reason to take the detour via the warp shader.
Nitorami is offline   Reply With Quote
Old 18th June 2020, 18:27   #3
NeonAngel
Junior Member
 
Join Date: Jun 2020
Posts: 7
Apologies for previous post - for some reason the images didn't show up. So i'll have another go...

In the first attached image (square green mandala), the left side is the original image - the right shows what it currently looks like in widescreen output. It's perfect as it's centred, not distorted, and just touches the edges. The code in the previous post works great here.

In the second attached image, however, (tall huichol mask), the left side shows the original tall image, but instead of keeping the correct proportions, it will be horribly stretched and distorted horizontally in widescreen as shown on the right. The original image will actually only look perfect when the image's aspect ratio matches EXACTLY the screen's aspect ratio.

Similarly for the third attached image (bosch painting), again with the original on the left, when in widescreen it now stretched vertically as shown on the right. Also just like the second example, the original image will actually only look perfect when the image's aspect ratio matches EXACTLY the screen's aspect ratio.
Attached Thumbnails
Click image for larger version

Name:	1-mandala.jpg
Views:	104
Size:	294.8 KB
ID:	54587   Click image for larger version

Name:	2-mask.jpg
Views:	100
Size:	235.5 KB
ID:	54588   Click image for larger version

Name:	3-bosch.jpg
Views:	94
Size:	303.6 KB
ID:	54589  
NeonAngel is offline   Reply With Quote
Old 18th June 2020, 19:13   #4
Nitorami
Major Dude
 
Join Date: Mar 2008
Location: Erlangen
Posts: 888
Just read! the! preset! authoring! guide!
Nitorami is offline   Reply With Quote
Old 18th June 2020, 19:28   #5
NeonAngel
Junior Member
 
Join Date: Jun 2020
Posts: 7
Thanks Nitorami. I am collaborating on a project where I am gathering every preset I can find that uses sampler images, around 40-50 different ones in total, and then setting about changing the images and making some minor code tweaks, usually just by trial and error. Otherwise I have no skills at all in preset authoring and find the code extremely difficult to understand. Nonetheless, the results I am getting are beautiful, it's only this issue that's causing a problem for some of the images and presets.

I have read the preset authoring guide re aspect ratios, and managed to make the change using 'aspect.xy', but it only works for square images. The only other solution I can think of is to convert the tall or wide images to square-shaped, so they stay in the correct proportions whatever the screen ratio. Any ideas how to change the code in the example to solve this?

By the way, you may be interested in work I am also doing on sprites, which don't seem to have had much attention over the years. I am about to release a package based around high-quality, high-resolution images and a reworked 'milk2_img.ini' file. Normally these images would be impossible to use as presets usually freeze for long periods of time as the images are loaded into memory. A programmer I am collaborating with on a project called NestDrop has come up with a solution so this is no longer an issue. The results are absolutely amazing and will give Milkdrop a new lease of life. This is an almost untapped area of Milkdrop and I have set about to change that.
NeonAngel is offline   Reply With Quote
Old 19th June 2020, 12:22   #6
Nitorami
Major Dude
 
Join Date: Mar 2008
Location: Erlangen
Posts: 888
Hi NeonAngel
I myself have never dealt with sprites, and am curious what you will come up with.

Nestdrop was announced recently on this forum in a different thread.

For your texture mapping:
You don't need the warp shader. Do it in the comp shader directly. The comp shader's "ret" is effectivels what you'll see on the screen.
What you need is the aspect ratio of your image; just define it above the shader body, and then use it for sampling. Here is the relevant part of the authoring guide:

If your shader wants to know how big the texture is, declare this
(also above the shader_body section):

float4 texsize_billy; // .xy = (w,h); .zw = (1/w, 1/h)

MilkDrop will see the "texsize_" prefix and automatically know what
to do. (You don't have to include the //comment, of course.)

To stretch this texture to cover the screen, do this (in the shader
body):

ret = tex2D(sampler_billy, uv).xyz;

Or to map it fitted to the screen, aspect-aware:

ret = tex2D(sampler_billy, uv * aspect.xy).xyz;

Or to tile it so the pixels are represented 1:1:

ret = tex2D(sampler_billy, uv * texsize.xy * texsize_billy.zw).xyz;

Or to map it tiled exactly 5 times:

ret = tex2D(sampler_billy, uv * 5).xyz;

Or to zoom into the center 20% of the image:

ret = tex2D(sampler_billy, (uv-0.5)*0.2 + 0.5 ).xyz;

Of course, you could also declare sampler_pw_billy, to do point
sampling, or sampler_fc_billy, for clamping, and so on.
Nitorami is offline   Reply With Quote
Old 21st June 2020, 23:52   #7
NeonAngel
Junior Member
 
Join Date: Jun 2020
Posts: 7
Thank you the references. I already read them over and over and tried various things before joining the forum, but description of what should happen when using 'aspect.xy' in the statement "ret = tex2D(sampler_main, (uv-0.5)*aspect.xy+0.5).xyz;" does not seem to match what the documentation promises, ie.

"The overall design goal in MilkDrop, concerning aspect ratio, is to fit the preset to the long axis of the window, and to crop the rest, but to do all of this without any stretching or zooming (so all internal canvas pixels map 1:1 to screen pixels).
-per-frame/per-vertex equations:
* multiply XY coords by the values "aspectx" and "aspecty", respectively.
-shader code:
* multiply UV coordinates by 'aspect.xy', prior to using them
to sample a texture, to make the texture fit on the screen properly.
(For example, if the screen is wide, the image will be fitted to cover
the width of the screen, and it will be cropped at the top and bottom.)"

It works perfectly if the source image is square, whatever the output screen ratio, but not for tall or wide images - they are still stretched to fit as if 'aspect.xy' wasn't there. This leads me to suspect there is a bug in the MilkDrop code itself that needs correcting. I am having that checked out.

If I'm wrong, any ideas how to correct the very simple preset I initially attached Nitorami, so it will work with 'texsize.xy' or whatever, for both tall and wide images? I would be very grateful if you could show me how I should change the code in the file.

By the way Nitorami you asked abount the sprites I was working on. I have attached four examples of the sort of things possible with any MilkDrop-based installation. The poor sprite has not had a lot of attention at all it seems. (Not you Prenso!). I 'discovered' it just a year ago - tried a few images, changed the code around a bit and I was staggered at how fabulous it looked in 4K/60fps. Checked out this forum and YouTube and so on - not a great deal there at all. So I set about trying to get the best out of it myself with high-resolution imagery all alone over several months. Just by luck eventually I was introduced to a programmer who happened to be buliding a GUI over MilkDrop, with high-res spout output. I transferred everything I learnt to the new system. We have now worked on the use of sprites to a point where their full potential is being realised.

If you want to know more I wil give more details of how to use Sprites. The message function has also been modernised using some great OFL fonts.
Attached Thumbnails
Click image for larger version

Name:	Sprite - Aztec Mask.jpg
Views:	92
Size:	406.9 KB
ID:	54596   Click image for larger version

Name:	Sprite - Blue Temple Buddha.jpg
Views:	90
Size:	412.6 KB
ID:	54597   Click image for larger version

Name:	Sprite - MMAD Molecule.jpg
Views:	89
Size:	91.0 KB
ID:	54598   Click image for larger version

Name:	Sprite - Taiwanese Dragon.jpg
Views:	96
Size:	576.7 KB
ID:	54601   Click image for larger version

Name:	Sprite - Voodoo Masquerade.jpg
Views:	101
Size:	632.0 KB
ID:	54602  

NeonAngel is offline   Reply With Quote
Old 22nd June 2020, 20:35   #8
Nitorami
Major Dude
 
Join Date: Mar 2008
Location: Erlangen
Posts: 888
NeonAngel
Listen. This is not a bug. Aspect is just the screen aspect, not the image's.

uv goes from (0;0), top left, to (1;1) bottom right. tex2D(sampler_image, uv) will stretch any image to the entire screen.

Multiplying uv by aspect.xy (which is the screen aspect, i.e. 16:9) just means that your image will be squeezed accordingly; a square image will then not be stretched over the entire screen but appear in correct proportions. But ONLY a square image !

You need to use the proportions of your IMAGE to scale it. This is what matters.

See the attached example. Hope that helps.
Attached Files
File Type: milk martin - leer.milk (6.9 KB, 90 views)
Nitorami is offline   Reply With Quote
Old 23rd June 2020, 04:26   #9
NeonAngel
Junior Member
 
Join Date: Jun 2020
Posts: 7
OK I've used your code in another preset by Zylot (attached), using the image of the tall mask (first image attached).

Now the tall aspect ratio of the image is correctly transferred to the preset as you can see in the second attached screenshot image. It is tiled of course, so the screen is filled. As you suggested tiling can be overridden - I disabled that as it leaves much of the screen blank. Anyway this looks really good. Great so far and I will use this technique for some preset modifications thank you.

However it's not quite what I was first asking about. The third attached image shows what the documentation I quoted suggests can happen - ie regardless of screen ratio, the image will be fitted so it:

"fits the preset to the long axis of the window, and to crop the rest, but to do all of this without any stretching or zooming".

Is this actually possible for anything that isn't square-shaped - can you show me this please? This is an important technique for me to learn, as the image regardless of dimensions, will be centred automatically, and fitted to width (or height) automatically, allowing randomly selected images to fit well without any tailoring. Please remember I have very little knowledge of preset authoring.
Attached Thumbnails
Click image for larger version

Name:	mask.jpg
Views:	85
Size:	465.8 KB
ID:	54610   Click image for larger version

Name:	TEXSIZE FIT.jpg
Views:	87
Size:	743.2 KB
ID:	54611   Click image for larger version

Name:	REQUIRED FIT.jpg
Views:	92
Size:	203.8 KB
ID:	54612  
Attached Files
File Type: milk Zylot - My World (burning mix) MASK.milk (6.7 KB, 82 views)
NeonAngel is offline   Reply With Quote
Old 24th June 2020, 18:39   #10
Nitorami
Major Dude
 
Join Date: Mar 2008
Location: Erlangen
Posts: 888
Bit tricky. Like that ?
Attached Files
File Type: milk center_image.milk (6.5 KB, 83 views)
Nitorami is offline   Reply With Quote
Old 13th July 2020, 02:36   #11
NeonAngel
Junior Member
 
Join Date: Jun 2020
Posts: 7
Thank you so much Nitorami. Apologies for not answering sooner, but I wanted to check things out thoroughly before replying and have been short of time.

I have used your example with every combination of screen ratio and image ratio - 18 in all! First I used the code in the solution you sent me and it looked fantastic, with all types of image and screen - always centred, with any necessary tiling at 50% brightness to emphasise the main image in the centre. Scaling was set by the following code:

scale = texsize_DeepSpace_FineArt_GardenOfEarthlyDelights_1505_HieronymusBosch_PUBD.zw*texsize.xy * min(sz.x,sz.y);

However, it still wasn't exactly what I asked for, ie image fitted in centre with no distortion or tiling, so I looked at your code and thought what happens if I change min(sz.x,sz.y) to max(sz.x,sz.y) - and it did exactly that! So now I have two great solutions.

To demononstrate I have attached three images showing each main screen ratio - square, wide and tall, and what happens if a square, wide, or tall image is used with either min or max in the scaling equation for each screen ratio.

In all cases the results are controlled and look good. So, I'd say the problem is solved. Thank you so much!

PS There is no way I could have worked this out from the manual - it's way too difficult for me to understand.
Attached Thumbnails
Click image for larger version

Name:	Fit to Square Screens 1-1.jpg
Views:	77
Size:	890.5 KB
ID:	54620   Click image for larger version

Name:	Fit to Wide Screens 3-1.jpg
Views:	84
Size:	892.6 KB
ID:	54621   Click image for larger version

Name:	Fit to Tall Screens 1-3.jpg
Views:	81
Size:	787.7 KB
ID:	54622  
NeonAngel is offline   Reply With Quote
Old 13th July 2020, 11:46   #12
Nitorami
Major Dude
 
Join Date: Mar 2008
Location: Erlangen
Posts: 888
Hi NeonAngel
Good to hear it works now. I don't know why you used "min"; my original code uses "max (sz.x,sz.y)".

I can't pull code like that out of the hat either, but it is not difficult; although some trial and error will certainly be required.
Scaling the image aspect correctly is easy, but that only means the image will be displayed undistorted, not that it will also fit the screen. That would only be the case for images with exactly the same aspect ratio as the screen.

So in a next step we need to scale the image, depending on whether it is too tall or too high. We need a decision, and that is done by max() which simply selects the axis with the largest misfit, and then scales both axes accordingly, maintaining the already corrected aspect.
Nitorami is offline   Reply With Quote
Old 13th July 2020, 20:17   #13
NeonAngel
Junior Member
 
Join Date: Jun 2020
Posts: 7
Yes I got max/min wrong way round, but didn't notice until after posting. I am now going to rework the presets using images I've been working on using this code. A while ago I searched for every preset I could find that already used sampler images (60 or so) and set about exchanging the source images and tweaking the code. It's quite possible to use quite high resolution images nowadays, even 2048 pixels or more without too many loading delays. The use of very high quality images makes a lot of difference I've found, especially at 4K or higher. I am currently able to run Milkdrop presets at more than 12,000x12,000 pixels at up to 60 fps believe it or not and send it all to Spout-enabled systems such as Resolume, so it can be mixed with other content as well.
NeonAngel is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Visualizations > MilkDrop > MilkDrop Troubleshooting Forum

Tags
aspect ratio; samplers

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump