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 xandermacleod · May 31, 2012 at 09:25 PM · materiallerpfadedifferentblend

How can I blend between 5 different materials?

Hi there. I've been taking a look at the unity scripting reference for material.Lerp, but it only seems to list an example where you might want to blend between 2 materials.

In my scene i need to blend between 5 different materials at a constant rate using either PingPong or Loop, over a cyclical period of 10 seconds.

Can anyone help please with some kind of example/link as to how I might go about this?

(P.S. Ideally if you could show an example in C# that would be great, but I don't mind if it's in Javascript).

edit(moved from answer-comment)
Ah! good point. I didnt clarify that. Im thinking lerp gradually from A-B, then B-C, then C-D, then D-E, then E back to A

Comment
Add comment · Show 2
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 Berenger · Jun 01, 2012 at 04:49 PM 0
Share

Do you want to blend between A, B, C, D, E at the same time (something like lerp( lerp( lerp ( lerp( A, B, t5), C, t3), D, t2), E, t1)), or do you want to lerp between A and B, then B and C, then C and D ... ?

avatar image hijinxbassist · Jun 01, 2012 at 05:58 PM 0
Share

@Berenger Wow, some crazy quad lerpin :p

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Wolfram · Jun 01, 2012 at 06:47 PM

You can split up your lerp parameter over the array of materials:

 // assuming "blend" is your interpolation parameter, moving from 0 to 1 in 10 seconds

 if(myMaterialArray.Length>=2){
     float scaledBlend=blend*(myMaterialArray.Length-1);
     int index=Mathf.FloorToInt(scaledBlend);
     if(blend==1){
         // special treatment/workaround for maximum, to prevent out-of-bounds overflow
         index--;
     }
     float partial01blend=scaledBlend-index; // the fraction of scaledBlend
     renderer.material.Lerp(myMaterialArray[index],myMaterialArray[index+1],partial01blend);
 }

EDIT: Oh, this does not lerp E back to A. So that's left as an exercise for the reader ;-)

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

Answer by Berenger · Jun 01, 2012 at 10:16 PM

I'm not sure what would be the best performance-wise, to declare 2 texture in you shader and use SetTexture in your script to assign them correctly, or to declare them all and use an int to choose the combinaison for the lerp inside the shader. Sort of if( i == 0 ) lerp( A, B, t ) etc. But both are correct.

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

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Material lerp problem 1 Answer

Way to get a material to alpha-fade along the texture? 0 Answers

Vertex Alpha value doesn't update? 1 Answer

Lerping/Fading between multiple colours 1 Answer

Fade an object out 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