tgjones / HlslTools

A Visual Studio extension that provides enhanced support for editing High Level Shading Language (HLSL) files
http://timjones.io/blog/archive/2016/04/25/hlsl-tools-for-visual-studio-v1.0-released
Other
561 stars 97 forks source link

[Request] Include supporting a starting "/" #195

Closed TisAFleshWound closed 3 years ago

TisAFleshWound commented 3 years ago

Due to format requirements using for Unreal Engine 4 user is currently forced to keep #includes in a "/Folder/File.usf" format. This seems to prevent the #include from registering with this extension.

Example of #include working in Unreal Engine but failing in this extension HLSL TOOLS (Visual Studio Code) image

Example of #include which fails in Unreal Engine which works with this extension HLSL TOOLS (Visual Studio Code) image UNREAL ENGINE image

An extension option allowing equivocation of "Folder/File.usf" and "/Folder/File.usf" or a fallback #include search using the latter would greatly enhance utility of the extension with Unreal Engine 4 and be greatly appreciated by this user.

PiezPiedPy commented 3 years ago

Have to agree that this issue being fixed would help immensely.

tgjones commented 3 years ago

I've added support for this - although first I had to read up on how these virtual directory things work in Unreal Engine 😄

You can now add virtual directory mappings to shadertoolsconfig.json (I've updated the readme with this information):

{
  "hlsl.virtualDirectoryMappings": {
    "/Shaders": "C:\\MyProject\\Shaders"
  }
}

I'm going to release a new version of HLSL Tools shortly, and then I'd appreciate if you can please test this and let me know if it works correctly.

PiezPiedPy commented 3 years ago

@tgjones Unfortunately I can't seem to get the virtual directories to work. I still get the error :

HLSL0018 Cannot open source file '/Engine/Public/Platform.ush'. D:\Private Shit\Unreal\DrasticAction\Shaders\Compute\CartesianSphere.usf

offending line in the shader is :

#include "/Engine/Public/Platform.ush"

config file is :

{
    "root": true,
    "hlsl.preprocessorDefinitions":
    {
        "HLSL_TOOLS": true
    },
    "hlsl.additionalIncludeDirectories":
    [
        "C:\\Program Files\\Unreal Engine\\UE_4.26\\Engine\\Shaders\\Public"
    ],
    "hlsl.virtualDirectoryMappings":
    {
        "/Engine": "C:\\Program Files\\Unreal Engine\\UE_4.26\\Engine\\Shaders"
    }
}

The shader works fine in Unreal so as a workaround I am using a pre-processor definition with an additional include directory

#ifndef HLSL_TOOLS
#include "/Engine/Public/Platform.ush"
#else
#include "Platform.ush"
#endif

The workaround works fine in Unreal and with HLSL Tools.

One thing I have noticed is the include directive points to /Engine/Public/Platform.ush although the file actually resides at Engine/Shaders/Public/Platform.ush