None value in Texture?

Hello,

I find some values in texture are abnormal. This is a shader which has 3 texture as input. These 3 textures’ size is same as screen’s size.

Shader "Unlit/Mix"
{
    Properties
    {
        _MainTex ("Texture", 2D) = "white" {}
        _Tex1("Texture1", 2D) = "white" {}
        _Tex2("Texture2", 2D) = "white" {}
    }
    SubShader
    {
        Tags { "RenderType"="Opaque" }
        LOD 100

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag
            // make fog work
            #pragma multi_compile_fog

            #include "UnityCG.cginc"

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

            struct v2f
            {
                float2 uv : TEXCOORD0;
                UNITY_FOG_COORDS(1)
                float4 vertex : SV_POSITION;
            };

            sampler2D _MainTex;
            sampler2D _Tex1;
            sampler2D _Tex2;
            float4 _MainTex_ST;

            v2f vert (appdata v)
            {
                v2f o;
                o.vertex = UnityObjectToClipPos(v.vertex);
                o.uv = TRANSFORM_TEX(v.uv, _MainTex);
                UNITY_TRANSFER_FOG(o,o.vertex);
                return o;
            }

            fixed4 frag (v2f i) : SV_Target
            {
                // sample the texture
                fixed4 col_Sn = tex2D(_Tex1, i.uv);
                fixed4 col_Un = tex2D(_Tex2, i.uv);
                fixed4 col_U = tex2D(_MainTex, i.uv);
                return col_Un + 0.5;
            }
            ENDCG
        }
    }
}

And the final image is one of texture color + 0.5 in each channel, which means the image is at least (0.5,0.5,0.5). However, look at the result:


Why do some picels still black? Only the pixels on the ground are added (0.5,0.5,0.5). It seems some values are “None”.

If you’re using floating point render textures, they’re floating point values, which means they can be infinity, negative infinity, and most importantly NaN.

NaN shows up in shaders more often than one might think. The most common cause it’s trying to get the square root of zero, usually as part of normalizing a zero length vector.

normize(float3(0,0,0)) == NaN

Thank you very much. I see.