Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

AlphaBland is not working when I set to transparent from opaque at runtime by script on mobile devic

Discussion in 'Shaders' started by poM2, Jan 25, 2016.

  1. poM2

    poM2

    Joined:
    Jul 13, 2015
    Posts:
    8
    Hello.

    I am making a rpg game, I am using a third person camera that follows character.
    I am implementing a transparent object that is between my character and camera.

    There is a level object that is between character and camera.
    Sometimes, It covers my character. So I have to make it as a transparent object when it covers the character.

    I have implemented it, it works on editor on windows but android device.


    I am using a material uses standard specular shader on Unity5.3.1f.
    When It needs alphablend, next script codes are called.

    mats.SetFloat("_Mode", 3);
    mats.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
    mats.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
    mats.SetInt("_ZWrite", 1);
    mats.DisableKeyword("_ALPHATEST_ON");
    mats.EnableKeyword("_ALPHABLEND_ON");
    mats.DisableKeyword("_ALPHAPREMULTIPLY_ON");
    mats.renderQueue = 3000;

    and then, alpha values are decreased smoothly.

    Sadly, It doesn't works on android mobile devices that supports SM3.0.
    It just works on windows platform editor.

    I have no idea. help me with any advices please.

    Thx.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    It's possible it's an asset package issue. The game will try to remove any version of the shader not in use by the scene or added to you shader variants. Try making a copy of one of your materials, setting it to be fade, and put an object in your level using that material. If that works look into shader variant collections.
     
  3. poM2

    poM2

    Joined:
    Jul 13, 2015
    Posts:
    8
    bgolus, you are right. I sovled this problem with your advice.

    I am curious, If there is other method.
    For instance, using multi compile shader.
    I think, It could be use multi compile shader.
    But, How can I multi compile standard shader?

    Sorry for my poor english.

    Thx.
     
  4. SanjayBhambhu

    SanjayBhambhu

    Joined:
    Aug 22, 2012
    Posts:
    13
    Hi
    "SUFFERING" from the same problem. I put the material on a cube in the main scene and still it isn't working.
    Please reply...