FFT Color Lines and Spectrum need granularity

Sat May 08, 2021 1:39 pm

Both the FFT Color Lines and the Spectrum modules would benefit from an option to specify the number of lines each module generates. Currently, they both seem to be fixed at 10 lines. I would love this to be an integer option that I can change from 1-3840 (@4K resolution ~ 1 line per pixel).

Thoughts?
TEHK
 
Posts: 18
Joined: Mon Mar 12, 2018 9:04 pm

Re: FFT Color Lines and Spectrum need granularity

Sat May 08, 2021 4:43 pm

To create a spectrum with a custom number of lines, use the Iterator module. For examples, see the sample project called IteratorSpectrumExamples.magic.

Because of the (different) way in which an FFT generates a spectrum, the number of lines in the FFT Color Lines and Spectrum modules cannot be changed.

An alternative method to *simulate* more lines with a Spectrum module is to use some type of pixelation effect afterwards. For this, I use the code below. I think I've shared it before but I can't remember.

Code: Select all
/*{
   "DESCRIPTION": "Creates a pixelation grid effect on its input.",
   "INPUTS": [
      {
         "NAME": "inputImage",
         "TYPE": "image"
      },
      {
         "NAME": "numPixels",
         "LABEL": "# Pixels",
         "TYPE": "float",
         "DEFAULT": 64.0,
         "MIN": 1.0
      },      
      {
         "NAME": "gridx",
         "LABEL": "Grid X",
         "TYPE": "bool",
         "DEFAULT": 1.0
      },   
      {
         "NAME": "gridy",
         "LABEL": "Grid Y",
         "TYPE": "bool",
         "DEFAULT": 1.0
      },   
      {
         "NAME": "gridSize",
         "LABEL": "Grid Size",
         "TYPE": "float",
         "DEFAULT": 0.25,
         "MIN": 0.0,
         "MAX": 1.0
      },   
      {
         "NAME": "softness",
         "LABEL": "Softness",
         "TYPE": "float",
         "DEFAULT": 0.25,
         "MIN": 0.0,
         "MAX": 1.0
      },         
   ],
}*/

float myStep(float pixelLocation, float flooredPixelLocation)
{
   if (softness == 0.0)
      return (1.0-abs(flooredPixelLocation-pixelLocation)*numPixels*2.0 > gridSize ? 1.0 : 0.0);
   else
      return smoothstep(gridSize*(1.0+softness)-softness, gridSize*(1.0+softness), 1.0-abs(flooredPixelLocation-pixelLocation)*numPixels*2.0);
}

void main()
{
    vec2 pixelLocation = vv_FragNormCoord;

    vec2 flooredPixelLocation = (floor(pixelLocation * numPixels)+.5) / numPixels;

    vec4 color = IMG_NORM_PIXEL(inputImage, flooredPixelLocation);

   gl_FragColor = color * (gridx ? myStep(pixelLocation.x, flooredPixelLocation.x) : 1.0) * (gridy ? myStep(pixelLocation.y, flooredPixelLocation.y) : 1.0);
}
Attachments
pixelated.png
pixelated.png (59.26 KiB) Viewed 1113 times
Eric
Site Admin
 
Posts: 3211
Joined: Wed Apr 09, 2014 9:28 pm

Return to Feature Requests

© 2021 Color & Music, LLC • This web site is mobile-friendly