d4rkc0d3r / d4rkAvatarOptimizer

d4rkpl4y3r's VRChat Avatar 3.0 optimizer
MIT License
390 stars 17 forks source link

Recursive shader includes does not expand paths properly #106

Closed hyblocker closed 4 months ago

hyblocker commented 4 months ago

The recursive shader include parser fails to correctly resolve the following types of paths:

// Common files
#include "/Assets/Hekky/Shaders/Common/Sampling.cginc"
#include "/Assets/Hekky/Shaders/Common/VRCMisc.cginc"
#include "/Assets/Hekky/Shaders/Common/AudioLinkHelpers.cginc"
#include "/Assets/Hekky/Shaders/Common/UnityUtils.cginc"
#include "/Assets/Hekky/Shaders/Common/Lighting.cginc"
#include "/Assets/Hekky/Shaders/Common/Blending.cginc"

These paths use a / to tell the shader compiler to start looking at the project root, so that no matter where I use the above lines from within a project, it will always find the absolute path.

d4rkc0d3r commented 4 months ago

Try to remove the leading /. Weird that it doesn't work though as I remember specifically adding support for that https://github.com/d4rkc0d3r/d4rkAvatarOptimizer/blob/main/Editor/ShaderAnalyzer.cs#L382

hyblocker commented 4 months ago

I had to change it to this to get it to work:

if (currentFilePath.StartsWithSimple("/Assets/") || currentFilePath.StartsWithSimple("Assets/"))
{
    var path = Path.GetDirectoryName(callerPath);
    var assetFolderPath = path.IndexOf("Assets") != -1 ? path.Substring(0, path.IndexOf("Assets") - 1) : path;
    if (currentFilePath[0] == '/') {
        currentFilePath = currentFilePath.Substring(1);
    }
    currentFilePath = Path.Combine(assetFolderPath, currentFilePath);
}

I think it's because of the leading / causing Path.Combine to mess up the evaluated path.