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 AlecKWhite · Mar 21, 2017 at 05:55 PM · meshcolormeshfiltervertex color

Heatmap Color Ramp on 3D model

I'm trying to generate a smooth continuous heat map color ramp of a 3D model, but I get a discrete looking shader on my model. Below is the code I used to generate the heatmap color ramp shader. In particular, I iterate through the vertices of the mesh and assign them new color values correlating to the y value so the lowest y value is given blue and the highest value is given red and the in between are cyan, green, and yellow. I want to scale the values based on height so there are more colors and the model then looks better/smoother.

I'm thinking my issue in how I am taking the Y values (the order of the vertices are stored in the mesh.vertices array) or I am not allowed to create that many colors.

Below is the model with the shader and vertex coloring method applied followed by the code.

alt text

 public class TopoHeatMap : MonoBehaviour {
     public Mesh mesh;
     public Material material1;
     public Shader vertexShader; // Material with a Custom/Vertex Colored shader assigned in Inspector
     public Renderer myRenderer;
     public void renderHeatMap()
     {
         myRenderer = GetComponent<Renderer>();
         vertexShader = Shader.Find ("Custom/Vertex Colored");
 
         if (myRenderer.material.shader != vertexShader) {
             vertexShader = Shader.Find ("Custom/Vertex Colored");
             myRenderer.material.shader = vertexShader;
 
             Mesh mesh = GetComponent<MeshFilter> ().mesh;
             Vector3[] vertices = mesh.vertices;
             Color[] colors = new Color[vertices.Length]; //stores colors for all vertices in mesh
             float partition = vertices.Length / 4;
 
             for (int i = 0; i < vertices.Length; i++) { //iterated through mesh vertices
                 if (i < vertices.Length / 4) {
                     colors [i] = new Color (0f, i / (partition), 1f, 1f); //populates color array of vertices with new color
                 } else if (i < vertices.Length / 2) {
                     colors [i] = new Color (0f, 1f, (i-partition) / (partition), 1f); //populates color array of vertices with new color
                 } else if (i < 3 * vertices.Length / 4) {
                     colors [i] = new Color ((i-2*partition)/ (partition), 1f, 0f, 1f); //populates color array of vertices with new color
                 } else {
                     colors [i] = new Color (1f, (i-3*partition)/ (partition), 0f, 1f); //populates color array of vertices with new color
                 }
             }
             mesh.colors = colors;
         } 
         else {
             vertexShader = Shader.Find ("Standard");
             myRenderer.material.shader = vertexShader;
         }
 
     }
 
 }


screenshot-2017-03-21-134216.png (313.8 kB)
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

Answer by AlecKWhite · Mar 21, 2017 at 06:56 PM

Here's what the model looks like without the heat map coloration applied.

alt text


screenshot-2017-03-21-134201.jpg (142.8 kB)
Comment
Add comment · 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

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

100 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

Related Questions

Mesh missing in prefab 0 Answers

Vertex Colors are lost after build Android 1 Answer

[Mesh] Unity 4 to Unity 5 Mesh Export 0 Answers

trying to skew preafabs 0 Answers

URGENT How to get triangles of mesh in world space? 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