Search Unity

Bug Shader graph of URP of 2020.2 does not support custom nodes and more issue

Discussion in 'Shader Graph' started by Deleted User, Dec 30, 2020.

  1. Deleted User

    Deleted User

    Guest

    I was trying to use the custom lighting.hlsl file with custom node from boat attack but gave an error message saying "invalid condition" I tried the another custom lighting from GitHub and the one from the unity docs but it was still giving the same error message.... it ran perfectly fine on 2019.4 but the new in 2020.2.0f is giving errors... And also the shader graphs when imported from boat attack do not work in 2020.2 yes they did ran perfectly on 2019.4 and the custom function node from the boat attack shader graphs do not show any settings in the node tab when selected... I can later send u screenshots if u require..
     
  2. ElliotB

    ElliotB

    Joined:
    Aug 11, 2013
    Posts:
    282
    If you have
    Code (csharp):
    1. #if SHADERGRAPH_PREVIEW
    then change it for
    Code (csharp):
    1. #if defined(SHADERGRAPH_PREVIEW)
     
  3. Deleted User

    Deleted User

    Guest

    @ElliotB Thank u very much it woks now!!:)
     
  4. kailhan54321

    kailhan54321

    Joined:
    Jun 10, 2020
    Posts:
    1
    Thank u, replacing "#if SHADERGRAPH_PREVIEW" with "#if defined(SHADERGRAPH_PREVIEW)" works.
     
  5. ColorStorm

    ColorStorm

    Joined:
    Jul 4, 2012
    Posts:
    28
    Thank you! It works, but where is the documentation for those?
     
    lteran9 likes this.
  6. unity_416jraimondi

    unity_416jraimondi

    Joined:
    Aug 6, 2018
    Posts:
    2
    Do you happen to know if they changed this for #ifndef too? That one is giving issues
     
  7. LGGDevs

    LGGDevs

    Joined:
    Dec 1, 2016
    Posts:
    4
    just hit this and started googling myself, try
    #if !defined (SHADERGRAPH_PREVIEW)


    really unsure why this change was needed after leaving preview but this seems to work.
     
  8. ALOISIOPN

    ALOISIOPN

    Joined:
    May 9, 2015
    Posts:
    1
    Here's what worked for me!
    Tnks @ElliotB
    ;)

    Code (CSharp):
    1.  
    2. #ifndef CUSTOM_LIGHTING_INCLUDED
    3. #define CUSTOM_LIGHTING_INCLUDED
    4.  
    5. void MainLight_float(float3 WorldPos, out float3 Direction, out float3 Color, out float DistanceAtten, out float ShadowAtten)
    6. {
    7. #if defined(SHADERGRAPH_PREVIEW)
    8.     Direction = float3(0.5, 0.5, 0);
    9.     Color = 1;
    10.     DistanceAtten = 1;
    11.     ShadowAtten = 1;
    12. #else
    13. #if SHADOWS_SCREEN
    14.     float4 clipPos = TransformWorldToHClip(WorldPos);
    15.     float4 shadowCoord = ComputeScreenPos(clipPos);
    16. #else
    17.     float4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
    18. #endif
    19.     Light mainLight = GetMainLight(shadowCoord);
    20.     Direction = mainLight.direction;
    21.     Color = mainLight.color;
    22.     DistanceAtten = mainLight.distanceAttenuation;
    23.     ShadowAtten = mainLight.shadowAttenuation;
    24. #endif
    25. }
    26. void MainLight_half(float3 WorldPos, out half3 Direction, out half3 Color, out half DistanceAtten, out half ShadowAtten)
    27. {
    28. #if defined(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 defined(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 defined(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
    119.  
     
  9. unity_B8EAD0EAE6DE639760CD

    unity_B8EAD0EAE6DE639760CD

    Joined:
    Jan 14, 2022
    Posts:
    1
    All in one file? i'm newbie at coding