Previous topicNext topic

Can't get ShaderToy shaders to work with Magic Performer

Questions, comments, feedback, etc.
Post Reply
KPL
Posts: 3
Joined: Sun Aug 22, 2021 12:37 am

Can't get ShaderToy shaders to work with Magic Performer

Post by KPL »

Hi,

I have recently installed Magic Performer v2.31 64bit.
I am trying to get this 2D EQ ShaderToy working..

https://www.shadertoy.com/view/Mlj3WV

ShaderToy shaders implement the mainImage function.
void mainImage( out vec4 fragColor, in vec2 fragCoord )

From reading the forums I know to add the following to the end of cut-paste from ShaderToy.

void main(void) {
mainImage(gl_FragColor, gl_FragCoord.xy);
}

But I still just get black screen. I have tried other shaders from ShaderToy with same result. The Shaders that come with Magic work ok. (have main())
I'm not sure what I might be missing. If someone can get a ShaderToy working with Magic Performer., and input is welcomed. Thank you. Kevin

2D_EQ.txt

uniform vec3 iResolution; // viewport resolution (in pixels)
uniform float iTime; // shader playback time (in seconds)
uniform float iTimeDelta; // render time (in seconds)
uniform int iFrame; // shader playback frame
uniform float iChannelTime[4]; // channel playback time (in seconds)
uniform vec3 iChannelResolution[4]; // channel resolution (in pixels)
uniform vec4 iMouse; // mouse pixel coords. xy: current (if MLB down), zw: click
uniform samplerXX iChannel0..3; // input channel. XX = 2D/Cube
uniform vec4 iDate; // (year, month, day, time in seconds)
uniform float iSampleRate; // sound sample rate (i.e., 44100)


// ...paste the shadertoy code here...

/*
2D LED Spectrum - Visualiser
Based on Led Spectrum Analyser by: simesgreen - 27th February, 2013 https://www.shadertoy.com/view/Msl3zr
2D LED Spectrum by: uNiversal - 27th May, 2015
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
*/




void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
// create pixel coordinates
vec2 uv = fragCoord.xy / iResolution.xy;

// quantize coordinates
const float bands = 30.0;
const float segs = 40.0;
vec2 p;
p.x = floor(uv.x*bands)/bands;
p.y = floor(uv.y*segs)/segs;

// read frequency data from first row of texture
float fft = texture( iChannel0, vec2(p.x,0.0) ).x;

// led color
vec3 color = mix(vec3(0.0, 2.0, 0.0), vec3(2.0, 0.0, 0.0), sqrt(uv.y));

// mask for bar graph
float mask = (p.y < fft) ? 1.0 : 0.1;

// led shape
vec2 d = fract((uv - p) *vec2(bands, segs)) - 0.5;
float led = smoothstep(0.5, 0.35, abs(d.x)) *
smoothstep(0.5, 0.35, abs(d.y));
vec3 ledColor = led*color*mask;

// output final color
fragColor = vec4(ledColor, 1.0);
}

// ...end paste the shadertoy code

// Add main to work with Magic, but still get black screen.
void main(void) {
mainImage(gl_FragColor, gl_FragCoord.xy);
}
Magic
Site Admin
Posts: 3451
Joined: Wed Apr 09, 2014 9:28 pm

Re: Can't get ShaderToy shaders to work with Magic Performer

Post by Magic »

Seems like you have added a lot of unnecessary variables to the beginning…
Terry Payman
Posts: 723
Joined: Sun Sep 14, 2014 8:15 am
Location: UK
Contact:

Re: Can't get ShaderToy shaders to work with Magic Performer

Post by Terry Payman »

Not being skilled at GLSL I can't spot errors and almost always need to use an automated conversion.

I find it easiest and most flexible to convert ShaderToy shaders to ISF format, which for me has several major advantages over using the GLSLShader module. With the VIDVOX ISF editor https://isf.vidvox.net/desktop-editor/ it's easy to syntax check, add extra parameters and specify meaningful names for the shader itself and all the parameters.

One way to convert is to use Eric & Syd's Shadertoy to ISF script https://magicmusicvisuals.com/forums/vi ... ?f=3&t=495. That link lists further advantages of the ISF format.

The VIDVOX ISF editor can import directly from ShaderToy, also from GLSLSandbox. It has built-in syntax checking and simple means of adding parameters. It has a few oddities though - I always try to Save any edits before adding or changing Inputs (parameters), else the edits may be discarded.

nb Not all ShaderToy shaders can be converted automatically, also (by default) they are not licensed for commercial use.

Remember that you need to use the AudioToImage module as the source for your converted shader. I find it useful to follow AudioToImage with the Contrast module.
KPL
Posts: 3
Joined: Sun Aug 22, 2021 12:37 am

Re: Can't get ShaderToy shaders to work with Magic Performer

Post by KPL »

Thanks.

This flow below has the shader running in Magic.

1. https://isf.vidvox.net/desktop-editor/
> Install.
> ISFEditor -> File -> Import from ShaderToy
> Paste URL: https://www.shadertoy.com/view/Mlj3WV

2. ISF Editor will save the above converted shader to:
> /Users/KPL/Library/Graphics/ISF/2D_LED_Spectrum-Visualiser_Mlj3WV.fs

3. Launch Magic
> Help -- Add Additonal Module folders. (specify path above)

4. Then I restart Magic, and can get the basic shader running.
(Other ShaderToys came over ok also). Just FYI. Thank you.
Attachments
basic eq
basic eq
shadertoy_eq.png (89 KiB) Viewed 12012 times
Terry Payman
Posts: 723
Joined: Sun Sep 14, 2014 8:15 am
Location: UK
Contact:

Re: Can't get ShaderToy shaders to work with Magic Performer

Post by Terry Payman »

I'm glad that got you going so quickly. Thanks for showing your detailed flow - very helpful to others. Some further points - sorry I didn't detail these in my rather hurried previous post:

1) AudioToImage module: Deselect the "Waveform" option. Use the "Spectrum" option alone if you want a pure spectrum display.

2) Contrast module: Brightness adjusts offset, Contrast adjusts gain of the spectrum.

3) The Contrast module is perhaps more useful when working with shaders that display waveforms. eg https://www.shadertoy.com/view/XlcXDs.
Although designed to show both spectrum and waveform, IMO that shader works very nicely with just a waveform feed. With a waveform image a further neat technique is to follow the Contrast module with a blur, eg Multi Pass Gaussian Blur, which acts as a spatial low-pass filter. As it is operating on an image of the audio, it has a similar effect to an audio low-pass filter and removes the high frequencies from the waveform display. This gives a much cleaner image with bass-heavy music.
KPL
Posts: 3
Joined: Sun Aug 22, 2021 12:37 am

Re: Can't get ShaderToy shaders to work with Magic Performer

Post by KPL »

Yes, the Add->ISF->Blur->Multi Pass Gaussian Blur has nice effect. Thanks,
riptide76
Posts: 13
Joined: Sat Mar 16, 2019 8:18 pm

Re: Can't get ShaderToy shaders to work with Magic Performer

Post by riptide76 »

Very cool, thank you for the show how! :mrgreen: :mrgreen:
Post Reply