Search Unity

including shadows.hlsl causes redefinition error

Discussion in 'Shaders' started by BoggyBolt, Oct 28, 2021.

  1. BoggyBolt

    BoggyBolt

    Joined:
    Oct 3, 2019
    Posts:
    2
    I'm using Unity 2021.2.0b16.
    I'm also almost completely new to shaders, so there's that.

    I'm trying to rewrite a shader graph into a shader since I need to do some things which I can't in shader graph

    The shader graph I made used a custom function(from a youtube tutorial), and it needs a reference to
    ShaderLibrary/Shadows.hlsl
    The problem is, when I try to include shadows.hlsl, it gives a redefinition error of 'PackHeightmap' in Common.hlsl if I include UnityCG.cginc, and a redefinition error of '_Time' in UnityInput.hlsl (which happens even if I only include shadows.hlsl)

    Am I doing something wrong?
    There's more information about *literally anything else* on the internet than this.



    Code (Shaderlab):
    1. #ifndef CUSTOM_LIGHTING_INCLUDED
    2. #define CUSTOM_LIGHTING_INCLUDED
    3.  
    4. void CalculateMainLight_float(float3 WorldPos, out float3 Direction, out float3 Color,
    5.     out half DistanceAtten, out half ShadowAtten) {
    6. #ifdef SHADERGRAPH_PREVIEW
    7.     Direction = half3(0.5, 0.5, 0);
    8.     Color = 1;
    9.     DistanceAtten = 1;
    10.     ShadowAtten = 1;
    11. #else
    12. #if SHADOWS_SCREEN
    13.     half4 clipPos = TransformWorldToHClip(WorldPos);
    14.     half4 shadowCoord = ComputeScreenPos(clipPos);
    15. #else
    16.     half4 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.  
    24. #endif
    25. }
    26. #endif
    Also note that this function works completely fine in Shader Graph.
     
  2. BoggyBolt

    BoggyBolt

    Joined:
    Oct 3, 2019
    Posts:
    2
    Nevermind. The real reason it was happening was because I was using CGPROGRAM instead of HLSLPROGRAM.
    Apparently every tutorial regarding shaders is outdated.
     
    bajja likes this.
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    If you're writing shaders for the URP or HDRP, then yes, basically every shader tutorial out there is now out of date.