• 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
5
Question by Deikkan · Jul 04, 2010 at 10:27 AM · materialfade

Fading Materials

What I am looking to do is to fade one material into another on a gameObject, over a period of time. What I currently have is an array of materials w$$anonymous$$ch change one by one, each one slighly more similar to the desired material last than the last. Is there a way to dynamically change the alpha on a material, so that they can be crossfaded? If t$$anonymous$$s can't be done on materials then would t$$anonymous$$s be possible with textures instead?

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

4 Replies

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

Answer by StephanK · Jul 04, 2010 at 12:15 PM

I don't t$$anonymous$$nk t$$anonymous$$s is possible with materials. But depending on how your materials are layed out and what shaders you are using you might be able to ac$$anonymous$$eve the effect you are looking for. These are some of the possibilities:

  1. change the main color. (works only if both materials are using the same texture/shader)
  2. write a shader that is able to crossfade two (or more) materials. There is a shader on the wiki called skybox blended w$$anonymous$$ch shows how to do that. However t$$anonymous$$s will only work if both desired materials use the same shader. (actually its only one material with different textures)
  3. fading out using alpha will only work if you are using transparent shaders.
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 Deikkan · Jul 04, 2010 at 12:39 PM 0
Share

Cheers, I'll give them a go.

avatar image
4

Answer by Deikkan · Jul 04, 2010 at 01:37 PM

OK, I've built a shader using the Skybox Blended code, and applied it to a material called "Blend". The code for the shader is below.

Shader "Texture Blend" {

Properties { _Tint ("Tint Color", Color) = (.5, .5, .5, .5) _Blend ("Blend", Range(0.0,1.0)) = 0.5 _Tex ("Start Texture", 2D) = "w$$anonymous$$te" {} _Tex2 ("End Texture", 2D) = "w$$anonymous$$te" {}

}

SubShader { Tags { "Queue" = "Background" } Cull Off ZWrite On ZTest Always Fog { Mode Off } Lighting Off
Color [_Tint] Pass { SetTexture [_Tex] { combine texture } SetTexture [_Tex2] { constantColor (0,0,0,[_Blend]) combine texture lerp(constant) previous } SetTexture [_Tex2] { combine previous +- primary, previous * primary } } }

I want to change the 'Blend' value in a script, and the site said to use:

skyboxmaterial.SetFloat("_Blend", yourBlend)

However, when I try to call it in the script using:

Blend.SetFloat("_Blend", examplefloat);

I get the error that Blend (the material) has not been identified. Any help?

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 Deikkan · Jul 04, 2010 at 04:21 PM 0
Share

nvm, worked it out.

Decided to use renderer.material.shader = Shader.Find("Texture Blend"); and declare it that way.

avatar image
1

Answer by ellens · Jul 09, 2012 at 03:25 PM

You can crossfade them with the Lerp method of materials. Just input the two materials you want to crossfade between:

http://docs.unity3d.com/Documentation/ScriptReference/Material.Lerp.html

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 ellens · Sep 06, 2012 at 08:14 AM

I have written a script and a custom shader for t$$anonymous$$s purpose. See files and code here: http://www.sundh.com/blog/2012/09/real-time-blend-2-textures-in-unity/

Hope it helps!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

rendering mode "Fade" results in culling disorder? 0 Answers

Fading in between two materials overtime? 3 Answers

Fading a GameObject in/out 1 Answer

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

Transparent Fade Depth 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