Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Object invisible - Shader compiler warning

Discussion in 'Shaders' started by R-Type, Mar 29, 2013.

  1. R-Type

    R-Type

    Joined:
    Oct 31, 2012
    Posts:
    44
    I have the following simple shader, which worked perfectly earlier. I don't know, since when it stopped rendering my objects, as I have not used it since a while, because I am working on other variants, which are much more complex, but based on this one. They all work well, as expected.

    I have absolutelly no idea, what the errors mean and if they are the cause for my objects being invisible during play. The properties are set correctly during play, as can be observed in the inspector. The preview is empty as well.

    The line number 27 is not related to the source code, as it keeps unchanged when inserting more lines. I'm working in Win7, Unity Pro 4.0.1f2.

    Any suggestions?

    Code (csharp):
    1.  
    2. Shader "MyProject/Interpolated" {
    3.     Properties {
    4.         _FirstTex ("Image (RGB) Transparency (A) - First", 2D) = "white" {}
    5.         _SecondTex ("Image (RGB) Transparency (A) - Second", 2D) = "white" {}
    6.         _t ("Interpolation Coefficient (t)", Range(0,1)) = 0.5
    7.     }
    8.     SubShader {
    9.         Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
    10.         LOD 200
    11. CGPROGRAM
    12. #pragma surface surf Lambert alpha
    13.         float _t;
    14.         sampler2D _FirstTex, _SecondTex;
    15.        
    16.         struct Input {
    17.             float2 uv;
    18.         };
    19.    
    20.         void surf (Input IN, inout SurfaceOutput o) {
    21.             fixed4 c = tex2D(_FirstTex, IN.uv) * (1.0 - _t);
    22.             c += tex2D(_SecondTex, IN.uv) * _t;
    23.             o.Emission = c.rgb;
    24.             o.Alpha = c.a;
    25.         }
    26. ENDCG
    27.     }
    28.     Fallback "Transparent/Cutout/VertexLit"
    29. }
    30.  
    Compilation gives the following warnings:

    Shader warning in 'Lightfield/Interpolated': Program 'vert_surf', not enough actual parameters for macro 'TRANSFORM_TEX' (compiling for d3d11) at line 27
    Shader warning in 'Lightfield/Interpolated': Program 'vert_surf', not enough actual parameters for macro 'TRANSFORM_TEX' (compiling for d3d11_9x) at line 27
    Shader warning in 'Lightfield/Interpolated': Program 'vert_surf', undeclared identifier 'TRANSFORM_TEX' (compiling for d3d11) at line 27
    Shader warning in 'Lightfield/Interpolated': Program 'vert_surf', undeclared identifier 'TRANSFORM_TEX' (compiling for d3d11_9x) at line 27
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    9,493
    Does the error go away if you disable dx11 mode?

    Or if you comment out the fallback line?
    (since that shader seems to have those TRANSFORM_TEX() lines..)
     
  3. R-Type

    R-Type

    Joined:
    Oct 31, 2012
    Posts:
    44
    The Fallback shouldn't be the problem, since all my other shaders have that too. Could it be connected to surface shaders somehow?
     
  4. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    Is it perhaps having trouble with the name you're using for the uvs (or rather: the lack of a texture name)? Try using uv_FirstTex in stead of uv.
     
    zwcloud likes this.
  5. R-Type

    R-Type

    Joined:
    Oct 31, 2012
    Posts:
    44
    That helped! Thanks a lot! It realy was the need of uv_FirstTex.

    However, I don't really understand why this is. Is it related to Surface Shaders? In other shaders, where I have Vertex and Fragment programs, it doesn't matter, how my uvs are named.
     
  6. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    639
    As far as I know, the vertex shader created by your surface shader, will try to scale and bias the uv coordinates for the entries in your Input struct that contain the string 'uv', using the TRANSFORM_TEX defined in UnityCG.cginc.

    TRANSFORM_TEX requires the name of the texture, for example '_SomeTexture', so that it can find '_SomeTexture_ST', which is automatically filled by Unity with the scale and bias information for that texture from the material inspector.

    So I think that to get information about the correct texture, the surface shader 'compiler' script will remove 'uv' from the name of the texture coordinate struct member, to get the name of the texture whose scale and bias should be applied.


    [Edit]The line numbers of compiler warnings seem to refer to a version of the resulting fragment and vertex shader that we don't see.
     
    Last edited: Mar 30, 2013