Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Unity giving me syntax errors for custom hlsl shader functions in shader graph

Discussion in 'Graphics Experimental Previews' started by alexanderameye, Jul 1, 2019.

  1. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    I was trying to write a custom function node but I'm getting syntax errors.

    Code (CSharp):
    1. void Outline_float(float4 ScreenPos, float4 Color, Texture2D DepthNormalsTexture, SamplerState Sampler, float2 Texel, float SampleDistance, float Falloff, float SensitivityNormals, float SensitivityDepth, out float4 Out)
    2. {
    3. float ns_DecodeFloatRG (float2 enc) {
    4.         float2 kDecodeDot = float2(1.0, 1 / 255.0);
    5.         return dot(enc, kDecodeDot);
    6.     }
    7.  
    8.  
    9.     float checkSame(float2 centerNormal, float centerDepth, float4 theSample, float sensitivityNormals, float sensitivityDepth) {
    10.         float2 diff = abs(centerNormal - theSample.xy) * sensitivityNormals;
    11.         int isSameNormal = (diff.x + diff.y) < 0.1;
    12.         float sampleDepth = ns_DecodeFloatRG(theSample.zw);
    13.         float zdiff = abs(centerDepth - sampleDepth);
    14.         int isSameDepth = zdiff * sensitivityDepth < 0.99 * centerDepth;
    15.         return (isSameNormal * isSameDepth) ? 1.0 : 0.0;
    16.     }
    17.  
    18.     float4 edgeColor() {
    19.         float sampleSizeX = Texel.x;
    20.         float sampleSizeY = Texel.y;
    21.         float2 screenUV = ScreenPos.xy;
    22.  
    23.         float2 _uv2 = screenUV + float2(-sampleSizeX, +sampleSizeY) * SampleDistance;
    24.         float2 _uv3 = screenUV + float2(+sampleSizeX, -sampleSizeY) * SampleDistance;
    25.         float2 _uv4 = screenUV + float2(sampleSizeX, sampleSizeY) * SampleDistance;
    26.         float2 _uv5 = screenUV + float2(-sampleSizeX, -sampleSizeY) * SampleDistance;
    27.  
    28.         float4 center = SAMPLE_TEXTURE2D(DepthNormalsTexture, Sampler, screenUV);
    29.         float4 sample1 = SAMPLE_TEXTURE2D(DepthNormalsTexture, Sampler, _uv2);
    30.         float4 sample2 = SAMPLE_TEXTURE2D(DepthNormalsTexture, Sampler, _uv3);
    31.         float4 sample3 = SAMPLE_TEXTURE2D(DepthNormalsTexture, Sampler, _uv4);
    32.         float4 sample4 = SAMPLE_TEXTURE2D(DepthNormalsTexture, Sampler, _uv5);
    33.  
    34.         float edge = 1.0;
    35.  
    36.         float2 centerNormal = center.xy;
    37.         float centerDepth = ns_DecodeFloatRG(center.zw);
    38.  
    39.         float d = clamp(centerDepth * Falloff - 0.05, 0.0, 1.0);
    40.         float4 depthFade = float4(d, d, d, 1.0);
    41.  
    42.         edge *= checkSame(centerNormal, centerDepth, sample1, sensitivityNormals, sensitivityDepth);
    43.         edge *= checkSame(centerNormal, centerDepth, sample2, sensitivityNormals, sensitivityDepth);
    44.         edge *= checkSame(centerNormal, centerDepth, sample3, sensitivityNormals, sensitivityDepth);
    45.         edge *= checkSame(centerNormal, centerDepth, sample4, sensitivityNormals, sensitivityDepth);
    46.  
    47.         return edge * Color + (1.0 - edge) * (depthFade * Color);
    48.     }
    49.    
    50.    
    51.     Out = edgeColor();
    52. }
    upload_2019-7-2_0-10-57.png

    I don't see where my errors are...
     
    _watcher_ likes this.
  2. alexanderameye

    alexanderameye

    Joined:
    Nov 27, 2013
    Posts:
    1,383
    This was a dumb mistake, I believe I just had to put the methods outside of the void method