Search Unity

How can I remove these black dots on the materials ?

Discussion in 'General Graphics' started by sayginkarahan, May 7, 2018.

  1. sayginkarahan

    sayginkarahan

    Joined:
    Jan 23, 2015
    Posts:
    49
    Hi everone,

    I have some problems when changing alpha percent of the materials.

    I got this strange view when i change the alpha value of its material like below.



    Code (CSharp):
    1. public static void SetTransparentOfObject(GameObject obj, float TransparentPercent)
    2.          {
    3.              foreach (Material m in obj.GetComponent<Renderer>().materials)
    4.              {
    5.                  m.SetFloat("_Mode", 2);
    6.                  m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
    7.                  m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
    8.                  m.DisableKeyword("_ALPHATEST_ON");
    9.                  m.EnableKeyword("_ALPHABLEND_ON");
    10.                  m.renderQueue = 3000;
    11.                  m.color = new Color(m.color.r, m.color.g, m.color.b, TransparentPercent);
    12.              }
    13.          }
    I wrote this code to do that. Can you tell me where is my wrong, thanks.
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    Nothing is wrong, it's rendering as intended. You're using Unity's Standard Shader which uses dithered alpha for transparent shadows. This can be disabled on some newer versions of Unity in the Graphics settings (it's the option named "Enable Semitransparent Shadows"), or more directly you can disable shadow casting on the renderer component of the object you're making transparent.

    https://docs.unity3d.com/ScriptReference/Renderer-shadowCastingMode.html
     
    sayginkarahan likes this.
  3. sayginkarahan

    sayginkarahan

    Joined:
    Jan 23, 2015
    Posts:
    49
    Thank you @bgolus for your fast reply. Probably I'll disable the shadows for these objects but I also tried to find the "enable semitransparent shadows" option but I can't find any where. Could you tell me where can I find that option please. Thanks again. (By the way I'm using 2018.1.0f2 Personal version)
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    If you don't see it, you probably don't have it. I think it was added in Unity 2018.1
     
  5. sayginkarahan

    sayginkarahan

    Joined:
    Jan 23, 2015
    Posts:
    49
    I'm using 2018.1 already but thank you for your help. ;)
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
  7. sayginkarahan

    sayginkarahan

    Joined:
    Jan 23, 2015
    Posts:
    49