State of VFX Graph for Custom SRPs

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

1 Like

@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.

{
  "name": "Unity.RenderPipelines.HighDefinition.Editor",
  "references": [
    "Unity.VisualEffectGraph.Editor"
  ],
  "includePlatforms": [
    "Editor"
  ],
  "excludePlatforms": [],
  "allowUnsafeCode": true,
  "overrideReferences": false,
  "precompiledReferences": [],
  "autoReferenced": true,
  "defineConstraints": []
}

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:

using System;

namespace UnityEditor.VFX.HDRP
{
    class VFXMOBDBinder : VFXSRPBinder
    {
        public override string templatePath     { get { return "Assets/Rendering/Editor/VFXGraph/Shaders"; } }
        public override string runtimePath      { get { return "Assets/Rendering/VFXGraph/Shaders"; } }

        public override string SRPAssetTypeStr  { get { return "MOBDPipelineAsset"; } }

        public override Type SRPOutputDataType
        {
            get { return null; }
        }
    }
}

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!

4 Likes

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.

Works like a charm! Thanks again for pointing me in the right direction :slight_smile:

1 Like

:hushed: oh, my god! I get it now!