Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

State of VFX Graph for Custom SRPs

Discussion in 'Visual Effect Graph' started by Laex410, Aug 13, 2020.

  1. Laex410

    Laex410

    Joined:
    Mar 18, 2015
    Posts:
    51
    Hi,

    is there any update on the way the integration of the VFX graph works with custom SRPs which aren't using the same shader passes as HDRP/UDP? Is there a way to integrate it without having to rewrite the whole vfx graph package? In other words: Is there an easy way to change the output shaders of the vfx graph?

    Thanks!

    Best,
    Alex
     
    andybak likes this.
  2. XRA

    XRA

    Joined:
    Aug 26, 2010
    Posts:
    265
    @Laex410
    It is entirely possible but the main issue to get around is VFX Graph being internal. So the cleanest workaround I use is to create a VFXGraph folder and an assembly definition for it named Unity.RenderPipelines.HighDefinition.Editor.asmdef

    The reason for this, is because the assembly Unity.VisualEffectGraph.Editor has defines set for which assemblys the internals are visible to
    (check the file Library/PackageCache/com.unity.visualeffectgraph@8.2.0/Editor/PackageInfo.cs )

    my asmdef for the custom VFXGraph binder and templates contains this.

    Code (CSharp):
    1.  
    2. {
    3.   "name": "Unity.RenderPipelines.HighDefinition.Editor",
    4.   "references": [
    5.     "Unity.VisualEffectGraph.Editor"
    6.   ],
    7.   "includePlatforms": [
    8.     "Editor"
    9.   ],
    10.   "excludePlatforms": [],
    11.   "allowUnsafeCode": true,
    12.   "overrideReferences": false,
    13.   "precompiledReferences": [],
    14.   "autoReferenced": true,
    15.   "defineConstraints": []
    16. }
    17.  

    Once you have that asmdef created, any code within your project's VFXGraph folder can now access the internals of Visual Effect Graph.

    I created a VFX Binder for my SRP, for example:

    Code (CSharp):
    1.  
    2. using System;
    3.  
    4. namespace UnityEditor.VFX.HDRP
    5. {
    6.     class VFXMOBDBinder : VFXSRPBinder
    7.     {
    8.         public override string templatePath     { get { return "Assets/Rendering/Editor/VFXGraph/Shaders"; } }
    9.         public override string runtimePath      { get { return "Assets/Rendering/VFXGraph/Shaders"; } }
    10.  
    11.         public override string SRPAssetTypeStr  { get { return "MOBDPipelineAsset"; } }
    12.  
    13.         public override Type SRPOutputDataType
    14.         {
    15.             get { return null; }
    16.         }
    17.     }
    18. }
    If you look at Library/PackageCache/com.unity.visualeffectgraph@8.2.0/Editor/Core/VFXLibrary.cs

    You'll find the VFXSRPBinder which is an abstract class, there are also some hard coded binders for Unity's Legacy, URP and old LWRP.

    The binder tells VFX Graph where to look for output templates.

    HDRP has its own binder within the HDRP package (which is why we are tricking VFXGraph with our HDRP asmdef in the first place)

    The next step is creating templates for your custom SRP. You can reference Library/PackageCache/com.unity.visualeffectgraph@8.2.0/Shaders/RenderPipeline/Universal

    The templates are pieced together to build the shader for output node types. VFXPasses.template defines the "LightMode" tag to use, which is what your custom SRP uses along with ShaderTagID when filtering and rendering Unity renderers.

    VFXParticlePlanarPrimitive.template is the basic quad output, you'll see that it points to some other templates for different stages of the shader.

    You can re-use or reference the existing templates or write your own. Check HDRP's templates too for ideas. There are hlsl files also that the templates reference and can be useful to copy what you need from.

    Also be sure to call this in your SRP's render method for the camera you're rendering
    UnityEngine.VFX.VFXManager.ProcessCamera(camera);

    It is also possible to create your own Particle Outputs if needed, similar to how HDRP implements it by extending from VFXShaderGraphParticleOutput

    Good luck!
     
    Last edited: Aug 20, 2020
  3. Laex410

    Laex410

    Joined:
    Mar 18, 2015
    Posts:
    51
    Thanks for the detailed reply! I'll try to adapt my custom SRP and I'll update this thread as soon as I have results.
     
  4. Laex410

    Laex410

    Joined:
    Mar 18, 2015
    Posts:
    51
    Works like a charm! Thanks again for pointing me in the right direction :)
     

    Attached Files:

    rrtt_2323 likes this.
  5. rrtt_2323

    rrtt_2323

    Joined:
    Mar 21, 2013
    Posts:
    22
    :eek: oh, my god! I get it now!