What is wrong with my shader? Lossing detail in the distance

Hi all,

I wrote a very simple shader for prototyping a game. The goal is to swap the color of a car on the fly without editing texture every time.

It is achieved by a color exclude map that told shader when to use the alternate color.

You can notice that the model starts to lose detail when the camera moves away, which did not happen when there is no exclude map applied.

Here is my code:

void surf (Input IN, inout SurfaceOutputStandard o)
        {
            // Albedo comes from a texture tinted by color
            fixed4 exclude = tex2D(_ExcludeTex, IN.uv_MainTex);
            fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
            if(exclude.r>0){
                c.rgb = _AlterColor.rgb;
            }
          
            o.Albedo = c.rgb;
            // Metallic and smoothness come from slider variables
            o.Metallic = _Metallic;
            o.Smoothness = _Glossiness;
            o.Alpha = c.a;
        }

Can someone help me out, please?

Because your exclude texture is showing a smaller mip map as you get further away, and you’ve got your shader code setup to check for anything over 0, which is going to eventually expand to the entire texture as the mip gets smaller.

You can try using > 0.5, but you’ll get some color fringing. The best solution would be something like this:

1 Like

Wow, your blog is really eye-opening!

In the blog, you also mentioned the bright fringes issue, which is super helpful!

Thank you for the amazing blog!