Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Syntax Error with "Hello World" Shader

Discussion in 'Shaders' started by Jonathan Czeck, Jul 9, 2005.

  1. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    From part 1 of the shader tutorial...

    Code (csharp):
    1.  
    2. Shader "simple" {
    3.     Properties {
    4.         _Color ("Main Color", Color) = (1,.5,.5,1)
    5.     }
    6.     Pass {
    7.         Material {
    8.             Diffuse [_Color]
    9.         }
    10.         Lighting On
    11.     }
    12. }
    13.  
    Syntax error on line 5. Line five is a closing brace.

    It works like this:

    Code (csharp):
    1.  
    2. Shader "simple" {
    3.     Properties {
    4.         _Color ("Main Color", Color) = (1,.5,.5,1)
    5.     }
    6.     SubShader {
    7.         Pass {
    8.             Material {
    9.                 Diffuse [_Color]
    10.             }
    11.             Lighting On
    12.         }
    13.     }
    14. }
    15.  
    Whooops. And I thought I was the one learning ShaderLab here. ;-)

    *Waits to find out he's dead wrong anyways*

    -Jon
     
  2. FancyPants

    FancyPants

    Joined:
    Jun 30, 2005
    Posts:
    38
    The second one has the correct number of braces (don't forget that the shader itself has to be closed). Depending on where in the parsing/lexing process for the shader errors of that type are generated, it could give a bad line number (or a confusing one, anyways), or I could have counted the lines wrong.. ;)
     
  3. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    You counted the lines/braces wrong. Open up the ShaderLab tutorial and try it for yourself. The first one is missing the SubShader part.

    I think you read me incorrectly. I'm not saying I was having trouble, I was saying the tutorial was incorrect! ;)

    -Jon
     
  4. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Thanks, I fixed it in the manual -