Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

Alpha will not change in Hololens, only in Editor.

edited December 2016 in Questions And Answers

Hello, I've been having a lot of trouble changing the Alpha in the Hololens emulator and the hololens itself. I've tried many different materials, all of the Holotoolkit ones and Standard Specular. AND Here is my code:

    GameObject eye;
    Material mat;
    Material mat2;
    Shader initShader;
    public MovieTexture[] tex;
    Color col;
    bool faded;
    float colVal = 2.5f;
    public float currColVal;
    public int texNum;
    public float max_Dist;
    public bool proximity;
    //public float appear_rate = 0.05f;
    //public float dissappear_rate = 0.1f;


   void Start()
    {
        mat = GetComponent<Renderer>().material;
        mat2 = GetComponent<Renderer>().material;
        currColVal = colVal;
        eye = GameObject.FindGameObjectWithTag("MainCamera");
        faded = false;
        //ChangeRenderingModeToTransparent();
        //mat.shader = Shader.Find("Standard (Specular setup)");
        //proximity = true;
    }

    void FixedUpdate()
    {
        //Changes based off of Proxemics script
        if(proximity == true && faded == false)
        {
            ChangeRenderingModeToFade();
            StartCoroutine(Dissappear());
            faded = true;
        }

        if(proximity == false && faded == true)
        {
            StartCoroutine(Appear());
            ChangeRenderingModeToOpaque();
            faded = false;
        }
}

    public IEnumerator Appear()
    {

        for (float j = 0f; j <= colVal; j += 0.1F)
        {
            col = mat.color;
            col.a = j;
            //col.r = j;
            //col.g = j;
            //col.b = j;
            mat.color = col;
            currColVal = j;
            yield return null;
            //yield return new WaitForSeconds(0.5f);
        }

    }


    public IEnumerator Dissappear()
    {     
            for (float i = colVal; i >= 0f; i -= 0.1f)
            {
                col = mat.color;
                col.a = i;
                //col.r = i;
                //col.g = i;
                //col.b = i;
                mat.color = col;
                currColVal = i;
                yield return null;
                //yield return new WaitForSeconds(0.5f);
            }
    }


    public void ChangeRenderingModeToOpaque()
    {
        mat.SetFloat("_Mode", 0);
        mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
        mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
        mat.SetInt("_ZWrite", 0);
        mat.DisableKeyword("_ALPHATEST_ON");
        mat.EnableKeyword("_ALPHABLEND_ON");
        mat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
        mat.renderQueue = 3000;
    }

    public void ChangeRenderingModeToFade()
    {
        mat.SetFloat("_Mode", 2);
        mat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
        mat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
        mat.SetInt("_ZWrite", 0);
        mat.DisableKeyword("_ALPHATEST_ON");
        mat.EnableKeyword("_ALPHABLEND_ON");
        mat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
        mat.renderQueue = 3000;
    }
Tagged:

Comments

  • Options

    Bump. Any help? Why does this fade in-editor but not the Hololens? I assume the shaders are the problem, but I've tried every shader I could find. Standard Specular I thought would work, but to no avail, I tried every Holotoolkit shader, even the galaxy explorer shaders.

  • Options

    Still having trouble with this question. Any ideas???

  • Options

    Any help would be greatly appreciated. Do I need to reword the question?

  • Options

    I'm facing the same trouble. Even though alpha value manipulation did work very well in the editor, it doesn't work in the HoloLens or in the emulator. I want to fade out an Object. Please, can anybody help?

  • Options

    What shader are you using ? Try HoloToolkit's VertexLit Configarble Transparent Shader ... It works for me

  • Options

    Also check your quality settings. Edit -> Project Settings -> Quality if I remember correctly. The toolkit sets up a very fast rendering configuration for the HoloLens but several features are turned off. The times I've seen a discrepancy between the editor and the device it's usually due to these quality settings.

    Our Holographic world is here

    RoadToHolo.com      WikiHolo.net      @jbienz
    I work in Developer Experiences at Microsoft. My posts are based on my own experience and don't represent Microsoft or HoloLens.

Sign In or Register to comment.