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 kilian277 · Jul 16, 2014 at 09:40 PM · shadervertexblendingfragmentvertexcolor

Vertex color blending shader

Hi,

i'm trying to create a 3 layer terrain shader that uses the vertex colors in the mesh painted by the vertex painter modifier in 3ds max

Now i tried to make this shader but it gives me errors that doesn't make any sense to me.

So here's the shader:

 Shader "Debug/Vertex color" {
 Properties {
         _Color ("Color", Color) = (0,0,0,1)
         _Layer1 ("Layer1", 2D) = "white" {}
         _Layer2 ("Layer2", 2D) = "white" {}
         _Layer3 ("Layer3", 2D) = "white" {}
     }
 SubShader {
     Pass {
         Fog { Mode Off }
         CGPROGRAM
 
         #pragma vertex vert
         #pragma fragment frag
 
         sampler2D _Layer1;
         sampler2D _Layer2;
         sampler2D _Layer3;
         float _Color;
 
         // vertex input: position, color
         struct appdata {
             float4 vertex : POSITION;
             fixed4 color : COLOR;
         };
 
         struct v2f {
             float4 pos : SV_POSITION;
             fixed4 color : COLOR;
             float2 uv_Layer1 : TEXCOORD0;
             float2 uv_Layer2 : TEXCOORD0;
             float2 uv_Layer3 : TEXCOORD0;
         };
         
         v2f vert (appdata v) {
             v2f o;
             o.pos = mul( UNITY_MATRIX_MVP, v.vertex );
             o.color = v.color;
             return o;
         }
         
         float4 frag (v2f i) : COLOR0
         { 
             half4 l1 = tex2D (_Layer1, i.uv_Layer1);
             half4 l2 = tex2D (_Layer2, i.uv_Layer2);
             half4 l3 = tex2D (_Layer3, i.uv_Layer3);
 
             float4 out;
 
             out = (l1.rgb * i.color.r) + (l2.rgb * i.color.g) + (l3.rgb * i.color.b);
 
             return out; 
         }
         ENDCG
     }
 }
 }


and this is the error log:

 Shader error in 'Debug/Vertex color': Shader program had errors at line 12
 
 Shader error in 'Debug/Vertex color': Program 'frag', cast not allowed at line 50
 
 Shader error in 'Debug/Vertex color': Program 'frag', syntax error, unexpected '=' at token "=" at line 50
 
 Shader error in 'Debug/Vertex color': Program 'frag', type name expected at token "=" at line 50
 
 Shader error in 'Debug/Vertex color': Program 'vert', cast not allowed at line 50
 
 Shader error in 'Debug/Vertex color': Program 'vert', syntax error, unexpected '=' at token "=" at line 50
 
 Shader error in 'Debug/Vertex color': Program 'vert', type name expected at token "=" at line 50
 
 Shader error in 'Debug/Vertex color': Program 'frag', syntax error, unexpected ';' at token ";" at line 52
 
 Shader error in 'Debug/Vertex color': Program 'frag', type name expected at token ";" at line 52
 
 Shader error in 'Debug/Vertex color': Program 'vert', syntax error, unexpected ';' at token ";" at line 52
 
 Shader error in 'Debug/Vertex color': Program 'vert', type name expected at token ";" at line 52
 

I would appreciate some corrections here.

Thanks!

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
1
Best Answer

Answer by MaT227 · Jul 17, 2014 at 08:32 AM

Here you have no more errors: As @Bunny83 said the out keyword was causing the error.

 Shader "Debug/Vertex color" {
     Properties
     {
         _Color    ("Color", Color) = (0,0,0,1)
         _Layer1 ("Layer1", 2D) = "white" {}
         _Layer2 ("Layer2", 2D) = "white" {}
         _Layer3 ("Layer3", 2D) = "white" {}
     }
     SubShader
     {
         Pass
         {
             Fog { Mode Off }
             CGPROGRAM
             #pragma vertex vert
             #pragma fragment frag
              
             sampler2D    _Layer1;
             sampler2D    _Layer2;
             sampler2D    _Layer3;
             float         _Color;
             
             struct appdata
             {
                 float4 vertex : POSITION;
                 fixed4 color : COLOR;
             };
              
             struct v2f
             {
                 float4 pos : SV_POSITION;
                 fixed4 color : COLOR;
                 float2 uv_Layer1 : TEXCOORD0;
                 float2 uv_Layer2 : TEXCOORD1;
                 float2 uv_Layer3 : TEXCOORD2;
             };
              
             v2f vert (appdata v)
             {
                 v2f o;
                 o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
                 o.color = v.color;
                 return o;
             }
              
             float4 frag (v2f i) : COLOR
             {
                 half4 l1 = tex2D (_Layer1, i.uv_Layer1);
                 half4 l2 = tex2D (_Layer2, i.uv_Layer2);
                 half4 l3 = tex2D (_Layer3, i.uv_Layer3);
                  
                 float4 color = float4(1, 1, 1, 1);
                 color.rgb = (l1.rgb * i.color.r) + (l2.rgb * i.color.g) + (l3.rgb * i.color.b);
                 return color;
             }
         ENDCG
         }
     }
 }

Comment
Add comment · Show 5 · 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 kilian277 · Jul 17, 2014 at 11:10 AM 1
Share

thanks man it helped to fix the errors , but 3ds max does not correctly save the vertex colors in de fbx file so i have to look into that also , but thanks :D

avatar image MaT227 · Jul 17, 2014 at 11:21 AM 0
Share

You're welcome, there are several example of vertex color blending shaders. You should also take a look at them.

avatar image kilian277 · Jul 17, 2014 at 11:44 AM 0
Share

Also when i apply the shader only the colors are shown on the mesh , the textures are not applied to it , something weird have a look at this pic. link text

avatar image Bunny83 · Jul 17, 2014 at 11:48 AM 1
Share

@kilian277: Just in case you still don't know what the problem was: "out" is a keyword like in C#.

avatar image kilian277 · Jul 17, 2014 at 01:15 PM 0
Share

@Bunny83: oh i didn't know that , anyways the texturing per vertex color is now working so everyone thanks for the input !

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

23 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 avatar image avatar image avatar image avatar image

Related Questions

how can i catch the sky box and do a reflection in object 0 Answers

Why does my shader only shade objects based on their normals in the X axis? 1 Answer

Problem with texture blending and vertex color shader for iOS 1 Answer

Additive shader visible in viewport but not in-game 3 Answers

CG - Using Matrix as texcoord 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