Search Unity

Question Invalid conditional expression

Discussion in 'Shader Graph' started by Lex_212, May 1, 2021.

  1. Lex_212

    Lex_212

    Joined:
    Oct 3, 2020
    Posts:
    84
    Hi, I am doing a toon shader and I get the Invalid condition expression error everytime I name the custom function. I am using Unity 2020.3.6f1
    This is the code from the custom light
    Code (CSharp):
    1. #ifndef CUSTOM_LIGHTING_INCLUDED
    2. #define CUSTOM_LIGHTING_INCLUDED
    3.  
    4. void MainLight_float(float3 WorldPos, out float3 Direction, out float3 Color, out float DistanceAtten, out float ShadowAtten)
    5. {
    6. #ifdef SHADERGRAPH_PREVIEW
    7.     Direction = float3(0.5, 0.5, 0);
    8.     Color = 1;
    9.     DistanceAtten = 1;
    10.     ShadowAtten = 1;
    11. #else
    12. #if SHADOWS_SCREEN
    13.     float4 clipPos = TransformWorldToHClip(WorldPos);
    14.     float4 shadowCoord = ComputeScreenPos(clipPos);
    15. #else
    16.     float4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
    17. #endif
    18.     Light mainLight = GetMainLight(shadowCoord);
    19.     Direction = mainLight.direction;
    20.     Color = mainLight.color;
    21.     DistanceAtten = mainLight.distanceAttenuation;
    22.     ShadowAtten = mainLight.shadowAttenuation;
    23. #endif
    24. }
    25.  
    26. void MainLight_half(float3 WorldPos, out half3 Direction, out half3 Color, out half DistanceAtten, out half ShadowAtten)
    27. {
    28. #if SHADERGRAPH_PREVIEW
    29.     Direction = half3(0.5, 0.5, 0);
    30.     Color = 1;
    31.     DistanceAtten = 1;
    32.     ShadowAtten = 1;
    33. #else
    34. #if SHADOWS_SCREEN
    35.     half4 clipPos = TransformWorldToHClip(WorldPos);
    36.     half4 shadowCoord = ComputeScreenPos(clipPos);
    37. #else
    38.     half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
    39. #endif
    40.     Light mainLight = GetMainLight(shadowCoord);
    41.     Direction = mainLight.direction;
    42.     Color = mainLight.color;
    43.     DistanceAtten = mainLight.distanceAttenuation;
    44.     ShadowAtten = mainLight.shadowAttenuation;
    45. #endif
    46. }
    47.  
    48. void DirectSpecular_float(float3 Specular, float Smoothness, float3 Direction, float3 Color, float3 WorldNormal, float3 WorldView, out float3 Out)
    49. {
    50. #if SHADERGRAPH_PREVIEW
    51.     Out = 0;
    52. #else
    53.     Smoothness = exp2(10 * Smoothness + 1);
    54.     WorldNormal = normalize(WorldNormal);
    55.     WorldView = SafeNormalize(WorldView);
    56.     Out = LightingSpecular(Color, Direction, WorldNormal, WorldView, float4(Specular, 0), Smoothness);
    57. #endif
    58. }
    59.  
    60. void DirectSpecular_half(half3 Specular, half Smoothness, half3 Direction, half3 Color, half3 WorldNormal, half3 WorldView, out half3 Out)
    61. {
    62. #if SHADERGRAPH_PREVIEW
    63.     Out = 0;
    64. #else
    65.     Smoothness = exp2(10 * Smoothness + 1);
    66.     WorldNormal = normalize(WorldNormal);
    67.     WorldView = SafeNormalize(WorldView);
    68.     Out = LightingSpecular(Color, Direction, WorldNormal, WorldView,half4(Specular, 0), Smoothness);
    69. #endif
    70. }
    71.  
    72. void AdditionalLights_float(float3 SpecColor, float Smoothness, float3 WorldPosition, float3 WorldNormal, float3 WorldView, out float3 Diffuse, out float3 Specular)
    73. {
    74.     float3 diffuseColor = 0;
    75.     float3 specularColor = 0;
    76.  
    77. #ifndef SHADERGRAPH_PREVIEW
    78.     Smoothness = exp2(10 * Smoothness + 1);
    79.     WorldNormal = normalize(WorldNormal);
    80.     WorldView = SafeNormalize(WorldView);
    81.     int pixelLightCount = GetAdditionalLightsCount();
    82.     for (int i = 0; i < pixelLightCount; ++i)
    83.     {
    84.         Light light = GetAdditionalLight(i, WorldPosition);
    85.         half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
    86.         diffuseColor += LightingLambert(attenuatedLightColor, light.direction, WorldNormal);
    87.         specularColor += LightingSpecular(attenuatedLightColor, light.direction, WorldNormal, WorldView, float4(SpecColor, 0), Smoothness);
    88.     }
    89. #endif
    90.  
    91.     Diffuse = diffuseColor;
    92.     Specular = specularColor;
    93. }
    94.  
    95. void AdditionalLights_half(half3 SpecColor, half Smoothness, half3 WorldPosition, half3 WorldNormal, half3 WorldView, out half3 Diffuse, out half3 Specular)
    96. {
    97.     half3 diffuseColor = 0;
    98.     half3 specularColor = 0;
    99.  
    100. #ifndef SHADERGRAPH_PREVIEW
    101.     Smoothness = exp2(10 * Smoothness + 1);
    102.     WorldNormal = normalize(WorldNormal);
    103.     WorldView = SafeNormalize(WorldView);
    104.     int pixelLightCount = GetAdditionalLightsCount();
    105.     for (int i = 0; i < pixelLightCount; ++i)
    106.     {
    107.         Light light = GetAdditionalLight(i, WorldPosition);
    108.         half3 attenuatedLightColor = light.color * (light.distanceAttenuation * light.shadowAttenuation);
    109.         diffuseColor += LightingLambert(attenuatedLightColor, light.direction, WorldNormal);
    110.         specularColor += LightingSpecular(attenuatedLightColor, light.direction, WorldNormal, WorldView, half4(SpecColor, 0), Smoothness);
    111.     }
    112. #endif
    113.  
    114.     Diffuse = diffuseColor;
    115.     Specular = specularColor;
    116. }
    117.  
    118. #endif
    Thanks
     

    Attached Files:

  2. Lex_212

    Lex_212

    Joined:
    Oct 3, 2020
    Posts:
    84
    I found how to fix it, you need to change all the #if to #ifdef
     
    maxximme likes this.
  3. maxximme

    maxximme

    Joined:
    Aug 18, 2021
    Posts:
    12
    Thank you so much, had the same error and this did the trick!
     
  4. Javabeans111

    Javabeans111

    Joined:
    Sep 2, 2014
    Posts:
    1
    Same problem and solved! thanks so much!:D