DisableKeyword() 개인적인 메소드

private DisableKeyword ( string keyword ) : void
keyword string
리턴 void
예제 #1
0
    private void SetColorRange(Material material)
    {
        switch (ColorRange)
        {
            case TOD_ColorRangeType.Auto:
                if (Components.Camera && Components.Camera.HDR)
                {
                    material.EnableKeyword("HDR");
                    material.DisableKeyword("LDR");
                }
                else
                {
                    material.DisableKeyword("HDR");
                    material.EnableKeyword("LDR");
                }
                break;

            case TOD_ColorRangeType.HDR:
                material.EnableKeyword("HDR");
                material.DisableKeyword("LDR");
                break;

            case TOD_ColorRangeType.LDR:
                material.DisableKeyword("HDR");
                material.EnableKeyword("LDR");
                break;
        }
    }
예제 #2
0
    private void SetColorSpace(Material material)
    {
        switch (ColorSpace)
        {
            case TOD_ColorSpaceType.Auto:
                if (QualitySettings.activeColorSpace == UnityEngine.ColorSpace.Linear)
                {
                    material.EnableKeyword("LINEAR");
                    material.DisableKeyword("GAMMA");
                }
                else
                {
                    material.DisableKeyword("LINEAR");
                    material.EnableKeyword("GAMMA");
                }
                break;

            case TOD_ColorSpaceType.Linear:
                material.EnableKeyword("LINEAR");
                material.DisableKeyword("GAMMA");
                break;

            case TOD_ColorSpaceType.Gamma:
                material.DisableKeyword("LINEAR");
                material.EnableKeyword("GAMMA");
                break;
        }
    }
예제 #3
0
    IEnumerator Start()
    {
        foreach (var r in GetComponentsInChildren<Renderer>()) {
            renderers.Add(r);
            originalMaterials[r] = r.sharedMaterial;

            var material = new Material(r.material);
            material.SetFloat("_Mode", 2);
            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;
            r.material = material;
        }

        for (float t = 0; t < 1f; t += Time.deltaTime) {
            if (!UpdateRenderers(t)) {
                yield break;
            }

            yield return null;
        }

        foreach (var r in renderers) {
            if (r) {
                r.material = originalMaterials[r];
            }
        }

        Destroy(this);
    }
 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.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.renderQueue = 2450;
         break;
     case BlendMode.Transparent:
         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.renderQueue = 3000;
         break;
     }
 }
예제 #5
0
 /// <summary>
 /// sets rendering mode of 'material' to transparent
 /// </summary>
 public static void MakeMaterialTransparent(UnityEngine.Material material)
 {
     material.SetFloat("_Mode", 2);
     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;
 }
예제 #6
0
 public static void SetTransparent(Material material)
 {
     material.SetOverrideTag("RenderType", "Transparent");
     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.DisableKeyword("_ALPHABLEND_ON");
     material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
     material.renderQueue = 3000;
 }
예제 #7
0
 public static void SetOpaque(Material material)
 {
     material.SetOverrideTag("RenderType", "");
     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;
 }
 public static void SetOpaqueMode(UnityEngine.Material material)
 {
     material.SetOverrideTag("RenderType", "Opaque");
     material.SetInt(srcBlendPropId, (int)UnityEngine.Rendering.BlendMode.One);
     material.SetInt(dstBlendPropId, (int)UnityEngine.Rendering.BlendMode.Zero);
     material.SetInt(zWritePropId, 1);
     material.DisableKeyword("_ALPHATEST_ON");
     material.DisableKeyword("_ALPHABLEND_ON");
     material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
     material.renderQueue = -1;
 }
예제 #9
0
파일: Comb.cs 프로젝트: jrand35/AmazingRPG
 void Opaque(Material material)
 {
     material.SetFloat("_Mode", 0);
     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;
 }
예제 #10
0
파일: Comb.cs 프로젝트: jrand35/AmazingRPG
 void Transparent(Material material)
 {
     material.SetFloat("_Mode", 3);
     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;
 }
 private void setMaterialToFade(Material m)
 {
     m.SetFloat("_Mode", 2);
     m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
     m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
     m.SetInt("_ZWrite", 0);
     m.DisableKeyword("_ALPHATEST_ON");
     m.EnableKeyword("_ALPHABLEND_ON");
     m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
     m.renderQueue = 3000;
 }
 public static void SetAlphaModeBlend(UnityEngine.Material material)
 {
     material.SetFloat(modePropId, (int)StandardShaderMode.Transparent);
     material.SetOverrideTag("RenderType", "Transparent");
     material.SetInt(srcBlendPropId, (int)UnityEngine.Rendering.BlendMode.SrcAlpha);         //5
     material.SetInt(dstBlendPropId, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); //10
     material.SetInt(zWritePropId, 0);
     material.DisableKeyword("_ALPHATEST_ON");
     material.EnableKeyword("_ALPHABLEND_ON");
     material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
     material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;  //3000
 }
