mob-sakai / SoftMaskForUGUI

Enhance Unity UI (uGUI) with advanced soft-masking features to create more visually appealing effects!
https://github.com/mob-sakai/SoftMaskForUGUI
MIT License
1.91k stars 257 forks source link

Program 'frag', error X8000: D3D11 Internal Compiler Error: #131

Closed danishalistruckd closed 2 years ago

danishalistruckd commented 2 years ago

Shader error in 'Hidden/UI/Default (SoftMaskable)': Program 'frag', error X8000: D3D11 Internal Compiler Error: Invalid Bytecode: Incompatible min precision type for operand #1 of opcode #76 (counts are 1-based). Expected int or uint. at line 49 (on metal)

Unity Editor version 2020.3.22f1 Platform iOS Colour Scheme Linear- sRGB Build options: [e.g. IL2CPP, .Net 4.x]

Additional context Also having issues with TextMeshPro. I can only see missing material i.e magenta colour for images

Shader error in 'Hidden/TextMeshPro/Distance Field (SoftMaskable)': Program 'PixShader', error X8000: D3D11 Internal Compiler Error: Invalid Bytecode: Incompatible min precision type for operand #1 of opcode #116 (counts are 1-based). Expected int or uint. at line 112 (on metal)

Shader error in 'Hidden/TextMeshPro/Mobile/Distance Field (SoftMaskable)': Program 'PixShader', error X8000: D3D11 Internal Compiler Error: Invalid Bytecode: Incompatible min precision type for operand #1 of opcode #77 (counts are 1-based). Expected int or uint. at line 81 (on metal)

nindim commented 2 years ago

Hi,

I am hitting this shader compile error as well when building for Android with GLES3.

I have tracked it down to the step calls in SoftMask.cginc.

This Unity bug report confirms there appears to be a HLSL compiler bug causing this: https://fogbugz.unity3d.com/default.asp?934464_sjh4cs4ok77ne0cj&_ga=2.124069071.432066521.1640792064-45545210.1640792064

The final reply shows a workaround by replacing the step calls (although the code presented is not quite correct as far as the CG implementation is concerned: https://developer.download.nvidia.com/cg/step.html)

I have managed to get a compiled shader by replacing all the calls to step in SoftMask.cginc with:

// Workaround for a HLSL compiler issue:
// https://fogbugz.unity3d.com/default.asp?934464_sjh4cs4ok77ne0cj&_ga=2.124069071.432066521.1640792064-45545210.1640792064
float CustomStep(float a, float x)
{
    return x >= a;
}

@mob-sakai - Can this fix be rolled into a new release, please?

Thank you!

Yaski commented 2 years ago

Yes that fixes the problem. We need that fix in the main branch.

nabergh commented 2 years ago

@nindim's solution is perfect! Here's my full SoftMask.cginc for those who want to do a full copy/paste. @mob-sakai an update would be appreciated by many others I'm sure.

#define UI_SOFTMASK_INCLUDED

sampler2D _SoftMaskTex;
float _Stencil;
float4x4 _GameVP;
float4x4 _GameTVP;
half4 _MaskInteraction;

float CustomStep(float a, float x)
{
    return x >= a;
}

fixed Approximately(float4x4 a, float4x4 b)
{
    float4x4 d = abs(a - b);
    return step(
        max(d._m00,max(d._m01,max(d._m02,max(d._m03,
        max(d._m10,max(d._m11,max(d._m12,max(d._m13,
        max(d._m20,max(d._m21,max(d._m22,max(d._m23,
        max(d._m30,max(d._m31,max(d._m32,d._m33))))))))))))))),
        0.5);
}

#if SOFTMASK_EDITOR
float SoftMaskInternal(float4 clipPos, float4 wpos)
#else
float SoftMaskInternal(float4 clipPos)
#endif
{
    half2 view = clipPos.xy/_ScreenParams.xy;
    #if SOFTMASK_EDITOR
        fixed isSceneView = 1 - Approximately(UNITY_MATRIX_VP, _GameVP);
        float4 cpos = mul(_GameTVP, mul(UNITY_MATRIX_M, wpos));
        view = lerp(view, cpos.xy / cpos.w * 0.5 + 0.5, isSceneView);
        #if UNITY_UV_STARTS_AT_TOP
            view.y = lerp(view.y, 1 - view.y, CustomStep(0, _ProjectionParams.x));
        #endif
    #elif UNITY_UV_STARTS_AT_TOP
        view.y = lerp(view.y, 1 - view.y, CustomStep(0, _ProjectionParams.x));
    #endif

    fixed4 mask = tex2D(_SoftMaskTex, view);
    half4 alpha = saturate(lerp(fixed4(1, 1, 1, 1), lerp(mask, 1 - mask, _MaskInteraction - 1), _MaskInteraction));
    #if SOFTMASK_EDITOR
    alpha *= CustomStep(0, view.x) * CustomStep(view.x, 1) * CustomStep(0, view.y) * CustomStep(view.y, 1);
    #endif

    return alpha.x * alpha.y * alpha.z * alpha.w;
}

#if SOFTMASK_EDITOR
    #define SOFTMASK_EDITOR_ONLY(x) x
    #define SoftMask(clipPos, worldPosition) SoftMaskInternal(clipPos, worldPosition)
#else
    #define SOFTMASK_EDITOR_ONLY(x)
    #define SoftMask(clipPos, worldPosition) SoftMaskInternal(clipPos)
#endif

#endif // UI_SOFTMASK_INCLUDED
Bersaelor commented 2 years ago

yup, seeing the same issue in our project (Unity 2021.2.18f1). Are you planning a new release soon?

hung365dev commented 2 years ago

@mob-sakai Can you fix this issue ?

ManeFunction commented 2 years ago

To simplify a work for the owner, created a verified pull request based on this issue and @nabergh solution.

https://github.com/mob-sakai/SoftMaskForUGUI/pull/135

mob-sakai commented 2 years ago

Sorry for my late reply. It will be released soon. Thanks to all of you for your cooperation! :+1:

github-actions[bot] commented 2 years ago

:tada: This issue has been resolved in version 1.0.1 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: