Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

[RELEASED] Shader Converter

Discussion in 'Assets and Asset Store' started by ReformSim, Feb 15, 2023.

  1. ReformSim

    ReformSim

    Joined:
    Aug 23, 2022
    Posts:
    15
    ShaderConverter is an editor tool that converting GLSL image shader on the Shadertoy website to Unity shader.

    Shader Converter for Built-in Render Pipeline
    Shader Converter for Universal Render Pipeline

    With a couple of clicks, you can easily convert GLSL image (fragment/pixel) shader to readable, usable and efficient Unity shader (HLSL), and you can preview the effect of shader immediately.

    Features:
    • The conversion workflow is very simple: One editor window, codes side to side and one button to convert.
    • Supports to set SubShader Tags: Render Type and Render Queue;
    • Supports to set Pass command: Cull, ZWrite, ZTest, Blend;
    • Supports to specify a shader model with the #pragma target directive;
    • Supports to convert Shadertoy shader with multiple passes: Common, Buffer A, Buffer B, Buffer C, Buffer D;
    • Supports to auto assign Shadertoy input: iFrame, iFrameRate, iMouse, iDate, iSampleRate, _iChannelTime;
    • Supports the same keyboard and mouse input as Shadertoy;
    • Supports 2D textures, cubemaps, video and music/sound input;
    • Supports to convert main image shader to object space shader or full screen shader;
    • Supports to render the effect of main image shader to RenderTexture;
    • Supports to save converted shader to a file, and create material from converted shader;
    • Supports to preview the effect of converted shader immediately;
    Notes:
    * Tested in Unity 2019.4.28, Unity 2020.3.38 and Unity 2021.3.25;
    * This editor tool only support 64-bit Unity Editor on Windows for now!
    * This editor tool cannot convert shaders for Built-in render pipeline to shaders for URP or HDRP!

    Screenshots:
    CoverImage2.jpg

    Screenshot3.jpg

    Screenshot-URP4.jpg

    VideoInputShader2.jpg

    MusicInputShader2.jpg

    Support:
    If you have any questions, issues or suggestions, use this thread or feel free to email me at:
    reformsim@outlook.com

    I hope you like it ^_^
     
    Last edited: Sep 5, 2023
    DragonCoder likes this.
  2. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    935
    Hey. Do you have already a test version for HDRP?
     
  3. ReformSim

    ReformSim

    Joined:
    Aug 23, 2022
    Posts:
    15
    Yes. I have already developed the ShaderConverter-HDRP package. But I haven't submitted it to tthe Asset Store yet.
    By the way, I have submitted the ShaderConverter-URP pacakge, which is reviewed by the Asset Store.
    Please stay tuned.
     
    keeponshading likes this.
  4. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    935
    That s great. btw. Did you checked if you get same signature from the wave information (white one) like https://www.shadertoy.com/view/Xds3R
    For compatibilty reasons it would be cool to have the same like in this example.
     
  5. ReformSim

    ReformSim

    Joined:
    Aug 23, 2022
    Posts:
    15
    I have noticed the difference, but haven't found the cause. I will continue to pay attention to this issue in the future.
     
  6. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    935
    Hey. Could you check the conversion of
    https://www.shadertoy.com/view/4sGSDw
    I tried hard several times with the multipass conversion. There are no compile errors but no fades are rendered.
     
  7. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    935
    Hello,

    could you convert the floats to original digits?

    original: 443.897
    left my conversion(send you an PM with converter): 443.897
    right: your conversion: 443.897003173828125f

    That makes the converted shaders hardly readable.
    More examples on screenshot.

    float.JPG
     
  8. ReformSim

    ReformSim

    Joined:
    Aug 23, 2022
    Posts:
    15
    I have updated the ShaderConverter package to v1.2, which is online now.
    The latest version has fixed an issue where the render texture of each pass/buffer was updated incorrectly.
    You could download the latest version to convert that shader.
    I have converted that shader. The rendering results are the same. Here is the screenshot:
    Screenshot.png

    Notes:
    Remember to assign RenderTextures or 2D/Cube textures to the input of the materials according to the Shadertoy shader. If you want to get the same effect as ShaderToy, you must assign same textures to the materials. In some cases, you may need to change Color Space from Linear to Gamma to get the same effect.

    PS. When play the "MultipassShaderExample" scene in Unity 2020.3, don't select the "MultipassQuad" GameObject in Hierarchy window, and don't select the "CustomMaterialMultipass" materials in Project window. Otherwise the rendering result will flicker. Maybe it's a bug of Unity 2020.3. Unity 2021.3 doesn't have this issue.
     
    Last edited: Apr 22, 2023
    4sascha likes this.
  9. ReformSim

    ReformSim

    Joined:
    Aug 23, 2022
    Posts:
    15
    This is because the floating point number cannot be accurately represented.
    Maybe there are other ways to avoid this. Further research is needed to address this issue.
     
    4sascha likes this.
  10. ReformSim

    ReformSim

    Joined:
    Aug 23, 2022
    Posts:
    15
    The Shader Converter package for Universal Render Pipeline is released:
    Shader Converter for Universal Render Pipeline

    And the Shader Converter package for Built-in Render Pipeline is updated to v1.2:
    • Supported video input, and added an example scene;
    • Supported keyboard input, and added an example scene;
    • Supported to set iChannelx type (2D or Cube) for each Buffer;
    • Fixed an issue where the render texture of each pass/buffer was updated incorrectly;
    • Updated the document;
     
    4sascha likes this.
  11. 4sascha

    4sascha

    Joined:
    Mar 9, 2017
    Posts:
    50

    Thanks. Your Multipass conversion is somehow a gamechanger. I always was to lazy doing it manually.
     
  12. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    935
    Hi. Could you please have check the conversion of this shadertoy shader?
    https://www.shadertoy.com/view/tsKXR3#

    I get some Macro expansion error.
    ..
    ERROR: :273: 'macro expansion' : Too few args in Macro D
    ..
    with
    Shader Converter 1.2 BuildInRP
    in
    Unity 2021.3.15
     
  13. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    935

    Hi. I tried to convert 3 times and doing the setup like documented.
    I cannot get the render output correct. There are no compile errors but only pure white rendering.
    Here is my conversion with ShaderConverter 1.2 BuilInRP.

    Another strange effect is that when i load the included MultiPassShader example there is also an strange rendering of the shader in the lower left corner of the quad. (only visible when you rotate the cam in scene view like in screenshot)

    Unbenannt.JPG
     

    Attached Files:

  14. ReformSim

    ReformSim

    Joined:
    Aug 23, 2022
    Posts:
    15
    Hi, I can get the correct rendering with your shaders. Maybe your setup is not right.
    Here is my setup:
    MultipassShader.png

    CustomMaterialMultipass-BufferA.mat:
    Note: You must set the _SecondTex/iChannel1 with the same texture as the Shadertoy website.
    Multipass-BufferA.png

    CustomMaterialMultipass-BufferB.mat:
    Multipass-BufferB.png

    Notes:
    1) The resolution must be the same as the size of the RenderTexture (BufferA, BufferB, BufferC, BufferD).
    2) The FPS must be the same as the Shadertoy website (60fps) to get the same rendering speed.
    Resolution.png
     
    Last edited: May 26, 2023
  15. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    935

    Thanks for the detailed explanation.
    I had downloaded the preview texture from the noise tex not the 256x256 one
    and had to set the import settings of the noise tex ARGB 16bit and 256 res.

    Also i had not set the same rendering speed(60fps) and resolution of the game window.
    After correcting it rendered out nicely.
     
    Last edited: May 31, 2023
  16. kanitabe

    kanitabe

    Joined:
    Apr 6, 2018
    Posts:
    2
    I tried to convert these shaders and got the following error.
    What is wrong?

    "The format of parameter of mainImage() is not correct: "
     

    Attached Files:

  17. ReformSim

    ReformSim

    Joined:
    Aug 23, 2022
    Posts:
    15
    Hi, the Shader Converter package is an editor tool that converting image shader on the Shadertoy website (Shadertoy BETA) to Unity shader. It cannot convert shaders for Built-in render pipeline to shaders for URP or HDRP.
     
  18. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    935
  19. keeponshading

    keeponshading

    Joined:
    Sep 6, 2018
    Posts:
    935
    Hi.

    I have some question about the base conversion...

    why do you convert...

    //vec2 q = fragCoord.xy / iResolution.xy;
    //vec2 p = (gl_FragCoord.xy - 0.5 * iResolution.xy) / iResolution.y;
    //bsMo = (iMouse.xy - 0.5 * iResolution.xy) / iResolution.y;

    to (1)

    float2 q = gl_FragCoord.xy / _ScreenParams.xy;
    float2 p = (gl_FragCoord.xy - (_ScreenParams.xy * 0.5f)) / _ScreenParams.y.xx;
    bsMo = (_iMouse.xy - (_ScreenParams.xy * 0.5f)) / _ScreenParams.y.xx;

    instead of to (2)

    float2 q = fragCoord.xy / iResolution.xy;
    float2 p = ((vertex_output.uv * _Resolution).xy - 0.5 * iResolution.xy) / iResolution.y;
    bsMo = (_Mouse.xy - 0.5 * iResolution.xy) / iResolution.y;

    When you rotate the quad with your conversion (1) the shader is rendered as front projection.
    When you rotate the quad with the last conversion (2) the shader is rotated and moved with the quad.

    Yust curious because i would expect the behaviour and conversion from (2).
     
  20. ReformSim

    ReformSim

    Joined:
    Aug 23, 2022
    Posts:
    15
    First, I'm sorry to be so late reply to you. Recently, I was busy with other things.

    The errors occurred because the shader code contained some macro calls without passing in arguments.
    HLSL doesn't support macro calls with default argument value.
    So you need to modify the source code as the following pictures:

    1) In Buffer A code:
    Change N() to N(vec2(0))
    Change V() to V(vec2(0))
    Change C() to C(vec2(0))
    Multiscale MIP Fluid - Buffer A (Modified).jpg

    2) In Buffer C code:
    Change CURL() to CURL(vec2(0))
    Multiscale MIP Fluid - Buffer C (Modified).jpg

    3) In Image code:
    Change D() to D(vec2(0))
    Multiscale MIP Fluid - Image (Modified).jpg

    After modifying the above code, you will be able to convert these shaders correctly.

    4) You need to change those 4 RenderTextures to enable Mip Maps. It is important to enable Mip Maps to get the same rendering result as the Shadertoy website. I will make it as the default setting in the next release.
    Enable Mip Maps.jpg

    The below picture shows the rendering result:
    Multiscale MIP Fluid.jpg
     
  21. ReformSim

    ReformSim

    Joined:
    Aug 23, 2022
    Posts:
    15
    The shaders on the shadertoy website are mostly full screen image shaders. If you want to apply these shaders to objects, you can render the effect to the RenderTexture, then set the RenderTexture to any material of any object. I have created two sample scenes, which will be released in the next version.
    Here is the screenshot:
    RenderToTextureMultipassExample3.jpg
     
  22. 4sascha

    4sascha

    Joined:
    Mar 9, 2017
    Posts:
    50
    Hey, do you know why the wave is positioned to the ground and not rendered centered?

    Would be helpful to get the same output because i have calibrated some shaders to this.
    Here the Shadertoy output.

    Screenshot_20230830-202353.png

    Your output:

    MusicInputShader2.jpg
     
  23. 4sascha

    4sascha

    Joined:
    Mar 9, 2017
    Posts:
    50
    It would be nice to habe this as option in the converter.
    We use all shaders on planes and rotate them in the space.
    To do additional rt textures is performance wise not possible for us.
    Would be cool to have iResoulution (rotates with) as default and ScreenParams (not rotating)
    as option in the converter UI.
     
  24. ReformSim

    ReformSim

    Joined:
    Aug 23, 2022
    Posts:
    15
    I have fixed the rendering issue of shader with sound/music input to get the rendering result as same as possible with the Shadertoy output. The new version of ShaderConverter asset have been submitted to the Asset Store. It will be online in about 3 days.
    Here is the screenshot:
    MusicInputShader2.jpg
     
  25. ReformSim

    ReformSim

    Joined:
    Aug 23, 2022
    Posts:
    15
    I'll try to develop this feature, but the implementation may not work with all shaders.
     
  26. ReformSim

    ReformSim

    Joined:
    Aug 23, 2022
    Posts:
    15
    You can download the Shadertoy built-in media files (texture, video, music…) from:
    Shadertoy media files | shadertoy - unofficial (wordpress.com)
     
  27. ReformSim

    ReformSim

    Joined:
    Aug 23, 2022
    Posts:
    15
    New Version is live:
    • Added two options in the window, now you can select the “Shader Type” of the converted main shader:
    (1) Full Screen: The main image shader will be converted to the full screen shader.
    (2) Object: The main image shader will be converted to the object shader. The rendering effect can be translated or rotated with the object.

    @4sascha, @keeponshading, thanks very much for your feedback, it helps a lot.