Search Unity

including HLSL Snippets in UnityShaders

Discussion in 'Shaders' started by Zyntherius, Aug 18, 2017.

  1. Zyntherius

    Zyntherius

    Joined:
    Nov 3, 2012
    Posts:
    6
    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
    Code (CSharp):
    1. Shader "Custom/PostEffectShader"
    2. {
    3.     Properties
    4.     {
    5.         _MainTex ("Main Texture", 2D) = "white" {}
    6.     }
    7.     SubShader
    8.     {
    9.         // No culling or depth
    10.         Cull Off ZWrite Off ZTest Always
    11.  
    12.         Pass
    13.         {
    14.             CGPROGRAM
    15.             #include "UnityCG.cginc"
    16.             #include "PostEffectShaderHLSL.cginc"
    17.             ENDCG
    18.         }
    19.     }
    20. }



    HLSL-Snippet-File (PostEffectShaderHLSL.cginc)
    Code (CSharp):
    1. #ifndef POST_EFFECT_SHADER_HLSL
    2. #define POST_EFFECT_SHADER_HLSL
    3.  
    4. #pragma vertex vert
    5. #pragma fragment frag
    6.  
    7. struct appdata
    8. {
    9.     float4 vertex : POSITION;
    10.     float2 uv : TEXCOORD0;
    11. };
    12.  
    13. struct v2f
    14. {
    15.     float2 uv : TEXCOORD0;
    16.     float4 vertex : SV_POSITION;
    17. };
    18.  
    19. inline v2f vert (appdata v)
    20. {
    21.     v2f o;
    22.     o.vertex = UnityObjectToClipPos(v.vertex);
    23.     o.uv = v.uv;
    24.     return o;
    25. }
    26.            
    27. sampler2D _MainTex;
    28.  
    29. inline fixed4 frag (v2f IN) : SV_Target
    30. {              
    31.     fixed4 col = tex2D(_MainTex, IN.uv + float2(0, sin( IN.vertex.x/50 + _Time[1]/2) / 50) );
    32.  
    33.     return col;
    34. }
    35.  
    36. #endif
     
  2. Zyntherius

    Zyntherius

    Joined:
    Nov 3, 2012
    Posts:
    6
    update
     
    DangerIncreased likes this.