Vixen
dd8b0a81
csharp
public sealed class ShaderGraphDocument

A shader, open for editing as a graph, with the Raven it emits beside it.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Doc 20's B5 has had "shader graph ✅" against .ShaderGraph for a while, and what that ticked was the node library, the typing and the emission. None of it was reachable: there was no document, no factory and no registration, so nothing in the editor could turn a double-click into a graph. This is that half — the same shape VfxDocument and CompositorDocument already have, and for the same reason it is in this assembly rather than in Vixen.Editor.ShaderGraph: that one knows nothing about a project or a panel, which is what lets its tests compile a graph with no editor in the way.

⚠ The file holds the graph, not the shader. A .vxshadergraph is a NodeGraphAsset — nodes, edges, positions, the numbers and names an author typed — and Compile turns it into Raven. Saving the emitted source instead would throw away the layout and make the document unopenable; saving both would be two files that can disagree, with the generated one the tempting thing to hand-edit.

⚠ Compiling runs the graph compiler and Raven's front end. The graph compiler's complaints name a node and a port; Raven's name a line of text the author never wrote. Both are worth having and neither substitutes for the other — a graph that is well-formed can still emit a shader that does not type-check, which is exactly the failure a panel showing only Diagnostics would report as success. SourceNodeDiagnostics is the second kind mapped back to the node that wrote the line, which doc 11 recorded as owed: the emitter now records spans as it writes, and Attribute is the join.

⚠ A .vxshadergraph is imported now, and by an importer that writes no artefact. This paragraph used to say nothing imported one and to describe the missing step as "an importer that runs Compile and hands the source to Raven" — which is half right and misplaces the other half. What a graph produces is Raven source, and source is not content: it is an input to a shader compilation, so ShaderGraphImporter exists only to report the graph's diagnostics against its own file, and ShaderGraphSources is what EditorEffects and ShaderBuildRunner enumerate when a compilation is actually wanted. Writing the text into the artefact store would put a second copy behind an address nothing resolves.

⚠ A file this build cannot read opens empty and says why. NodeGraphDocument.Load repairs what it can and refuses a graph from a later version outright; both arrive in LoadDiagnostics rather than as an exception, so the panel that could show the problem is reachable.

Fields and properties (11)

  • public const string Extension

    What a shader graph is written as.

  • public string AssetPath

    Where the file is, absolute.

  • public NodeGraphModel Graph

    The graph.

  • public NodeTypeRegistry Registry

    The node types this document is edited against.

  • public ISubGraphSource? SubGraphSource

    Where this graph's sub-graphs are found, when anything has said.

  • public IReadOnlyList<NodeDiagnostic> LoadDiagnostics

    What reading the file had to say — repairs, and a refusal.

  • public IReadOnlyList<NodeDiagnostic> Diagnostics

    What the last Compile had to say about the graph.

  • public INodePreviewSource? PreviewSource

    What renders a node's preview thumbnail, when this editor has a device to do it with.

  • public IReadOnlyList<CodeDiagnostic> SourceDiagnostics

    What Raven had to say about the source the last Compile emitted.

  • public IReadOnlyList<NodeDiagnostic> SourceNodeDiagnostics

    The same complaints, each addressed to the node that wrote the line.

  • public ShaderGraphSource? Source

    The shader the last Compile emitted, or .

Events (1)

Methods (7)

  • public string? PreviewRefusal(NodeId node)

    Why one node has no preview thumbnail, or when it has one.

  • public ShaderGraphDocument(EditorProject project, AssetId asset, string path, NodeTypeRegistry? registry = null)

    Opens a shader graph.

  • public ShaderGraphSource? Compile()

    Compiles the graph, and puts the emitted source through Raven.

  • public bool TryGet(NodeGraphModel graph, GraphNode node, NodeTypeDefinition definition, out NodePreview preview)
  • public string ToYaml()

    The graph as this document would write it, without writing it.

  • public string? ShaderSource()

    The Raven the graph emits, for a host that wants the text.

  • protected override void SaveCore()

    Writes the document back to wherever it came from.

Used by (9)

  • AssetEditorDiagnosticIdTestsVixen.Editor.AssetEditors.Tests
  • ChromeDumpTestsVixen.Editor.AssetEditors.Tests
  • EditorApplicationVixen.Editor.App
  • NodeGraphThemeTestsVixen.Editor.App.Tests
  • ShaderGraphEditorFactoryVixen.Editor.AssetEditors
  • ShaderGraphSurfaceTestsVixen.Editor.App.Tests
  • ShaderGraphTestsVixen.Editor.AssetEditors.Tests
  • ShaderGraphViewVixen.Editor.AssetEditors
  • ShaderGraphViewTestsVixen.Editor.AssetEditors.Tests