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
  4. Dismiss Notice

Buttons are transparent against Grid

Discussion in 'Editor & General Support' started by t-heo, Sep 16, 2020.

  1. t-heo

    t-heo

    Joined:
    Aug 22, 2019
    Posts:
    24
    Hi!

    Having a problem with having transparent buttons, that show through a Grid behind them. I would kindly appreciate tips to overcome this. The code for the Grid shader is the following, but I haven't been able to make sense of it. This issue only affects button (Canvas > UI > Button Sprites).



    Code for the Grid material, I tried tinkering with the settings with no luck:

    Code (CSharp):
    1.      {
    2.          var shader = Shader.Find("Hidden/Internal-Colored");
    3.          lineMaterial = new Material(shader);
    4.          lineMaterial.hideFlags = HideFlags.HideAndDontSave;
    5.          //alpha blending
    6.          lineMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
    7.          lineMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
    8.          // backface culling off
    9.          lineMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
    10.          // depth writes off
    11.          lineMaterial.SetInt("_ZWrite", 0);
    12.      }
     
  2. t-heo

    t-heo

    Joined:
    Aug 22, 2019
    Posts:
    24
    Sorry to bump but anyone got a clue? This seems like a pretty easy problem to solve with the right knowledge on shaders.
     
  3. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,053
    https://docs.unity.cn/530/Documentation/ScriptReference/GL.html

    if you are suing this then the maybe the issue is in the code you didn't include, they say

    Code (CSharp):
    1.  
    2. // Will be called after all regular rendering is done
    3.  
    maybe the buttons are render then you render the grind and put it on top of everything
     
  4. t-heo

    t-heo

    Joined:
    Aug 22, 2019
    Posts:
    24
    I tried setting the Grid creation to Awake but it didn't change a thing. Also, most objects are displayed with correct depth regarding, only the buttons are not.
     
  5. t-heo

    t-heo

    Joined:
    Aug 22, 2019
    Posts:
    24
    So far sorted out with a crude solution by adding a cube behind the buttons but would still prefer to sort this with a better solution.