Arvtesh / UnityFx.Outline

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

Alpha Testing not working #63

Closed CaseyHofland closed 1 year ago

CaseyHofland commented 1 year ago

Possibly related to #59

Alpha testing does nothing and is seemingly always enabled with a cutoff value of 1. The only cause I can think of is that OutlineColor.URP has a shader error saying invalid subscript 'uv'.

It's about this line of code

half4 FragmentAlphaTest(Varyings input) : SV_Target
{
    half4 c = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv); // error occurs here
    clip(c.a - _Cutoff);
    return 1;
}

Which is... stupid, why would Varyings not have uv, it has always had uv!? Am I crazy?!

Not sure what to do yet, Varyings is taken from #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" and it will have to be investigated.

Arvtesh commented 1 year ago

Unfortunately I don't have time to investigate this right now. If you find the solution, please share it.

CaseyHofland commented 1 year ago

Could you explain more about what OutlineColor.URP does? I'm getting really confused.

The above code throws an error, and when it does, the outline works as expected.

But when I fix the error by providing my own Varyings implementation (from URP Drawing a Texture) the outline doesn't show up.

Even when I do this:

half4 FragmentAlphaTest(Varyings input) : SV_Target
{
    //half4 c = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.uv); // error occurs here
    //clip(c.a - _Cutoff);
    return 1;
}

Still nothing. How can a shader only work when it doesn't work?

CaseyHofland commented 1 year ago

So a quick update (I really try to keep all my projects error free so I couldn't help it)

The new ShaderAPI uses input.texcoord (not sure when this was changed)

half4 FragmentAlphaTest(Varyings input) : SV_Target
{
    half4 c = SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, input.texcoord);
    clip(c.a - _Cutoff);
    return 1;
}

New code, no errors. But again, when you don't get errors in this shader outlines disappear. Could you perhaps share an insight into why this happens so I may investigate it?

Ciubix8513 commented 1 year ago

I managed to fix this issue in my project with the following steps:

  1. Create a new Outline Resources file
  2. Create a blank shader graph URP unlit shader
  3. Set Render shader in the created resources file to the created shader
  4. Set Outline shader to Outline.URP
  5. Set Outline resources of all Outline feature render features in the Universal Renderer Data to the created resources file
CaseyHofland commented 1 year ago

Works perfectly! Instead of making a shader graph I just used the URP Unlit shader which works as well. Thanks for the fix!

CaseyHofland commented 1 year ago

@Arvtesh I'd love to create another, very simple, PR for this, but you haven't accepted my first one yet. Like I said before, I really like this outline implementation and I hope you'll find the time to approve them so that it stays supported for everyone.