tex2Dlod and anisotropic filtering

Hello! I would like to know is it normal that anisitropic fitering affects on mip selection by tex2Dlod?
If I turn off AF lod selection is linear, but if AF enabled mips changed not linear.
I use tex2Dlod for glossy reflections and AF does banding artifacts;

AF off

Generally it’s expected that using tex2Dlod disables anisotropic filtering entirely as derivatives aren’t guaranteed to be valid, so a direction for the anisotropic filtering to use won’t be available.

However, anisotropic filtering also enables trilinear filtering as it is an extension of the later. It’s possible that when you disable anisotropic filtering your cubemap is using bilinear filtering?

Anisotropic filtering on cubemaps is also a special case that functions a little differently. Almost every GPU architecture acts a little differently on how they’re handled, even among the same manufacturer. So it’s also possible there’s just a straight up bug here on the drivers or GPU itself.

Hello! This is not a cube map this is a simple 2d texture. We generate ktx texture external. And trilinear filtering is always on.
I just curions is it Unity bag or normal behavior in 3d grahpics.

Aslo on android (gles 3) behavior is the same.

P.S. I realize this is happen only with external textures!

My experience with tex2Dlod and anisotropic filtering has always been that there wasn’t any difference between Trilinear and Anisotropic, but I also didn’t look that closely. Only enough to see that anisotropic filtering was no longer working at glancing angles where it is supposed to help.

I might suggest using RenderDoc to see what the difference between the Unity texture and the external texture is.

I don’t know what to look for.
Unity’s texture have linear filter state
3920113--334492--upload_2018-11-23_12-59-26.png

External have anisotropic filter state
3920113--334495--upload_2018-11-23_13-0-55.png

P.S. I think I should submit a bug to Unity.

That’s a Unity texture with anisotropic turned on? I wouldn’t expect Unity to be smart about disabling it, but maybe it does.

Anisotropic is forced on.

I tested this and can confirm what you’re seeing that a texture with anisotropic filtering does look different than trilinear filtering when using tex2Dlod. I would say it’s probably “working as intended” in that anisotropic filtering on GPUs don’t use the technique as described by the original specification for anisotropic filtering, but one of several published and/or proprietary approximations. Thus it’s not too surprising that using tex2Dlod will not necessarily produce identical results between trilinear and anisotropic filtering, even though the “spec” implementation of anisotropic filtering should.

In short, don’t enable anisotropic filtering on textures you intended to sample via tex2Dlod if you don’t like the way it looks. If you’re not aiming for Android or old iOS devices, maybe look at using explicit inline sampler states if you need the texture to have anisotropic filtering most of the time, but need to disable it.

Shader "Unlit/Inline Sampler Level Test"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _MipLevel ("Mip Level", Range(0,11)) = 0
    }
    SubShader
    {
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            #pragma target 3.5
           
            #include "UnityCG.cginc"

            struct appdata
            {
                float4 vertex : POSITION;
                float2 uv : TEXCOORD0;
            };

            struct v2f
            {
                float2 uv : TEXCOORD0;
                float4 vertex : SV_POSITION;
            };

            Texture2D _MainTex;
            SamplerState my_trilinear_repeat_sampler;

            float _MipLevel;
           
            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = v.uv;
                return o;
            }
           
            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 col = _MainTex.SampleLevel(my_trilinear_repeat_sampler, i.uv, _MipLevel);
                return col;
            }
            ENDCG
        }
    }
}

The above will ignore the settings on the texture and always use trilinear filtering.

Now I realize, an external texture has a hidden aniso attribute always 1, so the aniso settings influenced on mips. If set aniso to 0 then the interpolation will always be linear.

P.s.

Yeah I try it just to see that can works, but we are on mobile(
And thank you very much for the advice!