返回 Skills 目录
unity-technologies/skills已通过检查

SKILL DETAIL

shader-graph-create-custom-node

unity-technologies/skills/shader-graph-create-custom-node

此技能用于从 HLSL 代码生成自定义 Shader Graph 节点。当用户想要创建新的 Shader Graph 节点,或使现有 HLSL 代码作为反射函数节点工作时,可使用此技能。 操作步骤包括:生成带有 `UNITY_EXPORT_REFLECTION` 预处理定义的 HLSL 函数定义;使用 Shader Graph 提示标签(如 `sg:ProviderKey`、`sg:SearchCategory`、`sg:SearchTerms`、`sg:DisplayName`)进行装饰;将代码写入 `.hlsl` 资产,并确保文件以 `#include "ShaderApiReflectionSupport.hlsl"` 开头。

安装量 · 105查看来源

Installation

npx skills add https://github.com/unity-technologies/skills --skill shader-graph-create-custom-node

技能文件

SKILL.md

最近同步 · 2026年9月13日

resources/all_hints.hlsl›
#include "ShaderApiReflectionSupport.hlsl"

namespace Namespace
{
    struct CustomStruct
    {
        float Value;
    };

/// <funchints>
///     <sg:ProviderKey>AllHintsUniqueStableID</sg:ProviderKey>
///     <sg:DisplayName>All Known Hints</sg:DisplayName>
///     <sg:ReturnDisplayName>Final Result</sg:ReturnDisplayName>
///     <sg:SearchCategory>Hints/All</sg:SearchCategory>
///     <sg:SearchTerms>Features, Reflected, Every, Hint</sg:SearchTerms>
///     <sg:SearchName>All Hints Search Name</sg:SearchName>
/// </funchints>
/// <paramhints name="a">
///     <sg:DisplayName>Custom Struct Value</sg:DisplayName>
///     <sg:Default>0.5</sg:Default>
///     <sg:External>Namespace</sg:External>
/// </paramhints>
/// <paramhints name="c3">
///     <sg:DisplayName>Color 3</sg:DisplayName>
///     <sg:Color />
///     <sg:Default>1,1,0</sg:Default>
/// </paramhints>
/// <paramhints name="c4">
///     <sg:DisplayName>Color 4</sg:DisplayName>
///     <sg:Color />
///     <sg:Default>1,1,0,1</sg:Default>
/// </paramhints>
/// <paramhints name="sc3">
///     <sg:DisplayName>Static Color 3</sg:DisplayName>
///     <sg:Color />
///     <sg:Static />
///     <sg:Default>1,1,0</sg:Default>
/// </paramhints>
/// <paramhints name="sc4">
///     <sg:DisplayName>Static Color 4</sg:DisplayName>
///     <sg:Color />
///     <sg:Static />
///     <sg:Default>1,1,0,1</sg:Default>
/// </paramhints>
/// <paramhints name="d">
///     <sg:DisplayName>Dropdown</sg:DisplayName>
///     <sg:Dropdown>OptionA, OptionB, OptionC</sg:Dropdown>
///     <sg:Default>1</sg:Default>
/// </paramhints>
/// <paramhints name="sd">
///     <sg:DisplayName>Dropdown</sg:DisplayName>
///     <sg:Dropdown>OptionA, OptionB, OptionC</sg:Dropdown>
///     <sg:Static />
///     <sg:Default>2</sg:Default>
/// </paramhints>
/// <paramhints name="r">
///     <sg:DisplayName>Range</sg:DisplayName>
///     <sg:Range>0, 1</sg:Range>
///     <sg:Default>0.75</sg:Default>
/// </paramhints>
/// <paramhints name="sr">
///     <sg:DisplayName>Range</sg:DisplayName>
///     <sg:Static />
///     <sg:Range>0, 1</sg:Range>
///     <sg:Default>0.25</sg:Default>
/// </paramhints>
/// <paramhints name="sb">
///     <sg:DisplayName>Toggle</sg:DisplayName>
///     <sg:Static />
///     <sg:Default>1</sg:Default>
/// </paramhints>
/// <paramhints name="si">
///     <sg:DisplayName>Integer</sg:DisplayName>
///     <sg:Static />
///     <sg:Default>5</sg:Default>
/// </paramhints>
UNITY_EXPORT_REFLECTION float3 AllHints(
    inout CustomStruct a,
    float3 c3,
    inout float4 c4,
    float3 sc3,
    float4 sc4,
    inout uint d,
    uint sd,
    float r,
    float sr,
    bool sb,
    int si
)
{
    return float3(a.Value, sr, sc4.r);
}

} // Namespace

