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 /
avatar image
0
Question by Richard3575 · Oct 19, 2018 at 10:45 AM · shadermaterialsmaterial rendererrenderqueuealphablend

ARCore – not changing alpha on material after changing BlendMode through code.

Anyone got any ideas why in ARCore I’m not seeing a smooth fade of the material after I change the material blend mode? I’ve tested the following code and in the editor/Game mode it’s working fine. Also the fade routine is working fine in ARCore if I set the material blend mode to “standard>fade” (or transparent) in the Material Inspector, then the routine works fine and I get a nice fade in ARCore and the editor.

However, I need to switch modes on the fly as I have multiple items to fade out and I can’t get Unity to play well with them (z-sorting issues). So the best logic I can find is to change the blend mode whilst fading in/out, then set to “Standard > Opaque” once done. BUT…. This does not appear to be working in ARCore. I see the modes are changing, as you can see z-buffering sorting issues come and go as it switches between modes, but the fading is no longer happening.

Any ideas?

Thanks in advance for any help

 void Start()
     {
         myRenderer = GetComponent<Renderer>();
         solidColor = myRenderer.material.color;
         fadedColor = new Color(solidColor.r, solidColor.g, solidColor.b, 0f);
       //  myRenderer.material.renderQueue = 4001;
         Debug.Log(myRenderer.material.renderQueue);
         material = myRenderer.material;
     }
     public void startFading()
     {
        // go = true;
         Debug.Log("startFading - bb-working");
         if (!fading)
         {
             StartCoroutine(Fade());
         }
 
     }
 
     IEnumerator Fade()
     {
 
         material.SetFloat("_Mode", 2);
         material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
         material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
         material.SetInt("_ZWrite", 0);
         material.DisableKeyword("_ALPHATEST_ON");
         material.DisableKeyword("_ALPHABLEND_ON");
         material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
         material.renderQueue = 3000;
 
         Debug.Log("coruntine started for skin");
         fading = true;
         Color fromColor = faded ? fadedColor : solidColor;
         Color toColor = faded ? solidColor : fadedColor;
         for (var t = 0f; t < fadeTime; t += Time.deltaTime)
         {
             Debug.Log("fading skin");
             //currentColor = Color.Lerp(fromColor, toColor, t / fadeTime);
             myRenderer.material.color = Color.Lerp(fromColor, toColor, t / fadeTime);
             yield return null;
         }
         if (toColor == solidColor)
         {
             material.SetFloat("_Mode", 0);
             material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
             material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
             material.SetInt("_ZWrite", 1);
             material.DisableKeyword("_ALPHATEST_ON");
             material.DisableKeyword("_ALPHABLEND_ON");
             material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
             material.renderQueue = -1;
         }
 
         fading = false;
         faded = !faded;
     }
 
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
Best Answer

Answer by Richard3575 · Oct 19, 2018 at 02:06 PM

Right, Solved it! So you have to read the fine print. “Material of that type in your Assets. The material must be used in a scene” https://docs.unity3d.com/Manual/MaterialsAccessingViaScript.html (part 2 at the bottom)

So the issue was that it ran in the editor fine, but when built it stripped out all unused materials and I did not have a material using the Transparent shade in, and therefore it didn’t work. All I did was include a object with a “standard > transparent” material on in the scene and it works!!!

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

94 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

Related Questions

How to Add Render Queue property in Inspector to LightWeight Shader ? 1 Answer

How to edit a shader to make it show sprites it's on without lighting? 0 Answers

Seamless Water Material on a Plane using Shader Graph 3 Answers

My mesh didn’t appear in Unity 0 Answers

Sequential shaders. Pass the output color of a shader to the next one. 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