Arvtesh / UnityFx.Outline

Screen-space outlines for Unity3d.
MIT License
1.28k stars 90 forks source link

Error when building for Windows #75

Open blair-ahlquist opened 1 year ago

blair-ahlquist commented 1 year ago

Shader error in 'Hidden/UnityFx/OutlineColor.URP': invalid subscript 'uv' at line 26 (on d3d11)

I installed UnityFx from local folder (because I couldn't find the package in the Unity store). I didn't get it to work in the editor and it makes the build fail. I had good success with UnityFx in the past (non-URP).

xzippyzachx commented 1 year ago

Also having this issue

yorkie commented 1 year ago

A workaround is removing the include to "PostProcessing/Common.hlsl" and add Vert and related structs by hand:

struct Attributes
{
    float4 positionOS : POSITION;
    float2 uv         : TEXCOORD0;
    UNITY_VERTEX_INPUT_INSTANCE_ID
};

struct Varyings
{
    float4 positionCS : SV_POSITION;
    float2 uv         : TEXCOORD0;
    UNITY_VERTEX_OUTPUT_STEREO
};

Varyings Vert(Attributes input)
{
    Varyings output;
    UNITY_SETUP_INSTANCE_ID(input);
    UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(output);

    output.positionCS = TransformObjectToHClip(input.positionOS.xyz);
    output.uv = input.uv;
    return output;
}

This was introduced at https://github.com/Arvtesh/UnityFx.Outline/commit/9b82ddefa954b870e1bcf997d31af84c4718bc4d, which works with Unity 2021, but failed at Unity 2022(URP14). The reason of this failure is https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl#L36:

struct Varyings
{
    float4 positionCS : SV_POSITION;
    float2 texcoord   : TEXCOORD0;
    UNITY_VERTEX_OUTPUT_STEREO
};

URP changed the TEXCOORD0 name from uv to texcoord, but simply change input.uv to input.texcoord doesn't work, it seems texcoord is computed in the below function and not equal to the original uv:

float2 DynamicScalingApplyScaleBias(float2 xy, float4 dynamicScalingScaleBias)
{
    return dynamicScalingScaleBias.zw + xy * dynamicScalingScaleBias.xy;
}

I am not familiar with Unity Shader programming, so we can only wait for the @Arvtesh to fix it. However, at least the workaround is temporarily working for me.