/// <funchints>
///     <sg:ProviderKey>GoodReferables</sg:ProviderKey>
/// </funchints>
/// <paramhints name="UV">
///     <UV/>
///     <Default>UV2</Default>
/// </paramhints>
/// <paramhints name="alsoUV">
///     <sg:Referable>UV</sg:Referable>
///     <Default>UV1</Default>
/// </paramhints>
/// <paramhints name="Position">
///     <Position/>
///     <Default>AbsoluteWorld</Default>
/// </paramhints>
/// <paramhints name="Normal">
///     <Normal/>
///     <Default>World</Default>
/// </paramhints>
/// <paramhints name="Tangent">
///     <Tangent/>
///     <Default>Object</Default>
/// </paramhints>
/// <paramhints name="Bitangent">
///     <Bitangent/>
///     <Default>Tangent</Default>
/// </paramhints>
/// <paramhints name="ViewDirection">
///     <ViewDirection/>
///     <Default>Screen</Default>
/// </paramhints>
/// <paramhints name="VertColor">
///     <VertexColor/>
/// </paramhints>
/// <paramhints name="ScreenPosition">
///     <ScreenPosition/>
///     <Default>Pixel</Default>
/// </paramhints>
/// <paramhints name="defaultValue">
///     <Default>1,0,0</Default>
/// </paramhints>
UNITY_EXPORT_REFLECTION float3 ReferableGood(float2 UV,
                                            float2 alsoUV,
                                            float3 Position,
                                            float3 Normal,
                                            float3 Tangent,
                                            float3 Bitangent,
                                            float3 ViewDirection,
                                            float4 VertColor,
                                            float4 ScreenPosition,
                                            float3 defaultValue)
{
    return float3(1,1,0);
}

/// <funchints>
///     <sg:ProviderKey>PrecisionTest</sg:ProviderKey>
///     <Precision/>
/// </funchints>
/// <paramhints name="a">
///     <Dynamic/>
/// </paramhints>
/// <paramhints name="b">
///     <Dynamic/>
/// </paramhints>
/// <paramhints name="c">
///     <Dynamic/>
/// </paramhints>
UNITY_EXPORT_REFLECTION float2 PrecisionTest(float a, half b, out float c)
{
    c = a + b;
    return (a,b);
}

/// <funchints>
///     <sg:ProviderKey>LinkageExample</sg:ProviderKey>
/// </funchints>
/// <paramhints name="test">
///     <Linkage>other</Linkage>
/// </paramhints>
UNITY_EXPORT_REFLECTION float3 LinkageExample(bool test, float other)
{
    if (test)
        return float3(other, 0, 0);
    else
        return float3(0, other, 0);
}
SKILL.md›
---
name: shader-graph-create-custom-node
description: "Generates custom Shader Graph nodes from HLSL code. Use when the user wants to create a new Shader Graph node or make existing HLSL code work as a reflected function node."
required_packages:
  com.unity.shadergraph: ">=17.5.0"
---
# Generating a custom Shader Graph node

## Step 1: Generate an HLSL function definition
- The function must be preceded by the preprocessor define `UNITY_EXPORT_REFLECTION`

## Step 2: Decorate with Shader Graph hint tags
- See `resources/all_hints.hlsl` for all valid hint tags and usage patterns
- C#-style documentation tags are supported outside of `funchints` or `paramhints` blocks
- Required function hints:
  - `sg:ProviderKey`
  - `sg:SearchCategory`
  - `sg:SearchTerms`
  - `sg:DisplayName`

## Step 3: Write the code to an asset
- Search the project for a `ShaderInclude` asset (`.hlsl`) that already contains custom Shader Graph nodes
- If a matching asset exists, show the user its current contents and ask for confirmation before appending the new code
- If no matching asset exists, create a new `.hlsl` asset
- Ensure the file begins with `#include "ShaderApiReflectionSupport.hlsl"`