Search Unity

Shader Initialization Error

Discussion in 'Scripting' started by QuinnDP, May 18, 2017.

  1. QuinnDP

    QuinnDP

    Joined:
    Dec 12, 2016
    Posts:
    22
    I'm relatively new to the topic of Unity shaders, and have hit a problem with initialization (I believe because Unity is using DirectX11)..

    The error is "Shader Warning: Output Value 'vert' is not completely initailized on line 46 (on d3d11)" ( https://puu.sh/vTPsU/e1119ad1ec.png ), and here's a copy of the code. If anyone could help me out, I'd greatly appreciate it.

    Code (CSharp):
    1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
    2.  
    3. Shader "Custom/FresnelTextureEffect" {
    4.  
    5. Properties{
    6.     _MainTex("Main Texture", 2D) = "white" {}
    7.     _Colour("Main Colour", Color) = (1,1,1,1)
    8.     _SpecColour("Specular Colour", Color) = (1,1,1,1)
    9.     _SpecShininess("Specular Shininess", Range(1.0, 100.0)) = 2.0
    10.     _FresnelPower("Fresnel Power", Range(0.0, 3.0)) = 1.4
    11.     _FresnelScale("Fresnel Scale", Range(0.0, 1.0)) = 1.0
    12.     _FresnelColour("Fresnel Colour", Color) = (1,1,1,1)
    13. }
    14.  
    15. SubShader {
    16.     Pass {
    17.         Tags {"LightMode" = "ForwardBase"}
    18.         CGPROGRAM
    19.             #pragma vertex vert
    20.             #pragma fragment frag
    21.            
    22.             #include "UnityCG.cginc"
    23.            
    24.             struct appdata {
    25.                 float4 vertex : POSITION;
    26.                 float3 normal : NORMAL;
    27.                 float2 texcoord : TEXCOORD0;
    28.             };
    29.            
    30.             struct v2f {
    31.                 float4 pos : SV_POSITION;
    32.                 float3 normal: NORMAL;
    33.                 float2 texcoord : TEXCOORD0;
    34.                 float4 posWorld : TEXCOORD1;
    35.             };
    36.  
    37.             float4 _LightColour0;
    38.  
    39.             float4 _Colour;
    40.             sampler2D _MainTex;
    41.             float4 _MainTex_ST;
    42.  
    43.             float4 _SpecColour;
    44.             float _SpecShininess;
    45.  
    46.             v2f vert(appdata IN) {
    47.                 v2f OUT;
    48.                 OUT.pos = mul(UNITY_MATRIX_MVP, IN.vertex);
    49.                 OUT.posWorld = mul(unity_ObjectToWorld, IN.vertex);
    50.                 OUT.normal - mul(float4(IN.normal, 0.0), unity_ObjectToWorld).xyz;
    51.                 OUT.texcoord = TRANSFORM_TEX(IN.texcoord, _MainTex);
    52.                 return OUT;
    53.             }
    54.  
    55.             float4 frag(v2f IN) : COLOR {
    56.                 float4 texColour = tex2D(_MainTex, IN.texcoord);
    57.                
    58.                 float3 normalDirection = normalize(IN.normal);
    59.                 float3 lightDirection = normalize(_WorldSpaceLightPos0.xyz);
    60.                 float3 viewDirection = normalize(_WorldSpaceCameraPos - IN.posWorld.xyz);
    61.                 float3 diffuse = _LightColour0.rgb * _Colour.rgb * max(0.0, dot(normalDirection, lightDirection));
    62.  
    63.                 float3 specular;
    64.                 if (dot(normalDirection, lightDirection) < 0.0) { specular = float3(0.0, 0.0, 0.0); }
    65.                 else {
    66.                     specular = _LightColour0.rgb * _SpecColour.rgb * pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), _SpecShininess);
    67.                 }
    68.  
    69.                 float3 diffuseSpecular = diffuse + specular;
    70.                 return float4(diffuseSpecular, 1) * texColour;
    71.             }
    72.  
    73.         ENDCG
    74.     }
    75. }
    76.  
    77. }