Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by atul-s-morey · Nov 23, 2016 at 07:20 PM · shadermeshcolor

How to animate vertex color on a 3D GameObject ( say a cube)?

I am trying to animate Color from Bottom to Top on a cube. Below is my test code. I have Top face verts and bottom face vert indices stored in _topFaceVert and _bottomeFaceVert in Start().

 void AnimateColor()
     {
 
         _mesh = GetComponent<MeshFilter>().mesh;
         _vertices = _mesh.vertices;
         Color[] meshColors = new Color[_mesh.vertices.Length];
 
 
 
         int index;
         for (int i=0; i< _topFaceVert.Count; i++)
         {
             index = _topFaceVert[i];
             meshColors[index] = Color.red;
             
         }
 
         for (int j=0; j < _bottomeFaceVert.Count; j++)
         {
             index = _bottomeFaceVert[j];
             meshColors[index] = Color.blue;
         }
 
         _mesh.colors = meshColors;
     }


I am using Mobile/Particles/Vertex Blended shader. Here is the result: alt text

The issue is, you still see inside of the cube. The final result should be The top face being solid Red, bottom face being solid Blue and side faces being colored with gradient effect which is achieved here. Here is a screen shot of the Inspector for the Cube

alt text

What am I doing wrong here? Is there any better alternative? Need a optimized solution as this needs to be deployed in VR so more performance restrictions.

screen-shot-2016-11-23-at-111340-am.png (71.5 kB)
screen-shot-2016-11-23-at-111549-am.png (61.0 kB)
Comment
Add comment · Show 1
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 hexagonius · Nov 23, 2016 at 08:54 PM 0
Share

I think the main reason is you're creating a color array but only write colors to certain indices. since colors are struct they get default values, hence 0,0,0,0. you're using an alpha blended shader so that means they are transparent. and from the looks of the visible faces, you picked too few vertices. remember, each corner has 3.

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

strange grass and soft partcile glitch, example image attached. 0 Answers

Color the area between two black images to white 0 Answers

Need help to combine shaders, is this possible? 0 Answers

Shader invert sprite colors 2D 1 Answer

Mesh is lit through the terrain? 0 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