brunoherbelin / vimix

Live Video Mixer
GNU General Public License v3.0
260 stars 25 forks source link

How to import Shaders into ViMix please? #46

Closed MattYule closed 1 year ago

MattYule commented 2 years ago

Hi, I have downloaded and started to use Vimix, which is great and many thanks for it.... Can someone help how to import Shaders from Shadertoy? This was something which could be done in GLMixer so I'm guessing the same can be done with ViMix? Much appreciate any help / advice :)

brunoherbelin commented 2 years ago

Dear Matt, Your message comes at the perfect time ! I just finished implementing ShaderToy in vimix! It is working well and can already be tested if you compile from source or from linux Snap in unstable version. For OSX, a beta binary can be downloaded here : may be unstable, i am in the process of preparing version 0.7.1

To add shaders, the system is simplified from GLMixer: now you clone the source and set the filter on the clone. You can thus chain as many filters as you want (if computer's GPU follows..). You can use ShaderToy code in the Custom Shader:

20220706124455783_vmixcapture

Thanks for your input on the features and for signaling bugs!

MattYule commented 2 years ago

Dear Matt, Your message comes at the perfect time ! I just finished implementing ShaderToy in vimix! It is working well and can already be tested if you compile from source or from linux Snap in unstable version. For OSX, a beta binary can be downloaded here : may be unstable, i am in the process of preparing version 0.7.1

To add shaders, the system is simplified from GLMixer: now you clone the source and set the filter on the clone. You can thus chain as many filters as you want (if computer's GPU follows..). You can use ShaderToy code in the Custom Shader:

20220706124455783_vmixcapture

Thanks for your input on the features and for signaling bugs!

MattYule commented 2 years ago

Great - thanks Bruno for the reply. I've downloaded the link but still a bit stuck as you how you add shaders?...What do you mean by 'clone the source' and how is this done please? Presumed it was via + and then add via File/ Sequence / Connected / Generated / Internal ? Could you advise? Much appreciated

brunoherbelin commented 2 years ago
Screenshot at Jul 06 17-11-06
MattYule commented 2 years ago

Okay I'm nearly there - I've got into the custom shader - I then go to the website to select the shader - I've copied all the data and tried to paste but get an error message - do you select the webpage address instead? Please can you advise, showing step by step (apologies for being dense with this - but I'm a newbie to video editing etc)

brunoherbelin commented 2 years ago

Good ! You should be able to copy & paste the code of the shader. But indeed, for Shader errors and compatibility of ShaderToy with OpenGL and vimix, i'm afraid there is a bit of knowledge in GLSL programming required... I planned to make a wiki page with more details, just didn't do it yet!

So, in short for now:

  1. select the whole code in the shader editor of the clone. by default it is:
    void mainImage( out vec4 fragColor, in vec2 fragCoord )
    {
    vec2 uv = fragCoord.xy / iResolution.xy;
    fragColor = texture(iChannel0, uv);
    }
  2. Go to ShaderToy and copy the whole code of a shader, e,g, for https://www.shadertoy.com/view/Xsl3zn it is
    
    #define PROCEDURAL 1

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

if PROCEDURAL==0

vec2 warp = texture( iChannel0, uv*0.1 + iTime*vec2(0.04,0.03) ).xz;

else

float freq = 3.0*sin(0.5*iTime);
vec2 warp = 0.5000*cos( uv.xy*1.0*freq + vec2(0.0,1.0) + iTime ) +
            0.2500*cos( uv.yx*2.3*freq + vec2(1.0,2.0) + iTime) +
            0.1250*cos( uv.xy*4.1*freq + vec2(5.0,3.0) + iTime ) +
            0.0625*cos( uv.yx*7.9*freq + vec2(3.0,4.0) + iTime );

endif

vec2 st = uv + warp*0.5;

fragColor = vec4( texture( iChannel0, st ).xyz, 1.0 );

}



3. Back in vimix, paste the shader code in the editor 
4. Hit 'Build' to compile

Errors depend on the code you put, so I cannot say what problem you encounter.
What will not work:
- ShaderToy effects with multiple pass (more than one tab)
- ShaderToy effects with mouse interaction (i.e .imouse variable)

if you send me the link to the ShaderToy effect you want, I can tell you if its possible !
MattYule commented 2 years ago

Great - many thanks for this - I'll have a play and see how I get on, will let you know re any shaders I get issues with - cheers Bruno!

brunoherbelin commented 1 year ago

A documentation is now available to explain this feature of r0.7.1 at https://github.com/brunoherbelin/vimix/wiki/Filters-and-ShaderToy