Why is my custom shader code saying : Unexpected token 'uv'? - unity3d

I watched b3agz's making minecraft in unity tutorial on episode 15 there was an error when i coded the shade saying unexpected token 'uv' please help.
Here is my code for it:
Shader "Minecraft/Blocks"
{
Properties
{
_MainTex("Block Texture Atlas", 2D) = "white" {}
}
SubShader
{
Tags{"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
LOD 100
Lighting Off
Pass
{
CGPROGRAM
#pragma vertex vertFunction
#pragma fragment fragFunction
#pragma target 2.0
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION:
float2 uv : TEXCOORD0;
float4 color : COLOR;
};
struct v2f
{
float4 vertex : SV_POSITION:
float2 uv : TEXCOORD0;
float4 color : COLOR;
};
sampler2D _MainTex;
float GlobalLightLevel;
v2f vertFunction(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
o.color = v.color;
return o;
}
fixed4 fragFunction(v2f i) : SV_Target
{
fixed4 col = tex2D(_MainTex, i.uv);
float localLightLevel = clamp(GlobalLightLevel + i.color.a,0,1);
clip(col.a - 1);
col = lerp(col, float4(0,0,0,1), localLightLevel);
return col;
}
ENDCG
}
}
}

Both of your struct definitions, appdata and v2f have a colon in place of a semi-colon for the float4 vertex.
The correct syntax would be:
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};
struct v2f
{
float4 vertex : SV_POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};

Related

Invalid subscript in unity shader

