Hello,
I’m trying to implement the alpha to coverage or a solution to mitigate the alpha issues we have on low resolution screens in VR.
I’m following this logic : Anti-aliased Alpha Test: The Esoteric Alpha To Coverage | by Ben Golus | Medium
And I’m using shader graph.
We already were able to implement the shader code as is but I would like to use it with URP and with the Shader Graph so I can easily create shaders.
So far, I have created these nodes :

And I reference this hlsl script in the custom function :
void CalcMipLevel_float(out float2 texture_coord)
{
float2 dx = ddx(texture_coord);
float2 dy = ddy(texture_coord);
float delta_max_sqr = max(dot(dx, dx), dot(dy, dy));
texture_coord = max(0.0, 0.5 * log2(delta_max_sqr));
}
void CalcMipLevel_half(out half2 texture_coord)
{
half2 dx = ddx(texture_coord);
half2 dy = ddy(texture_coord);
half delta_max_sqr = max(dot(dx, dx), dot(dy, dy));
texture_coord = max(0.0, 0.5 * log2(delta_max_sqr));
}
void AlphaToCoverage_float(Texture2D _MainTex, half _Cutoff, half2 _uv, sampler2D _SS, out float4 _Color)
{
//float _MipScale = 0.25
// _Color = sampler2D(_MainTex, _uv);
//SamplerState sampler_MainTex; // "sampler" + “_MainTex”
// rescale alpha by mip level (if not using preserved coverage mip maps)
// Original : col.a *= 1 + max(0, CalcMipLevel(i.uv * _MainTex_TexelSize.zw)) * _MipScale;
//_Color.a *= 1 + max(0, CalcMipLevel_half(_uv.rg * _uv.ba)) * 0.25;
// rescale alpha by partial derivative
// Original : col.a = (col.a - _Cutoff) / max(fwidth(col.a), 0.0001) + 0.5;
//_Color.a = (_Color.a - _Cutoff) / max(fwidth(_Color.a), 0.0001) + 0.5;
//_Color =
_Color = float4 (0.0, 0.0, 0.0, 0.0);
}
void AlphaToCoverage_half(Texture2D _MainTex, half _Cutoff, half2 _uv, sampler2D _SS, out half4 _Color)
{
// #define AlphaToMask On;
// Don't know how to handle mipscale right now but here is the value it should have
//half _MipScale = 0.25;
//SamplerState sampler_MainTex;
//_Color = sampler2D(_MainTex, _uv);
_Color = SAMPLE_TEXTURE2D(_MainTex, _SS, _uv);
//_Color = _MainTex.Sample(sampler_MainTex, _uv);
//SamplerState sampler_MainTex; // "sampler" + “_MainTex”
// rescale alpha by mip level (if not using preserved coverage mip maps)
// Original : col.a *= 1 + max(0, CalcMipLevel(i.uv * _MainTex_TexelSize.zw)) * _MipScale;
//_Color.a *= 1 + max(0, CalcMipLevel_half(_uv.uv * sampler_MainTex.zw)) * _MipScale;
// rescale alpha by partial derivative
// Original : col.a = (col.a - _Cutoff) / max(fwidth(col.a), 0.0001) + 0.5;
//_Color.a = (_Color.a - _Cutoff) / max(fwidth(_Color.a), 0.0001) + 0.5;
_Color = half4 (0.0, 0.0, 0.0, 0.0);
}
As I lack hlsl & Unity general knowledge I’m kinda stuck.
I have already tested and followed a lot of conversations but I can’t get a result as I always have something blocking and I can’t be sure of everything I do.
I would be glad if someone could take a look to the code.
