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. Dismiss Notice

Question Read shadergraph source into string

Discussion in 'Shader Graph' started by Siam_, Apr 27, 2019.

  1. Siam_

    Siam_

    Joined:
    Jan 28, 2017
    Posts:
    2
    Hello, guys.
    I'm in very need to read shader source from .shadergraph file as string inside my editor script.
    From graph editor it is possible to use "Copy Shader" and it generates string in system copy buffer.
    Is it possible to get that "Copy Shader" using reflection?

    Thanks
     
    Last edited: Apr 27, 2019
  2. alexandral_unity

    alexandral_unity

    Unity Technologies

    Joined:
    Jun 18, 2018
    Posts:
    163
    Are you needing the output HLSL? The master node has a context menu option. Right click and find "Show Generated Code" or "Copy Generated Code" to see the output shader. It will only gather the calculations that are connected upstream from the master node.
     
  3. Siam_

    Siam_

    Joined:
    Jan 28, 2017
    Posts:
    2
    Yes, I need exactly HLSL output.
    But instead of 1) manually opening shadergraph file, 2) using context menu over master node and 3) copying HLSL output into clipboard memory, is it possible to bypass all above and just get HLSL source using script method.
    Something like:
    Code (CSharp):
    1. ShaderGraph shader = (ShaderGraph)AssetDatabase.LoadAssetAtPath(path, typeof(ShaderGraph));
    2. string hlsl = shader.GenerateOutput();
     
  4. alexandral_unity

    alexandral_unity

    Unity Technologies

    Joined:
    Jun 18, 2018
    Posts:
    163
    Unfortunately that's not possible right now, you can only get the generated output from the graph window itself.
     
  5. JohnOknelorfDev

    JohnOknelorfDev

    Joined:
    Oct 2, 2017
    Posts:
    20
    Hello. Any updates on this after more than 2 years?