Im pretty new to shader coding but I made this one by grouping 2 unlit shaders
When I try to make this shader, which is meant to create an outline and let me interpolate 2 textures unity tells me that there is this error: invalid subscript `vertex´ at line 61
Ive tried some things but i dont get this shader to work properly, if someone knows what do i have to do id be so thankful
Shader "Unlit/Combined"
{
Properties
{
_MainTex("Texture", 2D) = "white" {}
_SecondaryTex("Secondary Texture", 2D) = "white" {}
_LerpValue("Transition float", Range(0,1)) = 0.5
_OutlineColor("Outline color", color) = (0,0,0,1)
_OutlineWidth("Outline width", Range(1.0,5.0)) = 1.01
}
SubShader
{
Tags { "RenderType" = "Opaque" "Queue" = "Transparent"}
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;
float3 normal : NORMAL;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 outvertex : SV_POSITION;
float4 pos : POSITION;
float3 normal : NORMAL;
};
sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _SecondaryTex;
float4 _SecondaryTex_ST;
float _LerpValue;
float _OutlineWidth;
float4 _OutlineColor;
v2f vert(appdata v)
{
v2f o;
v.vertex.xyz *= _OutlineWidth;
o.outvertex = UnityObjectToClipPos(v.vertex);
o.pos = 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 = lerp(tex2D(_MainTex, i.uv),tex2D(_SecondaryTex, i.uv), _LerpValue);
return col;
return _OutlineColor;
}
ENDCG
}
Pass//Normal render
{
ZWrite On
Material
{
Diffuse[_Color]
Ambient[_Color]
}
Lighting On
SetTexture[_MainTex]
{
ConstantColor[_Color]
}
SetTexture[_MainTex]
{
Combine previous * primary DOUBLE
}
}
}
}
The line that has a problem is line 61:
v.vertex.xyz *= _OutlineWidth;
If you look at the type that v is declared as, its declared as appdata:
v2f vert(appdata v)
If you look at the definition of appdata:
struct appdata
{
//float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
};
You'll see that it does not have a vertex property, only uv and normal.
So the line that's an issue should be changed to one of those, probably normal as you're trying to modify a 3-value property of it (and uv only has xy).
v.normal.xyz *= _OutlineWidth;
Alternatively you can modify appdata to have a vertex property by uncommenteing the commented out vertex:
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float3 normal : NORMAL;
};
Or by removing line 61, depending on what you're trying to do.

Vertex shader compilation error from DX9 to DX11 (Unity 5.6 to 2017.4)

I have a Unity image post effect using a custom shader that throws an error when migrating from Unity 5.6 to Unity 2017.4
Assertion failed: Failed to create DX11 vertex declaration; something
wrong with vertex shader input data? (hr=80070057)
It appears to be a fault in this script.
Shader "SG/Stretch Shadows" {
Properties {
_MainTex ("Light texture", 2D) = "white" {}
}
SubShader {
LOD 100
Blend One Zero
Cull Off
ZWrite Off
Lighting Off
Pass { // 0 Blacken source
CGPROGRAM
#pragma target 3.0
#include "UnityCG.cginc"
#pragma vertex processVerts
#pragma fragment drawFrag
#pragma glsl_no_auto_normalization
struct vertdata {
float2 uv : TEXCOORD0;
float2 uvScaled : TEXCOORD1;
float4 vertex : POSITION;
};
struct frag_v2f {
float4 vertex : SV_POSITION;
half2 uv : TEXCOORD0;
};
uniform sampler2D _MainTex;
frag_v2f processVerts (vertdata v){
frag_v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
half4 drawFrag (frag_v2f i) : SV_Target {
fixed4 shadow = tex2D(_MainTex, i.uv);
half intensity = max(shadow.r, max(shadow.g, shadow.b));
intensity = step(intensity,0.1);
return 1-intensity;
}
ENDCG
}
Pass { // 1 Stretch
CGPROGRAM
#pragma target 3.0
#include "UnityCG.cginc"
#pragma vertex processVerts
#pragma fragment drawFrag
#pragma glsl_no_auto_normalization
struct vertdata {
float2 uv : TEXCOORD0;
float2 uvScaled : TEXCOORD1;
float4 vertex : SV_POSITION;
};
struct frag_v2f {
float4 vertex : SV_POSITION;
half2 basePos : TEXCOORD0;
half2 zoomPos : TEXCOORD1;
};
uniform sampler2D _ObstacleTex;
uniform sampler2D _MainTex;
half4 _SunPos;
#ifdef UNITY_HALF_TEXEL_OFFSET
#endif
frag_v2f processVerts (vertdata v){
frag_v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.basePos = v.uv;
o.zoomPos = v.uv * _SunPos.zw + (_SunPos.xy -_SunPos.zw*0.5);
return o;
}
half4 drawFrag (frag_v2f i) : SV_Target {
half2 basePos = i.basePos;
half2 zoomPos = i.zoomPos;
half4 tex = tex2D(_MainTex, i.basePos);
half sub = 1.0/60;
half len = length((basePos - zoomPos));
half4 col = tex*tex.a;
col = half4(0,0,0,0);
half pos = 1;
half power = 0.5;
for(int i = 0; i < 60; i++){
pos -= sub;
half4 obstacle = tex2D(_MainTex, lerp(zoomPos, basePos, pos));
obstacle *= pow(pos, power);
col = max(col, obstacle);
}
return 1-col;//half4(half3((basePos - zoomPos).x*20), 1);//tex2D(_ObstacleTex, basePos);
}
ENDCG
}
Pass { // 2 Blacken alpha
CGPROGRAM
#pragma target 3.0
#include "UnityCG.cginc"
#pragma vertex processVerts
#pragma fragment drawFrag
#pragma glsl_no_auto_normalization
struct vertdata {
float2 uv : TEXCOORD0;
float2 uvScaled : TEXCOORD1;
float4 vertex : SV_POSITION;
};
struct frag_v2f {
float4 vertex : SV_POSITION;
half2 uv : TEXCOORD0;
};
uniform sampler2D _MainTex;
frag_v2f processVerts (vertdata v){
frag_v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
return o;
}
half4 drawFrag (frag_v2f i) : SV_Target {
fixed4 shadow = tex2D(_MainTex, i.uv);
half4 intensity = half4(0,0.2,0.2,shadow.a);
intensity = lerp(shadow, intensity, shadow.a);
return intensity;
}
ENDCG
}
Pass { // 3 Draw fully zoomed shadow and half zoomed shadow
// Each pass duplicates previous pass, doubling drawn shadows
CGPROGRAM
#pragma target 3.0
#include "UnityCG.cginc"
#pragma vertex processVerts
#pragma fragment drawFrag
#pragma glsl_no_auto_normalization
struct vertdata {
float2 uv : TEXCOORD0;
float2 uvScaled : TEXCOORD1;
float4 vertex : SV_POSITION;
};
struct frag_v2f {
float4 vertex : SV_POSITION;
half2 basePos : TEXCOORD0;
half2 zoomPos : TEXCOORD1;
};
uniform sampler2D _ObstacleTex;
uniform sampler2D _MainTex;
half4 _SunPos;
half _Offset; // frational lerp value. Decrease by powers of two each pass
#ifdef UNITY_HALF_TEXEL_OFFSET
#endif
frag_v2f processVerts (vertdata v){
frag_v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.basePos = v.uv;
o.zoomPos = v.uv * _SunPos.zw + (_SunPos.xy -_SunPos.zw*0.5);
return o;
}
half4 drawFrag (frag_v2f i) : SV_Target {
half2 basePos = i.basePos;
half2 zoomPos = i.zoomPos;
half firstPass = tex2D(_MainTex, basePos).a;
half secondPass = tex2D(_MainTex, zoomPos).a-0.85;
half4 output = half4(0,0,0,max(firstPass, secondPass));
secondPass = tex2D(_MainTex, lerp(zoomPos, basePos, 0.65)).a-0.3;
output.a = max(output.a, secondPass);
secondPass = tex2D(_MainTex, lerp(zoomPos, basePos, 0.4)).a-0.45;
output.a = max(output.a, secondPass);
secondPass = tex2D(_MainTex, lerp(zoomPos, basePos, 0.25)).a-0.6;
output.a = max(output.a, secondPass);
secondPass = tex2D(_MainTex, lerp(zoomPos, basePos, 0.1)).a-0.7;
output.a = max(output.a, secondPass);
return output;//half4(half3((basePos - zoomPos).x*20), 1);//tex2D(_ObstacleTex, basePos);
}
ENDCG
}
Pass { // 4 Single pass. Ping-pong
// Each pass duplicates previous pass, doubling drawn shadows
CGPROGRAM
#pragma target 3.0
#include "UnityCG.cginc"
#pragma vertex processVerts
#pragma fragment drawFrag
#pragma glsl_no_auto_normalization
struct vertdata {
float2 uv : TEXCOORD0;
float2 uvScaled : TEXCOORD1;
float4 vertex : SV_POSITION;
};
struct frag_v2f {
float4 vertex : SV_POSITION;
half2 basePos : TEXCOORD0;
half2 zoomPos : TEXCOORD1;
};
uniform sampler2D _ObstacleTex;
uniform sampler2D _MainTex;
half4 _SunPos;
half _Offset; // frational lerp value. Decrease by powers of two each pass
#ifdef UNITY_HALF_TEXEL_OFFSET
#endif
frag_v2f processVerts (vertdata v){
frag_v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.basePos = v.uv;
o.zoomPos = v.uv * _SunPos.zw + (_SunPos.xy -_SunPos.zw*0.5);
return o;
}
half4 drawFrag (frag_v2f i) : SV_Target {
half firstPass = tex2D(_MainTex, i.basePos).a;
half secondPass = tex2D(_MainTex, lerp(i.zoomPos, i.basePos, _Offset)).a;
half4 output = half4(0,0,0,max(firstPass, secondPass));
return output;
}
ENDCG
}
}
The build tools don't provide any details as to what script or line number is at fault. Documentation on Unity post effects doesn't cover anything about specifics. Google doesn't find anyone else with the same problem. The only thing I've found is someone suggest SV_POSITION should be replaced with POSITION, which I've tried all sorts of combinations of without success.
I also created a new image effect shader in Unity to compare and the code looks the same.
What's the correct form for creating a suitable vertex shader for a post effect? Or is that even the problem with my code?
You're close! The SV_POSITION semantic is for the vertex position passed to the fragment shader.
Remove all SV_ prefixes from SV_POSITION in your vertdata structs. For example:
struct vertdata
{
float2 uv : TEXCOORD0;
float2 uvScaled : TEXCOORD1;
float4 vertex : POSITION; // <- Remove here
};
struct frag_v2f
{
float4 vertex : SV_POSITION; // <- Keep here
half2 uv : TEXCOORD0;
};

Unity shader pixel manipulation

I'm studying shaders in unity and I'm trying to achieve the below image. But I can't seem to make my code produce my target output. My end goal is to divide the whole image depending on the size of my array. Any idea how to correct my code?
Target output:
Code:Shader "Custom/PassArray"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags {"Queue"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform float4 _Test [3];
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
fixed4 frag (v2f i) : SV_Target
{
fixed4 col;
_Test[0] = fixed4(0,0,1,1);
_Test[1] = fixed4(1,0,0,1);
_Test[2] = fixed4(0,1,0,1);
//Test1: This code block produces output1 image.
int index = round(i.uv.x*_Test.Length);
col = _Test[index];
//Test2: This codeblocks outputs pure green.
//if(i.uv.x < 1/3){
// col = _Test[0];
//}
//else if(i.uv.x < 2/3){
// col = _Test[1];
//}
//else if(i.uv.x < 3/3){
// col = _Test[2];
//}
return col;
}
ENDCG
}
}
}
Actual output:
If I understood it correctly, it's giving me black pixels because of the max i.uv.x is 1. Thus making the index 3 (based on the computation i.uv.x/_Test.Length). But I don't have index 3 in my array though.
Change round to floor. Because you're rounding, values greater than 2.5 get rounded to 3. As you probably know, an array of 3 elements has no index 3, hence the black bar.
I've figured it out. Here's the updated code for anyone who may find it useful. I changed the formula from int index = round(i.uv.x_Test.Length); to int index = ceil(i.uv.x/1_Test.Length)-1;
Shader "Custom/PassArray"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
SubShader
{
Tags {"Queue"="Transparent"}
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
uniform float4 _Test [3];
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};
struct v2f
{
float2 uv : TEXCOORD0;
float4 vertex : SV_POSITION;
float4 color : COLOR;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.uv = v.uv;
return o;
}
sampler2D _MainTex;
fixed4 frag (v2f i) : SV_Target
{
fixed4 col;
_Test[0] = fixed4(0,0,1,1);
_Test[1] = fixed4(1,0,0,1);
_Test[2] = fixed4(0,1,0,1);
//Test1:
int index = ceil(i.uv.x/1*_Test.Length)-1;
col = _Test[index];
return col;
}
ENDCG
}
}
}

Error on scroll texture shader based on Alan Zucconi's book

Using unity 5.5 and Alan Zucconi's book I'm getting " incorrect number of arguments to numeric-type constructor"
shader source added as reccommended:
Shader "book/scroller"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_ScrollXSpeed ("x scroll speed", Range(0,10)) = 2
_ScrollYSpeed("Y scroll speed", Range(0,10)) = 2
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#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;
float4 _MainTex_ST;
fixed _ScrollXSpeed;
fixed _ScrollYSpeed;
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
{
fixed2 scrolledUV = i.uv;
fixed2 xScrolledValue = _ScrollXSpeed * _Time;
fixed2 yScrolledValue = _ScrollYSpeed * _Time;
scrolledUV += fixed2 (xScrolledValue, yScrolledValue);
fixed4 col = tex2D(_MainTex, scrolledUV);
return col;
}
ENDCG
}
}
}
Error shows at following line:
scrolledUV += fixed2 (xSCrolledValue, ySCrolledValue);
What is wrong with it?
Reason for the error:
You are creating fixed2-variable and giving it two fixed2 values as parameters, should be floats instead.
Here is a fixed version:
fixed xScrolledValue = _ScrollXSpeed * _Time;
fixed yScrolledValue = _ScrollYSpeed * _Time;
scrolledUV += fixed2 (xScrolledValue, yScrolledValue);

Shader error : incorrect number of arguments to numeric-type constructor - Unity3D

I was implementing a lightmap into my shader and then I got this error and I can't figure out what it means. Does any one know how I can fix this? It started happening since I added the light map in.
Shader error in 'Custom/HauntedHouseShader': incorrect number of arguments to numeric-type constructor at line 84 (on d3d11)
This is my code:
Shader "Custom/HauntedHouseShader" {
Properties {
_Texture ("Diffuse", 2D) = "white"{}
_Color ("Color", Color) = (0,0,0,1)
_TilingX ("TilingX", float) = 1
_TilingZ ("TilingZ", float) = 1
}
SubShader {
Pass{
Tags { "LightMode" = "ForwardBase"}
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
#include "UnityCG.cginc"
float4 _Color;
sampler2D _Texture;
float _TilingX;
float _TilingZ;
sampler2D unity_Lightmap;
float4 unity_LightmapST;
float4 _LightColor0;
struct VertexOutput
{
float4 pos : SV_POSITION;
float4 posWorld : TEXCOORD1;
float4 tex : TEXCOORD0;
float3 normalDir : TEXCOORD2;
float2 tex2 : TEXCOORD3;
};
struct VertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
};
struct FragmentOutput
{
float4 color : COLOR;
};
VertexOutput vert (VertexInput i)
{
VertexOutput VOUT;
VOUT.tex = i.texcoord;
VOUT.pos = mul(UNITY_MATRIX_MVP,i.vertex);
VOUT.posWorld = mul(_Object2World,i.vertex);
VOUT.normalDir = normalize( mul(float4(i.normal,0.0),_World2Object).xyz);
VOUT.tex2 = i.texcoord.xy * unity_LightmapST.xy + unity_LightmapST.zw;
return VOUT;
}
FragmentOutput frag(VertexOutput v)
{
FragmentOutput FOUT;
float3 lightDir;
float atten;
if(_WorldSpaceLightPos0.w == 0.0){
atten = 1;
lightDir = normalize(_WorldSpaceLightPos0.xyz);
}else
{
float3 fragmentToLightSource = _WorldSpaceLightPos0.xyz - v.posWorld.xyz;
float dist = length(fragmentToLightSource);
atten = 1.0/dist;
lightDir = normalize(fragmentToLightSource);
}
float3 lightMap = float3(DecodeLightmap(tex2D(unity_Lightmap, v.tex2.xy)),0.0);
float3 normalDir = v.normalDir;
float4 tex = tex2D(_Texture, float4(v.posWorld.x * _TilingX,v.posWorld.z * _TilingZ,0.0,0.0));
float3 diffuseReflection = atten * _LightColor0.xyz * saturate(dot(normalDir, lightDir));
float3 lightFinal = UNITY_LIGHTMODEL_AMBIENT.xyz + diffuseReflection;
float4 col = float4(tex.xyz * lightFinal * _Color + lightMap,0.0);
FOUT.color = col;
return FOUT;
}
ENDCG
}
Pass{
Tags { "LightMode" = "ForwardAdd"}
Blend One One
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 3.0
float4 _Color;
sampler2D _Texture;
float _TilingX;
float _TilingZ;
float4 _LightColor0;
struct VertexOutput
{
float4 pos : SV_POSITION;
float4 posWorld : TEXCOORD1;
float4 tex : TEXCOORD0;
float3 normalDir : TEXCOORD2;
};
struct VertexInput
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 tangent : TANGENT;
};
struct FragmentOutput
{
float4 color : COLOR;
};
VertexOutput vert (VertexInput i)
{
VertexOutput VOUT;
VOUT.tex = i.texcoord;
VOUT.pos = mul(UNITY_MATRIX_MVP,i.vertex);
VOUT.posWorld = mul(_Object2World,i.vertex);
VOUT.normalDir = normalize( mul(float4(i.normal,0.0),_World2Object).xyz);
return VOUT;
}
FragmentOutput frag(VertexOutput v)
{
FragmentOutput FOUT;
float3 lightDir;
float atten;
if(_WorldSpaceLightPos0.w == 0.0){
atten = 1;
lightDir = normalize(_WorldSpaceLightPos0.xyz);
}else
{
float3 fragmentToLightSource = _WorldSpaceLightPos0.xyz - v.posWorld.xyz;
float dist = length(fragmentToLightSource);
atten = 1.0/dist;
lightDir = normalize(fragmentToLightSource);
}
float3 normalDir = v.normalDir;
float4 tex = tex2D(_Texture, float4(v.posWorld.x * _TilingX,v.posWorld.z * _TilingZ,0.0,0.0));
float3 diffuseReflection = atten * _LightColor0.xyz * saturate(dot(normalDir, lightDir));
float3 lightFinal = UNITY_LIGHTMODEL_AMBIENT.xyz + diffuseReflection;
float4 col = float4(tex.xyz * lightFinal * _Color ,0.0);
FOUT.color = col;
return FOUT;
}
ENDCG
}
}
FallBack "Diffuse"
}
Well the error is from the line
float3 lightMap = float3(DecodeLightmap(tex2D(unity_Lightmap, v.tex2.xy)),0.0);
which is a clearly a typo, since here you try to construct float3 from 2 arguments float3 and float, which is meaningless. Maybe you meant:
float3 lightMap = DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, v.tex2.xy));
or
float3 lightMap = float3(DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, v.tex2.xy)).xy, 0.0);
I assume that what makes the confusion here is that error points to a wrong line number, the reason is that Unity 5 compilation makes some automatic converions of older APIs in your shader source (quite confusing), try reloading the file and see how it actually looks.