Syntax error at line 1

Shader error in ‘’: Parse error: syntax error at line 1

I am creating a combination of DiffuseDetail and Specular shaders.
I made it in 2.6 and looking at the new stuff I figured it would be easy.

All I did was copy the Diffuse Detail code into a new file.
I changed the name on line one, but even with the exact copy of the old file I still get this error.

I shut down the programs and restarted several times.
I could post code but really its just this line.

Shader "Diffuse Detail Spec" {
Properties {
	_Color ("Main Color", Color) = (1,1,1,1)
	_MainTex ("Base (RGB)", 2D) = "white" {}
	_Detail ("Detail (RGB)", 2D) = "gray" {}
}

SubShader {
	Tags { "RenderType"="Opaque" }
	LOD 250
	
CGPROGRAM
#pragma surface surf Lambert

sampler2D _MainTex;
sampler2D _Detail;
float4 _Color;

struct Input {
	float2 uv_MainTex;
	float2 uv_Detail;
};

void surf (Input IN, inout SurfaceOutput o) {
	half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
	c.rgb *= tex2D(_Detail,IN.uv_Detail).rgb*2;
	o.Albedo = c.rgb;
	o.Alpha = c.a;
}
ENDCG
}

Fallback "Diffuse"
}

The remaining lines are just the same as in the original. I havent even started editing yet.

The shader compiles and I can open it. The line looks normal to me.
The shader does not show up in the list when you try to assign it to a material.
I wrote it in Visual C#2008.
I started it as a new text file.

I’ve copied and pasted the code you’ve posted (on a Mac) and didn’t get any errors. Could the issue be with line endings or other invisible characters in the original code?

I know its not the code, its something weird. I’ll check what you mentioned.

I do sometimes have a pop up about having a mix of line endings. But not while working on these. VS2008 does the opposite of the built in text editor I think. I have one more thing to try. I was going to try cutting the Unity source files into Notepad, and see how that works.

I’ve made multiple shader files in VS and they were all broken like this.
In 2.6 I never had a problem.

Have to do some regular work first :slight_smile:

I had this same kind of problem when trying to learn Cg. It made no sense; I fixed line endings, and ran automated checks for differences which turned up no results. This was in Unity iPhone so it’s definitely not a new 3.0 issue.

I’ve never had this kind of issue with fixed function ShaderLab, though.

I just had a few minutes and cut the code into Notepad… and it worked just fine.
I then put the same code into VS2008 and it was broken. It compiles, but shows that error and wont display on the list of shaders.

Tonight I’ll poke around some more. Looks like I just wont be able to edit them in VS, no big deal.

Looks like I will be using UniSciTE to edit shaders.
It just doesnt work in VS2008 express.

Please can you file a bug report for this (menu: Help > Report A Bug)? If possible, please attach one of the shader files that causes the problem.

Ok

Its not really the code though.
It only messes up when I save in VS2008 express

It can’t just be VS, because I’ve never used it, and as I said, I had the same problem.

Reported
378899

This gets weirder.

I was making up some new files to send along and I found that the way I make the file made a difference.

  1. If I open the Unity source file for a builtin shader in VC# 2008 then edited that file, save as, then Unity 3 will compile and it works.

2 If I cut and paste into a new empty editor window it wont work.
VC#2008, right click on a folder in the project, Add>NewItem>TextFile (also Class file breaks), create it with a new name File.shader.
Paste the code into it, add a number into the string on line one so its unique, save, click on Unity3 window, watch it fail. It will compile, you can see the compiled code looks fine.

I know how stupid this sounds, but I repeated the steps several times.

Crap, I was going to reference this thread in the bug report. Phone call interrupted my thinking.

This is broken
http://dl.dropbox.com/u/10454876/Bugs/VC2008.shader

This works
http://dl.dropbox.com/u/10454876/Bugs/VC2008_works.shader

Cutting and pasting into NotePad works.

edit:
Win7, i7-920, radeon 5870

Ok I solved it :slight_smile:

Copying to the clipboard, pasting into VC#2008, save, creates a UTF-8 format file.
Pasting into Notepad, NotePad++, UniSci, creates a ANSI format file.

Unity 3 doesnt like getting a UTF-8 format SurfaceShader file.

I downloaded NotePad++ just now and it displays the Encoding at the bottom of the window.
I had two windows open, one good file and one bad, looking for hidden characters when I spotted the encoding formats.

I converted the UTF-8 file to ANSI and it worked.

From MSDN
“The only character set supported by the clipboard is Unicode in its UTF-8 encoding.”
So some editors will convert this to ANSI and others like VC# will keep the UTF-8.

Most of my C# code files are UTF-8 because I copy/paste the header information into the blank file. These files work fine.

Should Unity3 be able to use UTF-8 files for Surface Shaders?

(sent bug update and link to this post)

Visual Studio’s advanced save options:

1093688--41082--$1.PNG
Parse error: syntax error at line 1

1093688--41083--$2.PNG
Great success.

3 Likes

I just had this error again and couldnt remember the cause, it was so long ago :slight_smile:
Looks like The Unity 4 shader system still doesnt like this.
So after 30 min. I checked here.

Thanks alexzzzz that works great!

I found the same error in Unity5 on my Win7 x64 System.It seems like that Unity doesn’t like CR Line Endings,you should change it into CR+LF or LF,both is OK.
In MonoDevelop,just change it in your Project-Solution,Code Formatting,ShaderLab shader,I change the Line endings to Microsoft Windows,and it works.

I got the same error when do meshMaterial = new Material("Diffuse");, which should be meshMaterial = new Material(Shader.Find("Diffuse"));

Unity should improve the error message here.