including HLSL Snippets in UnityShaders

I’m looking for a solution to use the “HLSL Tool for Visual Studio” for the HLSL snippets in the .shader-files. Visual Studio doesn’t directly support ShaderLab combined with HLSL snippets (the older ShaderLab Extension (SUS) for Unity doesn’t work anymore in VS2017).

Currently I’m writing the ShaderLab code in MonoDev and trying to include the HLSL snippets so that VS needs to interpret only the HLSL snippet - without any success.

Is it possible to do this by including the hlsl code in the .shader-file?

.shader-File

Shader "Custom/PostEffectShader"
{
    Properties
    {
        _MainTex ("Main Texture", 2D) = "white" {}
    }
    SubShader
    {
        // No culling or depth
        Cull Off ZWrite Off ZTest Always

        Pass
        {
            CGPROGRAM
            #include "UnityCG.cginc"
            #include "PostEffectShaderHLSL.cginc"
            ENDCG
        }
    }
}

HLSL-Snippet-File (PostEffectShaderHLSL.cginc)

#ifndef POST_EFFECT_SHADER_HLSL
#define POST_EFFECT_SHADER_HLSL

#pragma vertex vert
#pragma fragment frag

struct appdata
{
    float4 vertex : POSITION;
    float2 uv : TEXCOORD0;
};

struct v2f
{
    float2 uv : TEXCOORD0;
    float4 vertex : SV_POSITION;
};

inline v2f vert (appdata v)
{
    v2f o;
    o.vertex = UnityObjectToClipPos(v.vertex);
    o.uv = v.uv;
    return o;
}
           
sampler2D _MainTex;

inline fixed4 frag (v2f IN) : SV_Target
{               
    fixed4 col = tex2D(_MainTex, IN.uv + float2(0, sin( IN.vertex.x/50 + _Time[1]/2) / 50) );

    return col;
}

#endif

update

1 Like