Magic

Music Visuals
https://magicmusicvisuals.com/forums/

FFT Color Lines and Spectrum need granularity

https://magicmusicvisuals.com/forums/viewtopic.php?f=4&t=2548

Page 1 of 1

FFT Color Lines and Spectrum need granularity

Posted: Sat May 08, 2021 1:39 pm
by TEHK
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?

Re: FFT Color Lines and Spectrum need granularity

Posted: Sat May 08, 2021 4:43 pm
by Eric
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);
}

All times are UTC
Page 1 of 1