Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Kansokusha · Jan 15, 2014 at 11:15 AM · errorshadercgunity4.3

Parse error: Syntax Error in compiled shader, Unity 4.3.1 [free]

Greeting everyone.

I am trying to follow the Cg Tutorial from nvidia's developer site to get familiar with shaders, and I am also consulting the porting tips from the wiki here: [http://wiki.unity3d.com/index.php/Cg_Tutorial_to_Unity][1]

Now I am trying to re-create the shader from example "C3E5_DoubleVision". At first I tried following only the cg tutorial from nvidia's site and correcting my errors alone. When it was all ready, with no compile errors i got this one:

"Shader error in 'Custom/doubleTexture': Parse error: syntax error at line 1049"

This Error appears in the compiled shader file and the line reads:

SetTexture 0 [$_mainTex] 2D 0

I could not find what's wrong so I tried making a new shader file named test and copying the example as it was from the wiki. Same Error happens (although the compiled shader has less lines because that code doesn't #include "UnityCG.cginc" like mine does, so the error occures in line 799 of the compiled shader).

Also, if I select any of the shader file, in the inspector this message appears:

Shader has Errors or is not supported by your graphics cards.

Any Ideas why that is? My graphics card is quite new so I doubt it doesn't support some shader model... Could it have something to do with vertex/fragment profiles mentioned in the cg tutorial? and If so what can i do in unity to set a profile? Or could it be sometihng else entirely?

Thank you very much in advanced.

[EDIT:] I also tried to implement the fix for older GPUs, using two texture units instead of one (in case my gpu did not indeed support the shader), from Cg tutorial as seen in:

Example 3-7. The C3E7f_twoTextures Fragment Program

([http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter03.html][2]) but I get the same problem. [EDIT2] I tried to implement other shaders too, and it seems the problem is produced every time by a call to: float4 tex2D(sampler2D samp, float2 s) and in the compiled shader this errors in the "d3d11" subprogram block. (i.e. I tried adding #pragma only_renderers d3d9 and it compiled but the shader did not behave as it should). [1]: http://wiki.unity3d.com/index.php/Cg_Tutorial_to_Unity [2]: http://http.developer.nvidia.com/CgTutorial/cg_tutorial_chapter03.html
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tanoshimi · Jan 16, 2014 at 07:21 AM 0
Share

"Shader has Errors or is not supported by your graphics cards." is the generic error that just means you've got an error in your shader. Please post the source code you're trying to compile and we might be able to spot the problem.

avatar image Kansokusha · Jan 16, 2014 at 07:36 AM 0
Share

It is the code exactly as it appears in the wiki here: Shader C3E6 : two textures double vision

I have tried writing other shaders too, trying not to get stuck with it, and it seems that everytime i try to use

 tex2D(decal, texCoords);

It produces an error. Which is weird because earlier I had tried a shader (This one) and it had worked. Now it doesn't. And I can't figure out what changed.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by tanoshimi · Jan 16, 2014 at 09:05 AM

The code on that wiki page looks incomplete/wrong. Try this instead:

 Shader "Custom/C3E5_DoubleVision"
 {
     Properties
     {
         _MainTex ("Diffuse", 2D) = "white" {}
         _leftSeparation ("Left Separation", Vector) = (-0.5,0,0,0)
         _rightSeparation ("Right Separation", Vector) = (0.5,0,0,0)
         _lerpValue ("Linear Interpolation Value", Float) = 0.5
     }
     SubShader 
     {
         Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
 
             uniform float2 _leftSeparation;
             uniform float2 _rightSeparation;
             uniform sampler2D _MainTex;
             uniform float _lerpValue;
 
             struct a2v {
                 float2 pos : POSITION;
                 float2 texCoord : TEXCOORD0;
             };
 
             struct v2f {
                 float4 oPos : SV_POSITION;
                 float2 leftTexCoord : TEXCOORD0;
                 float2 rightTexCoord : TEXCOORD1;
             };
 
             v2f vert(a2v IN)    
             {
                 v2f o;
                 o.oPos = float4(IN.pos, 0, 1);
                 o.leftTexCoord = IN.texCoord + _leftSeparation;
                 o.rightTexCoord = IN.texCoord + _rightSeparation;
                 return o;
  
             }
             float4 frag(v2f IN) : COLOR
             {
                 float4 leftColor = tex2D(_MainTex, IN.leftTexCoord);
                 float4 rightColor = tex2D(_MainTex, IN.rightTexCoord);
                 return lerp(leftColor, rightColor, _lerpValue);
             }
  
         ENDCG
         }
     }    
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kansokusha · Jan 16, 2014 at 09:21 AM 0
Share

This works Fine. Thank you very much.

But could you care to explain to me what the problem was? It seems to me the only difference is that you are using "struct" for input-output values ins$$anonymous$$d of "out" parameters in the functions. Does cause that problem somehow? Because anycode I have written with "out" but not using tex2D was ok...

avatar image Kansokusha · Jan 16, 2014 at 09:28 AM 0
Share

Hmmmm compiling both you code and the code form the wiki, i get this difference in the compiled shader:

(old wiki code) SubProgram "d3d11 " { $$anonymous$$eywords { } ConstBuffer "$Params" 16 // 4 used size, 1 vars Float 0 [_lerpValue] BindCB "$Params" 0 SetTexture 0 [$_$$anonymous$$ainTex] 2D 0 ...blah blah..}

(your code) SubProgram "d3d11 " { $$anonymous$$eywords { } ConstBuffer "$Globals" 32 // 20 used size, 3 vars Float 16 [_lerpValue] BindCB "$Globals" 0 SetTexture 0 [_$$anonymous$$ainTex] 2D 0 ...blah blah..}

$$anonymous$$aybe the error was because of [_lerpValue] being declared as Float 0 in the old code or the Constbuffer... but why could this be?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Shader compiler: internal error compiling shader snippet type=0 platform=0: 1 Answer

CG shader is treated as GLSL and doesn't compile 0 Answers

How to render a Cube using Shaders? 0 Answers

cross product in cg shader - error "can't find __getVectorIndex" 1 Answer

How to force the compilation of a shader in Unity? 5 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges