Search Unity

Resolved HDRP Shaders: Cannot Open Source Files and More

Discussion in 'Code Editors & IDEs' started by wildermuth, Sep 21, 2023.

  1. wildermuth

    wildermuth

    Joined:
    Jun 20, 2023
    Posts:
    2
    Solution: Visual Studio does not understand .shader files. Installing Rider as my project's IDE resolved the issues.


    The Problem

    When opening a shader asset, the boiler plate code is filled with errors:
    shader errors 4.jpg
    (Yes, I accidentally deleted a letter in the first line while preparing this post, but the error results regardless, as seen below)
    • Error HLSL0029 Cannot resolve type: 'Shader'. C:\Users\gnosn\4th Sobel\Assets\Sobel\Sobel.shader 1
    • Error HLSL0009 Found '"FullScreen/Sobel"' but expected '<identifier>'. C:\Users\gnosn\4th Sobel\Assets\Sobel\Sobel.shader 1
    • Error HLSL0010 Unexpected token '"FullScreen/Sobel"'. C:\Users\gnosn\4th Sobel\Assets\Sobel\Sobel.shader 1
    • Error HLSL0009 Found '"FullScreen/Sobel"' but expected ';'. C:\Users\gnosn\4th Sobel\Assets\Sobel\Sobel.shader 1
    • Error HLSL0018 Cannot open source file 'Packages/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/RenderPass/CustomPass/CustomPassCommon.hlsl'. C:\Users\gnosn\4th Sobel\Assets\Sobel\Sobel.shader 10
    And so on down through the code.

    'Original' code results in the same (this code is from a tutorial project created by someone else):
    shader errors 2.jpg

    • Error HLSL0029 Cannot resolve type: 'Shader'. C:\Users\gnosn\Downloads\HDRPTutorial_SobelEffect-master\Assets\Sobel Effect\Sobel.shader 1
    • Error HLSL0009 Found '"Hidden/Shader/Sobel"' but expected '<identifier>'. C:\Users\gnosn\Downloads\HDRPTutorial_SobelEffect-master\Assets\Sobel Effect\Sobel.shader 1
    • Error HLSL0009 Found '"Hidden/Shader/Sobel"' but expected ';'. C:\Users\gnosn\Downloads\HDRPTutorial_SobelEffect-master\Assets\Sobel Effect\Sobel.shader 1
    • Error HLSL0010 Unexpected token '"Hidden/Shader/Sobel"'. C:\Users\gnosn\Downloads\HDRPTutorial_SobelEffect-master\Assets\Sobel Effect\Sobel.shader 1
    • Error HLSL0018 Cannot open source file 'Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl'. C:\Users\gnosn\Downloads\HDRPTutorial_SobelEffect-master\Assets\Sobel Effect\Sobel.shader 14
    • Error HLSL0018 Cannot open source file 'Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl'. C:\Users\gnosn\Downloads\HDRPTutorial_SobelEffect-master\Assets\Sobel Effect\Sobel.shader 15
    • Error HLSL0018 Cannot open source file 'Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/FXAA.hlsl'. C:\Users\gnosn\Downloads\HDRPTutorial_SobelEffect-master\Assets\Sobel Effect\Sobel.shader 17
    • Error HLSL0018 Cannot open source file 'Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl'. C:\Users\gnosn\Downloads\HDRPTutorial_SobelEffect-master\Assets\Sobel Effect\Sobel.shader 16
    • Error HLSL0018 Cannot open source file 'Packages/com.unity.render-pipelines.high-definition/Runtime/PostProcessing/Shaders/RTUpscale.hlsl'. C:\Users\gnosn\Downloads\HDRPTutorial_SobelEffect-master\Assets\Sobel Effect\Sobel.shader 18
    • Error HLSL0018 Cannot open source file 'Packages/com.unity.render-pipelines.high-definition/Runtime/Material/NormalBuffer.hlsl'. C:\Users\gnosn\Downloads\HDRPTutorial_SobelEffect-master\Assets\Sobel Effect\Sobel.shader 19
    And so on down through the code.


    What I'm Running

    Unity:
    • 2022.3.9f1 (but I receive the same errors with 2022.3.2f1 and 2022.2.6f1)
    Packages:
    • HDRP 14.0.8
    • HDRP Config 14.0.8
    • Shader Graph 14.0.8
    PC:
    • Windows 11 Pro

    What I've Tried
    • Deleting the library
    • Various versions of Unity
    • Downloading completed projects from Git
    • Opening the HDRP tutorial project
    • Opening a normal 3D project then activating HDRP (and using the Wizard, of course)
    • Opening a 3D HDRP project
    • A lot of googling
    How I Got to this Point
    • Open new 3D HDRP Project
    • Assets -> Create -> Rendering -> HDRP C# Post Process Volume
    • Assets -> Create -> Shader -> HDRP Post Process
    • When opening the code for the Shader -> HDRP Post Process, I find the errors mentioned in this post.



    Am I missing a step in my initial setup of the project?
    Am I missing a package?
    Are my packages somehow incompatible with each other or the versions of Unity listed above?
    I have no idea.

    If anyone has any advice on how to resolve this, I would be thankful. I'm pretty deep into this (my first Unity project) and hate to be at a sudden standstill.

    Thanks to anyone who read this far and, especially, to anyone who responds with some tips. If you need more information, please ask.
     
    Last edited: Sep 21, 2023
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,909
    I may be wrong here but as far back as I remember Visual Studio (2019 back then) does not understand .shader files. It may understand HLSL, I think it has some support for that or for the old format (CG) but I'm not sure. It may simply not be aware of Unity's format and extensions or the fact that these aren't CG programs anymore.

    If VS 2020+ is known to correctly analyze and highlight .shader files, it may require some sort of setting to tell VS that .shader is actually a Unity HLSL (HDRP) shader.

    There's a paid plugin, and also Jetbrains Rider works with .shader files (and generally it's THE companion IDE for Unity) => https://forum.unity.com/threads/set...rk-with-hlsl-and-shader.1032145/#post-7446779
     
    simonmonkeyz likes this.
  3. wildermuth

    wildermuth

    Joined:
    Jun 20, 2023
    Posts:
    2
    You were correct! I installed Rider and I'm back on track. I can't thank you enough for taking the time to help me figure this out. Seriously.
     
    CodeSmile likes this.
  4. simonmonkeyz

    simonmonkeyz

    Joined:
    Jan 31, 2022
    Posts:
    2
    Installing ShaderlabVS extension makes so that VS can read and compile
     
    Last edited: Oct 3, 2023
    michaalwronaa and lexhtam like this.