Beispiel #1
0
 public UnityEngine.Texture GetUnityTexture()
 {
     if (texture == null)
     {
         texture = LoadTexture();
     }
     return(texture.GetUnityTexture());
 }
Beispiel #2
0
        public static UnityEngine.Material GetMaterial(Blending blending, bool zTestMode, bool zWriteMode, ShaderId shaderId, ITexture texture1, ITexture texture2)
        {
            UnityEngine.Material mat;
            var texCount = texture1 != null ? (texture2 != null ? 2 : 1) : 0;

            switch (shaderId)
            {
            case ShaderId.Silhuette:
                mat = texCount == 2 ? silhuetteWith2TexturesMat : silhuetteMat;
                break;

            default:
                if (texCount == 1 && shaderId == ShaderId.InversedSilhuette)
                {
                    mat = silhuetteInversedMat;
                    break;
                }
                mat = texCount == 2 ? imageCombinerMat : (texCount == 1 ?
                                                          (ThreeDimensionalRendering ? diffuseMat3d : diffuseMat) : flatMat);
                if (texCount == 1 && texture1 is MovieTexture)
                {
                    mat = movieWithSeparateAlphaMat;
                }
                break;
            }
            if (mat == movieWithSeparateAlphaMat)
            {
                mat.mainTexture = texture1.GetUnityTexture();
                mat.SetTexture("SecondTex", texture1.AlphaTexture.GetUnityTexture());
            }
            else
            {
                if (texture1 != null)
                {
                    mat.mainTexture = texture1.GetUnityTexture();
                }
                if (texture2 != null)
                {
                    mat.SetTexture("SecondTex", texture2.GetUnityTexture());
                }
            }
            UnityEngine.Rendering.BlendMode srcMode, dstMode;
            switch (blending)
            {
            case Blending.Add:
            case Blending.Glow:
                srcMode = Renderer.PremultipliedAlphaMode ?
                          UnityEngine.Rendering.BlendMode.One : UnityEngine.Rendering.BlendMode.SrcAlpha;
                dstMode = UnityEngine.Rendering.BlendMode.One;
                break;

            case Blending.Burn:
            case Blending.Darken:
                srcMode = UnityEngine.Rendering.BlendMode.DstColor;
                dstMode = UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha;
                break;

            case Blending.Modulate:
                srcMode = UnityEngine.Rendering.BlendMode.DstColor;
                dstMode = UnityEngine.Rendering.BlendMode.Zero;
                break;

            case Blending.Inherited:
            case Blending.Alpha:
            default:
                srcMode = Renderer.PremultipliedAlphaMode ?
                          UnityEngine.Rendering.BlendMode.One : UnityEngine.Rendering.BlendMode.SrcAlpha;
                dstMode = UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha;
                break;
            }
            mat.SetInt("BlendSrcMode", (int)srcMode);
            mat.SetInt("BlendDstMode", (int)dstMode);
            //mat.SetInt("ZWriteMode", zWriteMode ? 1 : 0);
            mat.SetInt("ZTestMode", zTestMode ? (int)UnityEngine.Rendering.CompareFunction.LessEqual : (int)UnityEngine.Rendering.CompareFunction.Always);
            return(mat);
        }