Object invisible - Shader compiler warning

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?

Shader "MyProject/Interpolated" {
    Properties {
        _FirstTex ("Image (RGB) Transparency (A) - First", 2D) = "white" {}
        _SecondTex ("Image (RGB) Transparency (A) - Second", 2D) = "white" {}
        _t ("Interpolation Coefficient (t)", Range(0,1)) = 0.5
    }
    SubShader {
        Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
        LOD 200
CGPROGRAM
#pragma surface surf Lambert alpha
        float _t;
        sampler2D _FirstTex, _SecondTex;
        
        struct Input {
            float2 uv;
        };
    
        void surf (Input IN, inout SurfaceOutput o) {
            fixed4 c = tex2D(_FirstTex, IN.uv) * (1.0 - _t);
            c += tex2D(_SecondTex, IN.uv) * _t;
            o.Emission = c.rgb;
            o.Alpha = c.a;
        }
ENDCG
    }
    Fallback "Transparent/Cutout/VertexLit"
}

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

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…)

The Fallback shouldn’t be the problem, since all my other shaders have that too. Could it be connected to surface shaders somehow?

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.

1 Like

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.

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.