예제 #13
0
 void Start()
 {
     Material m = new Material(Shader.Find("Custom/StandardDepthBuffer"));
     m.SetFloat("_Mode", 2);
     m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
     m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
     m.SetInt("_ZWrite", 0);
     m.DisableKeyword("_ALPHATEST_ON");
     m.EnableKeyword("_ALPHABLEND_ON");
     m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
     m.renderQueue = 3000;
 }
 public void ApplyOpaque(Color col)
 {
     rend = this.gameObject.GetComponent<Renderer>().material;
     rend.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
     rend.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
     rend.SetInt("_ZWrite", 1);
     rend.DisableKeyword("_ALPHATEST_ON");
     rend.DisableKeyword("_ALPHABLEND_ON");
     rend.DisableKeyword("_ALPHAPREMULTIPLY_ON");
     rend.renderQueue = -1;
     StartCoroutine(colorLerp1(rend.GetColor("_Color"), col));
 }
 public static void SetAlphaModeMask(UnityEngine.Material material, Schema.Material gltfMaterial)
 {
     material.SetFloat(modePropId, (int)StandardShaderMode.Cutout);
     material.SetOverrideTag("RenderType", "TransparentCutout");
     material.SetInt(srcBlendPropId, (int)UnityEngine.Rendering.BlendMode.One);
     material.SetInt(dstBlendPropId, (int)UnityEngine.Rendering.BlendMode.Zero);
     material.SetInt(zWritePropId, 1);
     material.EnableKeyword("_ALPHATEST_ON");
     material.DisableKeyword("_ALPHABLEND_ON");
     material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
     material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;  //2450
     material.SetFloat(cutoffPropId, gltfMaterial.alphaCutoff);
 }
예제 #16
0
 Material CreateMaterial(Color emissionColor)
 {
     Material m = new Material(outlineBufferShader);
     m.SetColor("_Color", emissionColor);
     m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
     m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
     m.SetInt("_ZWrite", 0);
     m.DisableKeyword("_ALPHATEST_ON");
     m.EnableKeyword("_ALPHABLEND_ON");
     m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
     m.renderQueue = 3000;
     return m;
 }
 private void RefreshDrawSelfShadowKeyword(bool drawSelfshadow, UnityEngine.Material material)
 {
     if (drawSelfshadow)
     {
         material.EnableKeyword("SELFSHADOW_ON");
         material.DisableKeyword("SELFSHADOW_OFF");
     }
     else
     {
         material.DisableKeyword("SELFSHADOW_ON");
         material.EnableKeyword("SELFSHADOW_OFF");
     }
 }
 void ApplyTransparent(Color col)
 {
     rend = this.gameObject.GetComponent<Renderer>().material;
     rend.SetFloat("_Mode", 3f);
     rend.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
     rend.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
     rend.SetInt("_ZWrite", 0);
     rend.DisableKeyword("_ALPHATEST_ON");
     rend.DisableKeyword("_ALPHABLEND_ON");
     rend.EnableKeyword("_ALPHAPREMULTIPLY_ON");
     rend.renderQueue = 3000;
     StartCoroutine(colorLerp1(rend.GetColor("_Color"), col));
 }
예제 #19
0
        public static void SetOpaque(Material material)
        {
            if (material.shader != StandardShader)
                Debug.LogWarning("Trying to set opaque mode on non-standard shader. Please use the Standard Shader instead or modify this method.");

            material.SetOverrideTag("RenderType", "");
            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;
        }
 static void SetKeyword(Material m, string keyword, bool state)
 {
     if (state)
         m.EnableKeyword(keyword);
     else
         m.DisableKeyword(keyword);
 }
예제 #21
0
 public static void SetAlphaModeBlend(UnityEngine.Material material)
 {
     material.SetFloat(modePropId, (int)StandardShaderMode.Transparent);
     material.SetFloat(dstBlendPropId, 10);
     material.SetOverrideTag("RenderType", "Transparent");
     material.DisableKeyword("_ALPHATEST_ON");
     material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
     material.renderQueue = 3000;
 }
예제 #22
0
        public static void SetTransparent(Material material, Color? newcolor = null)
        {
            material.SetOverrideTag("RenderType", "Transparent");
            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.DisableKeyword("_ALPHABLEND_ON");
            material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
            material.SetFloat("_Metallic", 0f);
            material.SetFloat("_Glossiness", 0f);
            material.renderQueue = 3000;
            material.mainTexture = null;

            if (newcolor != null)
            {
                material.color = newcolor.Value;
            }
        }
예제 #23
0
 public void EnsureKeyword(Material material, string name, bool enabled)
 {
     if (enabled != material.IsKeywordEnabled(name))
     {
         if (enabled)
             material.EnableKeyword(name);
         else
             material.DisableKeyword(name);
     }
 }
 protected void SetKeywordState(UnityEngine.Material material, string keyword, bool activate)
 {
     if (activate)
     {
         material.EnableKeyword(keyword);
     }
     else
     {
         material.DisableKeyword(keyword);
     }
 }
