输出值vert没有完全初始化

Output value vert is not completly initialized

我收到警告

Shader warning in 'Custom/NoobShader_02': Output value 'vert' is not completely initialized at line 30 (on d3d11)

使用以下代码谁能解释一下为什么要这样做?

Shader "Custom/NoobShader_02" {
    Properties {
        twisting ("Twist", Range(-10,10)) = 1
    }
    SubShader {
        Pass{
        CGPROGRAM
        #pragma vertex vert
        #pragma fragment frag

        float twisting;

        struct VertexOutput
        {
            float4 pos : SV_POSITION;
            float3 nor : NORMAL;
        };

        struct VertexInput
        {
            float4 vertex : POSITION;
            float3 normal : NORMAL;
        };

        struct FragmentOutput
        {
            float4 color : COLOR;
        };

        VertexOutput vert (VertexInput i)
        {
            VertexOutput VOUT;
            VOUT.pos = mul(UNITY_MATRIX_MVP, i.vertex);

            return VOUT;
        }

        FragmentOutput frag() 
        {
            FragmentOutput FOUT;
            float4 tempCol = {abs(_SinTime.z),0,0,1};
            FOUT.color = tempCol;
            return FOUT;
        }
        ENDCG
        }
    } 
    FallBack "Diffuse"
}

它几乎说明了发生的事情,VertexOutput VOUT; 只是变量的声明。这就像定义 MyObject o; 然后在 o 仍然为 null 时尝试使用 o.ToString();

你必须使用:

VertexOutput VOUT;
UNITY_INITIALIZE_OUTPUT(VertexOutput, VOUT);