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
1
Question by dsilvavini · Apr 30, 2013 at 03:25 PM · shadercompile

Why this shader compilation results in parse error?

I'm trying to write a shader to simulate the old film effect. My problem is whatever I write results in the same compilation error: "GLSL vertex shader: X: ERROR: '(' : syntax error parse error at line 11". I have commented the major part of the code to ensure a minimal shader to compile, but the error persists.

 Shader "Custom/OldFilm"
 {
     Properties
     {
         _MainTex ("Base (RGB)", 2D) = "white" {}
     }
     SubShader
     {
     Pass
         {
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
             
             #include "UnityCG.cginc"
             
             struct v2f {
                 float4 pos : POSITION;
                 float2 uv : TEXCOORD0;
             };
             
             v2f vert (appdata_img v)
             {
                 v2f o;
                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                 o.uv = v.texcoord.xy;
                 return o;
             }
             
 //            float2 ImageSize;
 //            float2 TexelSize;
 //            float4 Colour;
 //            sampler2D _MainTex;
 //            
 //            float SepiaValue;
 //            float NoiseValue;
 //            float ScratchValue;
 //            float InnerVignetting;
 //            float OuterVignetting;
 //            float RandomValue;
 //            float TimeLapse;
 //            
 //            float3 Overlay (float3 src, float3 dst)
 //            {
 //                // if (dst <= delta) then: 2 * src * dst
 //                // if (dst > delta) then: 1 - 2 * (1 - dst) * (1 - src)
 //                return float3((dst.x <= 0.5) ? (2.0 * src.x * dst.x) : (1.0 - 2.0 * (1.0 - dst.x) * (1.0 - src.x)),
 //                            (dst.y <= 0.5) ? (2.0 * src.y * dst.y) : (1.0 - 2.0 * (1.0 - dst.y) * (1.0 - src.y)),
 //                            (dst.z <= 0.5) ? (2.0 * src.z * dst.z) : (1.0 - 2.0 * (1.0 - dst.z) * (1.0 - src.z)));
 //            }
 //            
 //                        /// <summary>
 //            /// 2D Noise by Ian McEwan, Ashima Arts.
 //            /// <summary>
 //            float3 mod289(float3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
 //            float2 mod289(float2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
 //            float3 permute(float3 x) { return mod289(((x*34.0)+1.0)*x); }
 //            
 //            float snoise (float2 v)
 //            {
 //                const float4 C = float4(0.211324865405187,  // (3.0-sqrt(3.0))/6.0
 //                                    0.366025403784439,  // 0.5*(sqrt(3.0)-1.0)
 //                                    -0.577350269189626, // -1.0 + 2.0 * C.x
 //                                    0.024390243902439); // 1.0 / 41.0
 //            
 //                // First corner
 //                float2 i  = floor(v + dot(v, C.yy) );
 //                float2 x0 = v -   i + dot(i, C.xx);
 //            
 //                // Other corners
 //                float2 i1;
 //                i1 = (x0.x > x0.y) ? float2(1.0, 0.0) : float2(0.0, 1.0);
 //                float4 x12 = x0.xyxy + C.xxzz;
 //                x12.xy -= i1;
 //            
 //                // Permutations
 //                i = mod289(i); // Avoid truncation effects in permutation
 //                float3 p = permute( permute( i.y + float3(0.0, i1.y, 1.0 ))
 //                    + i.x + float3(0.0, i1.x, 1.0 ));
 //            
 //                float3 m = max(0.5 - float3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
 //                m = m*m ;
 //                m = m*m ;
 //            
 //                // Gradients: 41 points uniformly over a line, mapped onto a diamond.
 //                // The ring size 17*17 = 289 is close to a multiple of 41 (41*7 = 287)
 //            
 //                float3 x = 2.0 * frac(p * C.www) - 1.0;
 //                float3 h = abs(x) - 0.5;
 //                float3 ox = floor(x + 0.5);
 //                float3 a0 = x - ox;
 //            
 //                // Normalise gradients implicitly by scaling m
 //                // Approximation of: m *= inversesqrt( a0*a0 + h*h );
 //                m *= 1.79284291400159 - 0.85373472095314 * ( a0*a0 + h*h );
 //            
 //                // Compute final noise value at P
 //                float3 g;
 //                g.x  = a0.x  * x0.x  + h.x  * x0.y;
 //                g.yz = a0.yz * x12.xz + h.yz * x12.yw;
 //                return 130.0 * dot(m, g);
 //            }
     
             float4 frag : COLOR(v2f v)
             {
 //                // Sepia RGB value
 //                float3 sepia = float3(112.0 / 255.0, 66.0 / 255.0, 20.0 / 255.0);
 //            
 //                // Step 1: Convert to grayscale
 //                float2 vUv = v.uv;
 //                float3 colour = texture2D(_MainTex, v.uv).xyz;
 //                float gray = (colour.x + colour.y + colour.z) / 3.0;
 //                float3 grayscale = float3(gray);
 //                
 //                // Step 2: Appy sepia overlay
 //                float3 finalColour = Overlay(sepia, grayscale);
 //                
 //                // Step 3: Lerp final sepia colour
 //                finalColour = grayscale + SepiaValue * (finalColour - grayscale);
 //                
 //                // Step 4: Add noise
 //                float noise = snoise(vUv * float2(1024.0 + RandomValue * 512.0, 1024.0 + RandomValue * 512.0)) * 0.5;
 //                finalColour += noise * NoiseValue;
 //                
 //                // Optionally add noise as an overlay, simulating ISO on the camera
 //                //vec3 noiseOverlay = Overlay(finalColour, vec3(noise));
 //                //finalColour = finalColour + NoiseValue * (finalColour - noiseOverlay);
 //                
 //                // Step 5: Apply scratches
 //                if ( RandomValue < ScratchValue )
 //                {
 //                    // Pick a random spot to show scratches
 //                    float dist = 1.0 / ScratchValue;
 //                    float d = distance(vUv, float2(RandomValue * dist, RandomValue * dist));
 //                    if ( d < 0.4 )
 //                    {
 //                        // Generate the scratch
 //                        float xPeriod = 8.0;
 //                        float yPeriod = 1.0;
 //                        float pi = 3.141592;
 //                        float phase = TimeLapse;
 //                        float turbulence = snoise(vUv * 2.5);
 //                        float vScratch = 0.5 + (sin(((vUv.x * xPeriod + vUv.y * yPeriod + turbulence)) * pi + phase) * 0.5);
 //                        vScratch = clamp((vScratch * 10000.0) + 0.35, 0.0, 1.0);
 //            
 //                        finalColour.xyz *= vScratch;
 //                    }
 //                }
 //                
 //                // Step 6: Apply vignetting
 //                // Max distance from centre to corner is ~0.7. Scale that to 1.0.
 //                float d = distance(float2(0.5, 0.5), vUv) * 1.414213;
 //                float vignetting = clamp((OuterVignetting - d) / (OuterVignetting - InnerVignetting), 0.0, 1.0);
 //                finalColour.xyz *= vignetting;
 //                
 //                // Apply colour
 //                return float4(finalColour , 1.0);
                 return float4(1.0 , 1.0 , 1.0 , 1.0);
             }
             ENDCG
         }
     } 
     FallBack "Diffuse"
 }

That's the compiled shader:

 Shader "Custom/OldFilm"
 {
     Properties
     {
         _MainTex ("Base (RGB)", 2D) = "white" {}
     }
     SubShader
     {
     Pass
         {
             // shader program with errors was here
 Program "err" { SubProgram { "!!error" } }
 
 #LINE 160
 
         }
     } 
     FallBack "Diffuse"
 }
Comment
Add comment
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

1 Reply

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

Answer by whydoidoit · Apr 30, 2013 at 03:48 PM

Try

 float4 frag( v2f v ) : COLOR
Comment
Add comment · Show 1 · 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 dsilvavini · Apr 30, 2013 at 04:00 PM 0
Share

That's solved. Thanks!

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

13 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

Related Questions

anything obvious wrong with my multi_compile? 2 Answers

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

Building a Unity 5 Standard Material at runtime 3 Answers

Why does unity take so long to compile shader? 0 Answers

Shader compile error on } 1 Answer


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