Vixen
dd8b0a81
csharp
public static class ShaderGraphPreview

One node's sub-expression, as a shader that draws it on a quad.

Read the guide page for this →

Remarks

A graph transformation, not a second compiler. What a preview needs is the expression one node produces, and the graph already says what that is: the node, everything upstream of it, and a master to end at. So this copies that closure into a graph of its own, hangs an Master/Unlit on the node's output and hands the result to the ordinary ShaderGraphCompiler. Nothing about emission, typing, conversion or diagnostics is duplicated, and a preview is by construction compiled the same way the shader is — which is the only arrangement in which a preview can be trusted to be showing the graph rather than a second opinion about it.

The vertex stage needs no special case either. Every graph emits worldViewProjection * float4(position, 1f) and exactly the varyings it asked for, so a preview is that stage over a quad with identity transforms: a renderer supplies clip-space corners as position and the unit square as texcoord, and the shader is unmodified. See ShaderGraphPreviewRenderer.

⚠ Unlit, deliberately, and not because it is the simplest master. A preview shaded by Master/PBR would answer a question nobody asked — what this value looks like as a base colour under one directional light — and it would put the answer in a lit frame's units, where an authored 0–1 tint and a pass that never ran are the same picture. Unlit writes the value straight out, so what a preview shows is the number the node computed.

⚠ A node that is itself a master previews as itself. Wiring a master's output into another master is not a thing the graph can express — a master has no output port — so the closure ends there and the shader is the one that graph would emit anyway.

Fields and properties (3)

  • public const string Master

    The master a preview ends at, when the node is not one itself.

  • public const string MasterInput

    Which of the master's inputs the previewed value is wired into.

  • public const string Name

    What the emitted shader is called, so a preview never collides with the graph's own.

Methods (1)

Used by (2)

  • ShaderGraphPreviewRendererVixen.Editor.ShaderGraph
  • ShaderGraphPreviewTestsVixen.Editor.ShaderGraph.Tests