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 delstrega · Jun 17, 2012 at 07:46 AM · meshupdateloopfastvertex color

Best practice to change vertex color on a large amount of quads?

Hi there! For a project of mine I need to change the vertex colors of a large amount of quad meshes (900+) individually. What I want to achieve is that every quad has it's own time offset saved in myAlphaOffset[] that determines when the alpha change for that quad begins (since I subtract that offset from the current progress in my lerp). When 'progress' has reached 1f, every quad, regardless of its offset should end up with a alpha of 0.

My code atm is something like this:

    public override IEnumerator ChangeQuadAlphas ()
         {
         
             Color transColor = Color.white;
             
             while(changingAlpha){
                 
                 for(int r=0;r<rows;r++){
                     for(int c=0;c<cols;c++){            
                         transColor.a = Mathf.Lerp(0f,1f,(progress-myAlphaOffset[c+r*cols])/duration);
                         
                         quads[c+r*cols].mesh.colors = new Color[]{
                             transColor,
                             transColor,
                             transColor,
                             transColor
                          };
                     }
                 }
                 yield return null;
             }
         
             yield return null;
         }

This code so far works fine but strains the cpu very much. I tried easing the load on the cpu by yielding after each row of the loop but then the alpha changes occur spread over multiple frames. This way I would end up with a lot of half visible quads when progress reaches 1f since there weren't enough frames for changing.

Now I don't know how to optimise that further. Would loop unrolling have much of an impact here? Would it be better to give each quadobject a lerptarget so that the mesh alpha would be changed in the quadobject's Update()? This is what I mean:

 //Script attached to each quad
 ...
 Color myColor = Color.white;
 float myOffset = someValue;
 
 void Update(){
   myColor.a = Mathf.Lerp(0f, 1f, (progress-myOffset)/duration;
   this.mesh.colors = new Color[]{
         myColor,
         myColor,
         myColor,
         myColor
 
   }
 }

I would guess that the overhead of 900+ Update()-functions might outweigh the benefits.

Maybe there is another approach that I might be unaware of so - what is the best (fastest) way of updating the mesh colors of a large amount of meshes individually?

Thanks in advance,

delstrega

Comment
Add comment · Show 4
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 Wolfram · Jun 23, 2012 at 12:31 PM 0
Share

Consider using a shader ins$$anonymous$$d.

avatar image delstrega · Jun 23, 2012 at 02:01 PM 0
Share

Sounds interesting. Since I'm not that much into shaders, what are the possibilities here? Can you pass parameters to shaders and use that to adjust the vertex color there?

avatar image Jessy · Jun 23, 2012 at 02:41 PM 0
Share

You can adjust colors, but it's a massively parallel operation which does the same thing to every vertex. Are the color offsets always the same, between quads? If that were the case, you could do this in the vertex shader. Otherwise, I'm not thinking of a way to do it outside of script.

avatar image delstrega · Jun 23, 2012 at 02:48 PM 0
Share

Unfortunately the offsets differ from quad to quad :( Guess I'm out of luck then, but thanks for clearing that up :)

1 Reply

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

Answer by Jessy · Jun 17, 2012 at 07:57 AM

There is no fast way to update the colors for a ton of meshes. Combine the meshes. The rest of the stuff you're mentioning, like loop unrolling, is not the problem at all.

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 delstrega · Jun 23, 2012 at 11:41 AM 0
Share

Thanks Jessy, I guess I'll have to bite the bullet and try to limit the number of quads then ;)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

While loop issues in Update() vs. Start() 0 Answers

c# update loop. How to? 2 Answers

variables based on array.length not updating in JS 1 Answer

A delay/yield/wait function for function Update? 6 Answers

Objects Instantiated in a Loop Problem 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