===========================================================================
public static void SetupMaterialWithBlendMode(Material material, BlendMode blendMode) { switch (blendMode) { case BlendMode.Opaque: 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; break; case BlendMode.Cutout: material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.EnableKeyword("_ALPHATEST_ON"); material.DisableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = 2450; break; case BlendMode.Fade: material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.DisableKeyword("_ALPHATEST_ON"); material.EnableKeyword("_ALPHABLEND_ON"); material.DisableKeyword("_ALPHAPREMULTIPLY_ON"); material.renderQueue = 3000; break; case BlendMode.Transparent: 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; break; } }
============================================================================
ex)
skinMeshRenders[i].materials[j].shader = Shader.Find("Standard");
skinMeshRenders[i].materials[j].SetFloat("_Mode", 2.0f);
skinMeshRenders[i].materials[j].SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
skinMeshRenders[i].materials[j].SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
skinMeshRenders[i].materials[j].SetInt("_ZWrite", 0);
skinMeshRenders[i].materials[j].DisableKeyword("_ALPHATEST_ON");
skinMeshRenders[i].materials[j].EnableKeyword("_ALPHABLEND_ON");
skinMeshRenders[i].materials[j].DisableKeyword("_ALPHAPREMULTIPLY_ON");
skinMeshRenders[i].materials[j].renderQueue = 3000;
Color temp_color = skinMeshRenders[i].materials[j].color;
temp_color.a = alpha;
skinMeshRenders[i].materials[j].color = temp_color;
'프로그래밍 정리 > Unity' 카테고리의 다른 글
[유니티][Unity] 유니티 라이브버리 추가시 빌드에러일 경우 (0) | 2016.11.15 |
---|---|
[유니티][Unitty] 유니티 화면 안 꺼지게하는 코드 (0) | 2016.11.08 |
[Unity - 유니티] 전처리기(Preprocessor) (0) | 2014.06.10 |
[Unity - 유니티] Touch 구조체 (0) | 2014.06.10 |
[Unity - 유니티] 스크린 터치(Screen Touch) - ScreenPointToRay 함수 (1) | 2014.06.10 |