예제 #25
0
 public static void SetBlendMode(Material material, Mode blendMode)
 {
     switch (blendMode)
     {
         case Mode.Opaque:
             material.SetOverrideTag("RenderType", "");
             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 Mode.Cutout:
             material.SetOverrideTag("RenderType", "TransparentCutout");
             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 Mode.Fade:
             material.SetOverrideTag("RenderType", "Transparent");
             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 Mode.Transparent:
             material.SetOverrideTag("RenderType", "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;
     }
 }
 public static void SetShaderBlendMode(BlendMode blendMode, ref Material material)
 {
     switch (blendMode) {
         case BlendMode.Opaque:
             material.SetFloat("_Mode", (float)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.SetFloat("_Mode", (float)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.SetFloat("_Mode", (float)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.SetFloat("_Mode", (float)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;
     }
 }
예제 #27
0
    public static UnityEngine.Material ToUnityMaterial(this Elements.Material material)
    {
        var uMaterial = new UnityEngine.Material(Shader.Find("Standard"));

        uMaterial.name  = material.Name;
        uMaterial.color = material.Color.ToUnityColor();
        uMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
        if (material.Color.Alpha < 1.0f)
        {
            uMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
            uMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            uMaterial.SetInt("_ZWrite", 0);
            uMaterial.DisableKeyword("_ALPHATEST_ON");
            uMaterial.DisableKeyword("_ALPHABLEND_ON");
            uMaterial.EnableKeyword("_ALPHAPREMULTIPLY_ON");
            uMaterial.SetFloat("_Glossiness", material.GlossinessFactor);
            // uMaterial.SetFloat("_Metallic", material.SpecularFactor);
            uMaterial.renderQueue = 3000;
        }

        return(uMaterial);
    }
예제 #28
0
        public static void SetTransparent(Material material, Color? newcolor = null)
        {
            if (material.shader != StandardShader)
                Debug.LogWarning("Trying to set transparent mode on non-standard shader. Please use the Standard Shader instead or modify this method.");

            material.SetOverrideTag("RenderType", "Transparent");
            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.DisableKeyword("_ALPHABLEND_ON");
            material.EnableKeyword("_ALPHAPREMULTIPLY_ON");
            material.SetFloat("_Metallic", 0f);
            material.SetFloat("_Glossiness", 0f);
            material.renderQueue = 3000;
            material.mainTexture = null;

            if (newcolor != null)
            {
                material.color = newcolor.Value;
            }
        }
예제 #29
0
 static public int DisableKeyword(IntPtr l)
 {
     try {
         UnityEngine.Material self = (UnityEngine.Material)checkSelf(l);
         System.String        a1;
         checkType(l, 2, out a1);
         self.DisableKeyword(a1);
         return(0);
     }
     catch (Exception e) {
         LuaDLL.luaL_error(l, e.ToString());
         return(0);
     }
 }
예제 #30
0
 static public int DisableKeyword(IntPtr l)
 {
     try {
         UnityEngine.Material self = (UnityEngine.Material)checkSelf(l);
         System.String        a1;
         checkType(l, 2, out a1);
         self.DisableKeyword(a1);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static int DisableKeyword(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.Material obj = (UnityEngine.Material)ToLua.CheckObject(L, 1, typeof(UnityEngine.Material));
         string arg0 = ToLua.CheckString(L, 2);
         obj.DisableKeyword(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
예제 #32
0
    public override Material CloneMaterial(Material src, int nth)
    {
        Material m = new Material(src);
        m.SetInt("g_batch_begin", nth * m_instances_par_batch);
        m.SetBuffer("particles", m_world.GetParticleBuffer());

        if (m_hdr)
        {
            m.SetInt("_SrcBlend", (int)BlendMode.One);
            m.SetInt("_DstBlend", (int)BlendMode.One);
        }
        else
        {
            m.SetInt("_SrcBlend", (int)BlendMode.DstColor);
            m.SetInt("_DstBlend", (int)BlendMode.Zero);
        }

        if(m_enable_shadow)
        {
            m.EnableKeyword("ENABLE_SHADOW");
            switch (m_sample)
            {
                case Sample.Fast:
                    m.EnableKeyword ("QUALITY_FAST");
                    m.DisableKeyword("QUALITY_MEDIUM");
                    m.DisableKeyword("QUALITY_HIGH");
                    break;
                case Sample.Medium:
                    m.DisableKeyword("QUALITY_FAST");
                    m.EnableKeyword ("QUALITY_MEDIUM");
                    m.DisableKeyword("QUALITY_HIGH");
                    break;
                case Sample.High:
                    m.DisableKeyword("QUALITY_FAST");
                    m.DisableKeyword("QUALITY_MEDIUM");
                    m.EnableKeyword ("QUALITY_HIGH");
                    break;
            }
        }
        else
        {
            m.DisableKeyword("ENABLE_SHADOW");
        }

        return m;
    }
예제 #33
0
 /// <summary>
 /// Permet de changer le mode du shader standard
 /// </summary>
 /// <param name="material">le material à utiliser</param>
 /// <param name="blendMode"> le mode voulu : Opaque , Cutout, Fade, Transparent</param>
 public static void SetupMaterialWithBlendMode(Material material, string blendMode)
 {
     switch (blendMode)
     {
         case "Opaque":
             material.SetFloat("_Mode", 0);
             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 "Cutout":
             material.SetFloat("_Mode", 1);
             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 "Fade":
             material.SetFloat("_Mode", 2);
             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 "Transparent":
             material.SetFloat("_Mode", 3);
             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;
     }
 }
예제 #34
0
        private static void ApplyBlendMode(UnityEngine.Material unityMaterial, BlendMode blendMode)
        {
            switch (blendMode)
            {
            case BlendMode.Opaque:
                unityMaterial.SetFloat(Mode, 0);
                unityMaterial.SetInt(SrcBlend, (int)UnityEngine.Rendering.BlendMode.One);
                unityMaterial.SetInt(DstBlend, (int)UnityEngine.Rendering.BlendMode.Zero);
                unityMaterial.SetInt(ZWrite, 1);
                unityMaterial.DisableKeyword("_ALPHATEST_ON");
                unityMaterial.DisableKeyword("_ALPHABLEND_ON");
                unityMaterial.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                unityMaterial.renderQueue = -1;
                break;

            case BlendMode.Cutout:
                unityMaterial.SetFloat(Mode, 1);
                unityMaterial.SetInt(SrcBlend, (int)UnityEngine.Rendering.BlendMode.One);
                unityMaterial.SetInt(DstBlend, (int)UnityEngine.Rendering.BlendMode.Zero);
                unityMaterial.SetInt(ZWrite, 1);
                unityMaterial.EnableKeyword("_ALPHATEST_ON");
                unityMaterial.DisableKeyword("_ALPHABLEND_ON");
                unityMaterial.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                unityMaterial.renderQueue = 2450;
                break;

            case BlendMode.Translucent:
                unityMaterial.SetFloat(Mode, 3);
                unityMaterial.SetInt(SrcBlend, (int)UnityEngine.Rendering.BlendMode.One);
                unityMaterial.SetInt(DstBlend, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                //!!!!!!! this is normally switched off but somehow enabling it seems to resolve so many issues.. keep an eye out for weirld opacity issues
                //unityMaterial.SetInt("_ZWrite", 0);
                unityMaterial.SetInt(ZWrite, 1);
                unityMaterial.DisableKeyword("_ALPHATEST_ON");
                unityMaterial.DisableKeyword("_ALPHABLEND_ON");
                unityMaterial.EnableKeyword("_ALPHAPREMULTIPLY_ON");
                unityMaterial.renderQueue = 3000;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        /// <summary>
        /// Apply all the Properties Collection to the Target Material by its Name/Id.
        /// This method is only used by this base class to generate the Materials for the Cache
        /// </summary>
        /// <param name="PropCollection">Our source helper Prop Collection Dictionary.</param>
        /// <param name="CollectionName">Set the Collection by its Name/Id.</param>
        /// <param name="Target">Target material.</param>
        private void SetProperties(Dictionary<string, PropertiesCollection> PropCollection, string CollectionName, Material Target)
        {
            //Querry the Dictionary by the CollectionId and apply all properties to the Target Material
            if (PropCollection.ContainsKey(CollectionName))
            {
                //Apply all Textures
                foreach (var tex in PropCollection[CollectionName].Textures)
                {
                    Target.SetTexture(tex.Target.GetString(), tex.Value);
                }

                //Apply all Float Values
                foreach (var val in PropCollection[CollectionName].Floats)
                {
                    Target.SetFloat(val.Target.GetString(), val.Value);
                }

                //Apply all Color tints
                foreach (var tints in PropCollection[CollectionName].Tints)
                {
                    Target.SetColor(tints.Target.GetString(), tints.Value);
                }

                //Apply for all Shader Features
                foreach (var feature in PropCollection[CollectionName].Features)
                {
                    if (feature.Value)
                        Target.EnableKeyword(feature.Target.GetString());
                    else
                        Target.DisableKeyword(feature.Target.GetString());
                }
            }
            else
            {
                Debug.LogError("There is no matching Id on this Collection");
            }
        }
예제 #36
0
    private void SetCloudQuality(Material material)
    {
        switch (CloudQuality)
        {
            case TOD_CloudQualityType.Fastest:
                material.EnableKeyword("FASTEST");
                material.DisableKeyword("DENSITY");
                material.DisableKeyword("BUMPED");
                break;

            case TOD_CloudQualityType.Density:
                material.DisableKeyword("FASTEST");
                material.EnableKeyword("DENSITY");
                material.DisableKeyword("BUMPED");
                break;

            case TOD_CloudQualityType.Bumped:
                material.DisableKeyword("FASTEST");
                material.DisableKeyword("DENSITY");
                material.EnableKeyword("BUMPED");
                break;
        }
    }
        private static void ApplyBlendMode(UnityEngine.Material unityMaterial, BlendMode blendMode)
        {
            // disable shader passes
            unityMaterial.SetShaderPassEnabled("DistortionVectors", false);
            unityMaterial.SetShaderPassEnabled("MOTIONVECTORS", false);
            unityMaterial.SetShaderPassEnabled("TransparentDepthPrepass", false);
            unityMaterial.SetShaderPassEnabled("TransparentDepthPostpass", false);
            unityMaterial.SetShaderPassEnabled("TransparentBackface", false);

            // reset existing blend modes, will be enabled explicitly
            unityMaterial.DisableKeyword("_BLENDMODE_ALPHA");
            unityMaterial.DisableKeyword("_BLENDMODE_ADD");
            unityMaterial.DisableKeyword("_BLENDMODE_PRE_MULTIPLY");

            switch (blendMode)
            {
            case Engine.VPT.BlendMode.Opaque:

                // required for the blend mode
                unityMaterial.SetInt(SrcBlend, (int)UnityEngine.Rendering.BlendMode.One);
                unityMaterial.SetInt(DstBlend, (int)UnityEngine.Rendering.BlendMode.Zero);
                unityMaterial.SetInt(ZWrite, 1);

                // properties
                unityMaterial.SetFloat(SurfaceType, 0);                         // 0 = Opaque; 1 = Transparent
                unityMaterial.SetFloat(AlphaCutoffEnable, 0);

                // render queue
                unityMaterial.renderQueue = -1;

                break;

            case Engine.VPT.BlendMode.Cutout:

                // set render type
                unityMaterial.SetOverrideTag("RenderType", "TransparentCutout");

                // keywords
                unityMaterial.EnableKeyword("_ALPHATEST_ON");
                unityMaterial.EnableKeyword("_NORMALMAP_TANGENT_SPACE");

                // required for the blend mode
                unityMaterial.SetInt(SrcBlend, (int)UnityEngine.Rendering.BlendMode.One);
                unityMaterial.SetInt(DstBlend, (int)UnityEngine.Rendering.BlendMode.Zero);
                unityMaterial.SetInt(ZWrite, 1);

                // properties
                unityMaterial.SetFloat(SurfaceType, 0);                         // 0 = Opaque; 1 = Transparent
                unityMaterial.SetFloat(AlphaCutoffEnable, 1);

                unityMaterial.SetFloat(ZTestDepthEqualForOpaque, 3);
                unityMaterial.SetFloat(ZTestModeDistortion, 4);
                unityMaterial.SetFloat(ZTestGBuffer, 3);

                // render queue
                unityMaterial.renderQueue = 2450;

                break;

            case Engine.VPT.BlendMode.Translucent:

                // set render type
                unityMaterial.SetOverrideTag("RenderType", "Transparent");

                // keywords
                //unityMaterial.EnableKeyword("_ALPHATEST_ON"); // required for _AlphaCutoffEnable
                unityMaterial.EnableKeyword("_BLENDMODE_PRESERVE_SPECULAR_LIGHTING");
                unityMaterial.EnableKeyword("_BLENDMODE_PRE_MULTIPLY");
                unityMaterial.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT");
                unityMaterial.EnableKeyword("_NORMALMAP_TANGENT_SPACE");
                unityMaterial.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");

                // required for the blend mode
                unityMaterial.SetInt(SrcBlend, (int)UnityEngine.Rendering.BlendMode.One);
                unityMaterial.SetInt(DstBlend, (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                unityMaterial.SetInt(ZWrite, 0);

                // properties
                unityMaterial.SetFloat(SurfaceType, 1);                       // 0 = Opaque; 1 = Transparent
                //unityMaterial.SetFloat("_AlphaCutoffEnable", 1); // enable keyword _ALPHATEST_ON if this is required
                unityMaterial.SetFloat(BlendMode, 4);                         // 0 = Alpha, 1 = Additive, 4 = PreMultiply

                // render queue
                const int transparentRenderQueueBase = 3000;
                const int transparentSortingPriority = 0;
                unityMaterial.SetInt(TransparentSortPriority, transparentSortingPriority);
                unityMaterial.renderQueue = transparentRenderQueueBase + transparentSortingPriority;

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #38
0
        protected virtual MaterialCacheData CreateMaterial(GLTF.Schema.Material def, int materialIndex)
        {
            MaterialCacheData materialWrapper = null;

            if (materialIndex < 0 || _assetCache.MaterialCache[materialIndex] == null)
            {
                Shader shader;

                // get the shader to use for this material
                try
                {
                    if (_root.ExtensionsUsed != null && _root.ExtensionsUsed.Contains("KHR_materials_pbrSpecularGlossiness"))
                    {
                        shader = _shaderCache[MaterialType.KHR_materials_pbrSpecularGlossiness];
                    }
                    else if (def.PbrMetallicRoughness != null)
                    {
                        shader = _shaderCache[MaterialType.PbrMetallicRoughness];
                    }
                    else if (_root.ExtensionsUsed != null && _root.ExtensionsUsed.Contains("KHR_materials_common") &&
                             def.CommonConstant != null)
                    {
                        shader = _shaderCache[MaterialType.CommonConstant];
                    }
                    else
                    {
                        shader = _shaderCache[MaterialType.PbrMetallicRoughness];
                    }
                }
                catch (KeyNotFoundException)
                {
                    Debug.LogWarningFormat("No shader supplied for type of glTF material {0}, using Standard fallback", def.Name);
                    shader = Shader.Find("Standard");
                }

                shader.maximumLOD = MaximumLod;

                var material = new UnityEngine.Material(shader);

                if (def.AlphaMode == AlphaMode.MASK)
                {
                    material.SetOverrideTag("RenderType", "TransparentCutout");
                    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 = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
                    material.SetFloat("_Cutoff", (float)def.AlphaCutoff);
                }
                else if (def.AlphaMode == AlphaMode.BLEND)
                {
                    material.SetOverrideTag("RenderType", "Transparent");
                    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 = (int)UnityEngine.Rendering.RenderQueue.Transparent;
                }
                else
                {
                    material.SetOverrideTag("RenderType", "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;
                }

                if (def.DoubleSided)
                {
                    material.SetInt("_Cull", (int)CullMode.Off);
                }
                else
                {
                    material.SetInt("_Cull", (int)CullMode.Back);
                }

                if (def.PbrMetallicRoughness != null)
                {
                    var pbr = def.PbrMetallicRoughness;

                    material.SetColor("_Color", pbr.BaseColorFactor.ToUnityColor());

                    if (pbr.BaseColorTexture != null)
                    {
                        var textureDef = pbr.BaseColorTexture.Index.Value;
                        material.SetTexture("_MainTex", CreateTexture(textureDef));

                        ApplyTextureTransform(pbr.BaseColorTexture, material, "_MainTex");
                    }

                    material.SetFloat("_Metallic", (float)pbr.MetallicFactor);

                    if (pbr.MetallicRoughnessTexture != null)
                    {
                        var texture = pbr.MetallicRoughnessTexture.Index.Value;
                        material.SetTexture("_MetallicRoughnessMap", CreateTexture(texture));

                        ApplyTextureTransform(pbr.MetallicRoughnessTexture, material, "_MetallicRoughnessMap");
                    }

                    material.SetFloat("_Roughness", (float)pbr.RoughnessFactor);
                }

                if (_root.ExtensionsUsed != null && _root.ExtensionsUsed.Contains(KHR_materials_pbrSpecularGlossinessExtensionFactory.EXTENSION_NAME))
                {
                    KHR_materials_pbrSpecularGlossinessExtension specGloss = def.Extensions[KHR_materials_pbrSpecularGlossinessExtensionFactory.EXTENSION_NAME] as KHR_materials_pbrSpecularGlossinessExtension;

                    if (specGloss.DiffuseTexture != null)
                    {
                        var texture = specGloss.DiffuseTexture.Index.Value;
                        material.SetTexture("_MainTex", CreateTexture(texture));

                        ApplyTextureTransform(specGloss.DiffuseTexture, material, "_MainTex");
                    }
                    else
                    {
                        material.SetColor("_Color", specGloss.DiffuseFactor.ToUnityColor());
                    }

                    if (specGloss.SpecularGlossinessTexture != null)
                    {
                        var texture = specGloss.SpecularGlossinessTexture.Index.Value;
                        material.SetTexture("_SpecGlossMap", CreateTexture(texture));
                        material.EnableKeyword("_SPECGLOSSMAP");

                        ApplyTextureTransform(specGloss.SpecularGlossinessTexture, material, "_SpecGlossMap");
                    }
                    else
                    {
                        material.SetVector("_SpecColor", specGloss.SpecularFactor.ToUnityVector3());
                        material.SetFloat("_Glossiness", (float)specGloss.GlossinessFactor);
                    }
                }

                if (def.CommonConstant != null)
                {
                    material.SetColor("_AmbientFactor", def.CommonConstant.AmbientFactor.ToUnityColor());

                    if (def.CommonConstant.LightmapTexture != null)
                    {
                        material.EnableKeyword("LIGHTMAP_ON");

                        var texture = def.CommonConstant.LightmapTexture.Index.Value;
                        material.SetTexture("_LightMap", CreateTexture(texture));
                        material.SetInt("_LightUV", def.CommonConstant.LightmapTexture.TexCoord);

                        ApplyTextureTransform(def.CommonConstant.LightmapTexture, material, "_LightMap");
                    }

                    material.SetColor("_LightFactor", def.CommonConstant.LightmapFactor.ToUnityColor());
                }

                if (def.NormalTexture != null)
                {
                    var texture = def.NormalTexture.Index.Value;
                    material.SetTexture("_BumpMap", CreateTexture(texture));
                    material.SetFloat("_BumpScale", (float)def.NormalTexture.Scale);
                    material.EnableKeyword("_NORMALMAP");

                    ApplyTextureTransform(def.NormalTexture, material, "_BumpMap");
                }

                if (def.OcclusionTexture != null)
                {
                    var texture = def.OcclusionTexture.Index;

                    material.SetFloat("_OcclusionStrength", (float)def.OcclusionTexture.Strength);

                    if (def.PbrMetallicRoughness != null &&
                        def.PbrMetallicRoughness.MetallicRoughnessTexture != null &&
                        def.PbrMetallicRoughness.MetallicRoughnessTexture.Index.Id == texture.Id)
                    {
                        material.EnableKeyword("OCC_METAL_ROUGH_ON");
                    }
                    else
                    {
                        material.SetTexture("_OcclusionMap", CreateTexture(texture.Value));

                        ApplyTextureTransform(def.OcclusionTexture, material, "_OcclusionMap");
                    }
                }

                if (def.EmissiveTexture != null)
                {
                    var texture = def.EmissiveTexture.Index.Value;
                    material.EnableKeyword("EMISSION_MAP_ON");
                    material.EnableKeyword("_EMISSION");
                    material.SetTexture("_EmissionMap", CreateTexture(texture));
                    material.SetInt("_EmissionUV", def.EmissiveTexture.TexCoord);

                    ApplyTextureTransform(def.EmissiveTexture, material, "_EmissionMap");
                }

                material.SetColor("_EmissionColor", def.EmissiveFactor.ToUnityColor());

                materialWrapper = new MaterialCacheData
                {
                    UnityMaterial = material,
                    UnityMaterialWithVertexColor = new UnityEngine.Material(material),
                    GLTFMaterial = def
                };

                materialWrapper.UnityMaterialWithVertexColor.EnableKeyword("VERTEX_COLOR_ON");

                if (materialIndex > 0)
                {
                    _assetCache.MaterialCache[materialIndex] = materialWrapper;
                }
            }

            return(materialIndex > 0 ? _assetCache.MaterialCache[materialIndex] : materialWrapper);
        }
예제 #39
0
        protected virtual UnityEngine.Material CreateMaterial(Material def, bool useVertexColors)
        {
            if (def.ContentsWithVC == null || def.ContentsWithoutVC == null)
            {
                Shader shader;

                // get the shader to use for this material
                try
                {
                    if (def.PbrMetallicRoughness != null)
                    {
                        shader = _shaderCache[MaterialType.PbrMetallicRoughness];
                    }
                    else if (_root.ExtensionsUsed != null && _root.ExtensionsUsed.Contains("KHR_materials_common") &&
                             def.CommonConstant != null)
                    {
                        shader = _shaderCache[MaterialType.CommonConstant];
                    }
                    else
                    {
                        shader = _shaderCache[MaterialType.PbrMetallicRoughness];
                    }
                }
                catch (KeyNotFoundException e)
                {
                    Debug.LogWarningFormat("No shader supplied for type of glTF material {0}, using Standard fallback", def.Name);
                    shader = Shader.Find("Standard");
                }

                shader.maximumLOD = MaximumLod;

                var material = new UnityEngine.Material(shader);

                if (def.AlphaMode == AlphaMode.MASK)
                {
                    material.SetOverrideTag("RenderType", "TransparentCutout");
                    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 = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
                    material.SetFloat("_Cutoff", (float)def.AlphaCutoff);
                }
                else if (def.AlphaMode == AlphaMode.BLEND)
                {
                    material.SetOverrideTag("RenderType", "Transparent");
                    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 = (int)UnityEngine.Rendering.RenderQueue.Transparent;
                }
                else
                {
                    material.SetOverrideTag("RenderType", "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;
                }

                if (def.DoubleSided)
                {
                    material.SetInt("_Cull", (int)CullMode.Off);
                }
                else
                {
                    material.SetInt("_Cull", (int)CullMode.Back);
                }

                if (def.PbrMetallicRoughness != null)
                {
                    var pbr = def.PbrMetallicRoughness;

                    material.SetColor("_Color", pbr.BaseColorFactor);

                    if (pbr.BaseColorTexture != null)
                    {
                        var texture = pbr.BaseColorTexture.Index.Value;
                        material.SetTexture("_MainTex", CreateTexture(texture));
                    }

                    material.SetFloat("_Metallic", (float)pbr.MetallicFactor);

                    if (pbr.MetallicRoughnessTexture != null)
                    {
                        var texture = pbr.MetallicRoughnessTexture.Index.Value;
                        material.SetTexture("_MetallicRoughnessMap", CreateTexture(texture));
                    }

                    material.SetFloat("_Roughness", (float)pbr.RoughnessFactor);
                }

                if (def.CommonConstant != null)
                {
                    material.SetColor("_AmbientFactor", def.CommonConstant.AmbientFactor);

                    if (def.CommonConstant.LightmapTexture != null)
                    {
                        material.EnableKeyword("LIGHTMAP_ON");

                        var texture = def.CommonConstant.LightmapTexture.Index.Value;
                        material.SetTexture("_LightMap", CreateTexture(texture));
                        material.SetInt("_LightUV", def.CommonConstant.LightmapTexture.TexCoord);
                    }

                    material.SetColor("_LightFactor", def.CommonConstant.LightmapFactor);
                }

                if (def.NormalTexture != null)
                {
                    var texture = def.NormalTexture.Index.Value;
                    material.SetTexture("_BumpMap", CreateTexture(texture));
                    material.SetFloat("_BumpScale", (float)def.NormalTexture.Scale);
                }

                if (def.OcclusionTexture != null)
                {
                    var texture = def.OcclusionTexture.Index;

                    material.SetFloat("_OcclusionStrength", (float)def.OcclusionTexture.Strength);

                    if (def.PbrMetallicRoughness != null &&
                        def.PbrMetallicRoughness.MetallicRoughnessTexture != null &&
                        def.PbrMetallicRoughness.MetallicRoughnessTexture.Index.Id == texture.Id)
                    {
                        material.EnableKeyword("OCC_METAL_ROUGH_ON");
                    }
                    else
                    {
                        material.SetTexture("_OcclusionMap", CreateTexture(texture.Value));
                    }
                }

                if (def.EmissiveTexture != null)
                {
                    var texture = def.EmissiveTexture.Index.Value;
                    material.EnableKeyword("EMISSION_MAP_ON");
                    material.SetTexture("_EmissionMap", CreateTexture(texture));
                    material.SetInt("_EmissionUV", def.EmissiveTexture.TexCoord);
                }

                material.SetColor("_EmissionColor", def.EmissiveFactor);

                def.ContentsWithoutVC = material;
                def.ContentsWithVC    = new UnityEngine.Material(material);
                def.ContentsWithVC.EnableKeyword("VERTEX_COLOR_ON");
            }

            return(def.GetContents(useVertexColors));
        }
예제 #40
0
		//material
		public static void EnableBlending(Material mat, bool enable) {
			if(!internalBlendingSupport) return;
			if(enable) {
				mat.EnableKeyword("MARMO_SKY_BLEND_ON");
				mat.DisableKeyword("MARMO_SKY_BLEND_OFF");
			} else {
				mat.DisableKeyword("MARMO_SKY_BLEND_ON");
				mat.EnableKeyword("MARMO_SKY_BLEND_OFF");
			}
		}
예제 #41
0
		//material
		public static void EnableProjection(Material mat, bool enable) {
			if(!internalProjectionSupport) return;
			if(enable) {
				mat.EnableKeyword("MARMO_BOX_PROJECTION_ON");
				mat.DisableKeyword("MARMO_BOX_PROJECTION_OFF");
			} else {
				mat.DisableKeyword("MARMO_BOX_PROJECTION_ON");
				mat.EnableKeyword("MARMO_BOX_PROJECTION_OFF");
			}
		}
예제 #42
0
    private void SetSkyQuality(Material material)
    {
        switch (SkyQuality)
        {
            case TOD_SkyQualityType.PerVertex:
                material.EnableKeyword("PER_VERTEX");
                material.DisableKeyword("PER_PIXEL");
                break;

            case TOD_SkyQualityType.PerPixel:
                material.DisableKeyword("PER_VERTEX");
                material.EnableKeyword("PER_PIXEL");
                break;
        }
    }
        private UnityEngine.Material CreateMaterial(Material def, bool useVertexColors)
        {
            UnityEngine.Material material = new UnityEngine.Material(useVertexColors ? ColorMaterial : NoColorMaterial);

            material.shader.maximumLOD = MaximumLod;

            if (def.AlphaMode == AlphaMode.MASK)
            {
                material.SetOverrideTag("RenderType", "TransparentCutout");
                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 = (int)UnityEngine.Rendering.RenderQueue.AlphaTest;
                material.SetFloat("_Cutoff", (float)def.AlphaCutoff);
            }
            else if (def.AlphaMode == AlphaMode.BLEND)
            {
                material.SetOverrideTag("RenderType", "Transparent");
                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 = (int)UnityEngine.Rendering.RenderQueue.Transparent;
            }
            else
            {
                material.SetOverrideTag("RenderType", "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;
            }

            if (def.DoubleSided)
            {
                material.SetInt("_Cull", (int)CullMode.Off);
            }
            else
            {
                material.SetInt("_Cull", (int)CullMode.Back);
            }

            if (useVertexColors)
            {
                material.EnableKeyword("VERTEX_COLOR_ON");
            }

            if (def.PbrMetallicRoughness != null)
            {
                var pbr = def.PbrMetallicRoughness;

                material.SetColor("_Color", pbr.BaseColorFactor);

                if (pbr.BaseColorTexture != null)
                {
                    var texture = pbr.BaseColorTexture.Index.Value;
                    material.SetTexture("_MainTex", _imageCache[texture.Source.Value]);
                }

                material.SetFloat("_Metallic", (float)pbr.MetallicFactor);

                if (pbr.MetallicRoughnessTexture != null)
                {
                    var texture = pbr.MetallicRoughnessTexture.Index.Value;
                    material.SetTexture("_MetallicRoughnessMap", _imageCache[texture.Source.Value]);
                }

                material.SetFloat("_Roughness", (float)pbr.RoughnessFactor);
            }

            if (def.CommonConstant != null)
            {
                material.SetColor("_AmbientFactor", def.CommonConstant.AmbientFactor);

                if (def.CommonConstant.LightmapTexture != null)
                {
                    material.EnableKeyword("LIGHTMAP_ON");

                    var texture = def.CommonConstant.LightmapTexture.Index.Value;
                    material.SetTexture("_LightMap", _imageCache[texture.Source.Value]);
                    material.SetInt("_LightUV", def.CommonConstant.LightmapTexture.TexCoord);
                }

                material.SetColor("_LightFactor", def.CommonConstant.LightmapFactor);
            }

            if (def.NormalTexture != null)
            {
                var texture = def.NormalTexture.Index.Value;
                material.EnableKeyword("_NORMALMAP");
                material.SetTexture("_BumpMap", _imageCache[texture.Source.Value]);
                material.SetFloat("_BumpScale", (float)def.NormalTexture.Scale);
            }
            else
            {
                material.SetTexture("_BumpMap", null);
                material.DisableKeyword("_NORMALMAP");
            }

            if (def.OcclusionTexture != null)
            {
                var texture = def.OcclusionTexture.Index;

                material.SetFloat("_OcclusionStrength", (float)def.OcclusionTexture.Strength);

                if (def.PbrMetallicRoughness != null &&
                    def.PbrMetallicRoughness.MetallicRoughnessTexture.Index.Id == texture.Id)
                {
                    material.EnableKeyword("OCC_METAL_ROUGH_ON");
                }
                else
                {
                    material.SetTexture("_OcclusionMap", _imageCache[texture.Value.Source.Value]);
                }
            }

            if (def.EmissiveTexture != null)
            {
                var texture = def.EmissiveTexture.Index.Value;
                material.EnableKeyword("_EMISSION");
                material.EnableKeyword("EMISSION_MAP_ON");
                material.SetTexture("_EmissionMap", _imageCache[texture.Source.Value]);
                material.SetInt("_EmissionUV", def.EmissiveTexture.TexCoord);
            }

            material.SetColor("_EmissionColor", def.EmissiveFactor);

            return(material);
        }
예제 #44
0
        public void SetMaterialRenderMode(Material m, float newMode)
        {
            m.SetFloat("_Mode", newMode);
            var integerRenderMode = Mathf.RoundToInt(newMode);

            switch (integerRenderMode) {
                case 0:
                    m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                    m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                    m.SetInt("_ZWrite", 1);
                    m.DisableKeyword("_ALPHATEST_ON");
                    m.DisableKeyword("_ALPHABLEND_ON");
                    m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                    m.renderQueue = -1;
                    break;
                case 1:
                    m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                    m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
                    m.SetInt("_ZWrite", 1);
                    m.EnableKeyword("_ALPHATEST_ON");
                    m.DisableKeyword("_ALPHABLEND_ON");
                    m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                    m.renderQueue = 2450;
                    break;
                case 2:
                    m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
                    m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                    m.SetInt("_ZWrite", 0);
                    m.DisableKeyword("_ALPHATEST_ON");
                    m.EnableKeyword("_ALPHABLEND_ON");
                    m.DisableKeyword("_ALPHAPREMULTIPLY_ON");
                    m.renderQueue = 3000;
                    break;
                case 3:
                    m.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
                    m.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
                    m.SetInt("_ZWrite", 0);
                    m.DisableKeyword("_ALPHATEST_ON");
                    m.DisableKeyword("_ALPHABLEND_ON");
                    m.EnableKeyword("_ALPHAPREMULTIPLY_ON");
                    m.renderQueue = 3000;
                    break;
            }
        }
예제 #45
0
        // Enable Masking in the Shader
        void EnableMasking()
        {
            if (m_fontMaterial == null)
            {
                m_fontMaterial = CreateMaterialInstance(m_sharedMaterial);
                m_uiRenderer.SetMaterial(m_fontMaterial, m_sharedMaterial.mainTexture);
            }

            m_sharedMaterial = m_fontMaterial;
            if (m_sharedMaterial.HasProperty(ShaderUtilities.ID_ClipRect))
            {
                m_sharedMaterial.EnableKeyword(ShaderUtilities.Keyword_MASK_SOFT);
                m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_HARD);
                m_sharedMaterial.DisableKeyword(ShaderUtilities.Keyword_MASK_TEX);

                UpdateMask(); // Update Masking Coordinates
            }

            m_isMaskingEnabled = true;

            //m_uiRenderer.SetMaterial(m_sharedMaterial, null);

            //m_padding = ShaderUtilities.GetPadding(m_sharedMaterial, m_enableExtraPadding, m_isUsingBold);
            //m_alignmentPadding = ShaderUtilities.GetFontExtent(m_sharedMaterial);

            /*
            Material mat = m_uiRenderer.GetMaterial();
            if (mat.HasProperty(ShaderUtilities.ID_MaskCoord))
            {
                mat.EnableKeyword("MASK_SOFT");
                mat.DisableKeyword("MASK_HARD");
                mat.DisableKeyword("MASK_OFF");

                m_isMaskingEnabled = true;
                UpdateMask();
            }
            */
        }
	public static void switchKeyword (Material mat, string keyword1, string keyword2, bool on){
		if(on) { mat.EnableKeyword(keyword1);  mat.DisableKeyword(keyword2); }
		 else { mat.EnableKeyword(keyword2);  mat.DisableKeyword(keyword1); }
	}