private Texture2D RetriveMipmapFromTam(int mipmapLevel)
        {
            var size = new IntVector2((int)(Tam.width / Mathf.Pow(2, mipmapLevel)), (int)(Tam.height / Mathf.Pow(2, mipmapLevel)));
            var tx   = new Texture2D(size.X, size.Y, Tam.format, false);

            tx.SetPixels32(Tam.GetPixels32(TamLevel, mipmapLevel));
            tx.Apply(false);
            return(tx);
        }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        if (webCamTexture.width > 100)
        {
            if (init == false)
            {
                Init();
                init = true;
            }

            try
            {
                smallTex = TextureScaler.scaled(webCamTexture, width, height);

                for (int i = 0; i < texArray.depth - 1; i++)
                {
                    texArray.SetPixels32(texArray.GetPixels32(i + 1), i);
                }

                texArray.SetPixels32(smallTex.GetPixels32(), texArray.depth - 1);
                texArray.Apply();

                Destroy(smallTex);
            }
            catch (System.Exception e)
            {
            }
        }
    }
Пример #3
0
 public static bool PopulateImageData(Texture2DArray texture, int index, ref ImageData texdata)
 {
     if (!PopulateImageData(texture as Texture, ref texdata))
     {
         return(false);
     }
     texdata.depth       = 1;
     texdata.format      = VkFormat.R8G8B8A8_UNORM;
     texdata.pixels      = NativeUtils.ToNative(Color32ArrayToByteArray(texture.GetPixels32(index, 0)));
     texdata.mipmapCount = 1;
     return(true);
 }
    public static int GetPixels32(IntPtr l)
    {
        int result;

        try
        {
            int num = LuaDLL.lua_gettop(l);
            if (num == 2)
            {
                Texture2DArray texture2DArray = (Texture2DArray)LuaObject.checkSelf(l);
                int            arrayElement;
                LuaObject.checkType(l, 2, out arrayElement);
                Color32[] pixels = texture2DArray.GetPixels32(arrayElement);
                LuaObject.pushValue(l, true);
                LuaObject.pushValue(l, pixels);
                result = 2;
            }
            else if (num == 3)
            {
                Texture2DArray texture2DArray2 = (Texture2DArray)LuaObject.checkSelf(l);
                int            arrayElement2;
                LuaObject.checkType(l, 2, out arrayElement2);
                int miplevel;
                LuaObject.checkType(l, 3, out miplevel);
                Color32[] pixels2 = texture2DArray2.GetPixels32(arrayElement2, miplevel);
                LuaObject.pushValue(l, true);
                LuaObject.pushValue(l, pixels2);
                result = 2;
            }
            else
            {
                LuaObject.pushValue(l, false);
                LuaDLL.lua_pushstring(l, "No matched override function GetPixels32 to call");
                result = 2;
            }
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Пример #5
0
    // Draw the texture on the screen to see it.
    void OnGUI()
    {
        if (tex2DArrRead != null)
        {
            layer = new Texture2D(width, height, TextureFormat.ARGB32, true);

            // Just copy one layer.
            layerID = Mathf.Clamp(layerID, 0, layerCount - 1);
            layer.SetPixels32(tex2DArrRead.GetPixels32(layerID, 0), 0);
            layer.Apply();

            int drawWidth  = 1024;
            int drawHeight = 1024;
            int w          = drawWidth;
            int h          = drawHeight;
            int sw         = Screen.width / 2;
            int sh         = Screen.height / 2;

            // Draw the texture on the screen to test array contents.
            Rect rect = new Rect(sw - w / 2, sh - h / 2, drawWidth, drawHeight);
            GUI.DrawTexture(rect, layer, ScaleMode.ScaleToFit, false);
        }
    }
Пример #6
0
    public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties)
    {
        EditorGUILayout.HelpBox("Please note that params marked with '*' must be synced across bark, leaf and maybe even the billboard material.", MessageType.Info);

        base.OnGUI(materialEditor, properties);
        Material targetMat = materialEditor.target as Material;

        //  Bark texture2D
        if (targetMat.HasProperty("_BumpSpecAOMap"))
        {
            if (targetMat.GetTexture("_BumpSpecAOMap") == null)
            {
                targetMat.SetTexture("_BumpSpecAOMap", Resources.Load("CTI_default_normal_spec_ao") as Texture2D);
            }
        }
        //  Bark textureArray
        else if (targetMat.HasProperty("_BumpSpecAOMapArray"))
        {
            if (targetMat.GetTexture("_BumpSpecAOMapArray") == null)
            {
                targetMat.SetTexture("_BumpSpecAOMapArray", Resources.Load("CTI_default_normal_spec_ao_Texture2DArray") as Texture2DArray);
            }
        }

        //  Assign default combined detail texture
        if (targetMat.HasProperty("_DetailNormalMapX"))
        {
            if (targetMat.GetTexture("_DetailNormalMapX") == null)
            {
                targetMat.SetTexture("_DetailNormalMapX", Resources.Load("CTI_default_normal_spec_ao") as Texture2D);
            }
        }

        //  Leaves
        if (targetMat.HasProperty("_BumpSpecMap"))
        {
            if (targetMat.GetTexture("_BumpSpecMap") == null)
            {
                targetMat.SetTexture("_BumpSpecMap", Resources.Load("CTI_default_normal_spec") as Texture2D);
            }
        }
        if (targetMat.HasProperty("_TranslucencyMap"))
        {
            if (targetMat.GetTexture("_TranslucencyMap") == null)
            {
                targetMat.SetTexture("_TranslucencyMap", Resources.Load("CTI_default_ao_trans_smoothness") as Texture2D);
            }
        }


        //  Get average color
        if (targetMat.HasProperty("_AverageCol"))
        {
            GUILayout.Space(8);
            if (GUILayout.Button("Get average Color"))
            {
                if (targetMat.HasProperty("_MainTex") && targetMat.GetTexture("_MainTex") != null)
                {
                    getAverageColor(targetMat.GetTexture("_MainTex") as Texture2D);
                }
                else if (targetMat.HasProperty("_MainTexArray") && targetMat.GetTexture("_MainTexArray") != null)
                {
                    Texture2DArray sourceTex = targetMat.GetTexture("_MainTexArray") as Texture2DArray;
                    Color32[]      aColor    = sourceTex.GetPixels32(0, 1);
                    avrgCol = aColor[0];
                }
                targetMat.SetColor("_AverageCol", avrgCol);
            }
        }


        GUILayout.Space(8);
    }