Esempio n. 1
0
    void Build()
    {
        array = new Texture2DArray(ga.Strokes, 1, count, TextureFormat.RGBAFloat, false);
        array.Apply();

        lines = new FboPingpong(count, 2, RenderTextureFormat.ARGBFloat, FilterMode.Point);
        Graphics.Blit(null, lines.ReadTex, updateMat, (int)LinesRenderMode.Init);

        feedback            = new Texture2D(count, 2, TextureFormat.RGBAFloat, false);
        feedback.filterMode = FilterMode.Point;
        feedback.Apply();

        for (int i = 0; i < count; i++)
        {
            var cr = ga.Nematodes[i % ga.Nematodes.Count];
            Graphics.CopyTexture(cr.GetTexture(), 0, 0, array, i, 0);
        }
        array.Apply();

        var gradTex = new Texture2D(count, 1);

        for (int i = 0; i < count; i++)
        {
            gradTex.SetPixel(i, 0, grad.Evaluate(1f * i / count));
        }
        gradTex.Apply();

        visualizeMat.SetTexture("_Lines", lines.ReadTex);
        visualizeMat.SetTexture("_Nematodes", array);
        visualizeMat.SetFloat("_Depth", count);
        visualizeMat.SetVector("_Strokes", new Vector4(ga.Strokes, 1f / ga.Strokes, (1f / ga.Strokes) * 0.5f, -1f));
        visualizeMat.SetTexture("_Gradient", gradTex);

        var mesh     = new Mesh();
        var vertices = new Vector3[count];
        var uv       = new Vector2[count];
        var inv      = 1f / count;
        var hinv     = inv * 0.5f;
        var indices  = new int[count];

        for (int i = 0; i < count; i++)
        {
            var idx = i;
            var t   = i * inv + hinv;
            vertices[idx] = Random.insideUnitSphere;
            uv[idx]       = new Vector2(0f, t);
            indices[idx]  = idx;
        }

        mesh.vertices = vertices;
        mesh.uv       = uv;
        mesh.SetIndices(indices, MeshTopology.Points, 0);
        mesh.RecalculateBounds();

        GetComponent <MeshFilter>().sharedMesh = mesh;
    }
        public static void SetTexture(this Texture2DArray dstArr, Texture2D src, int dstCh, bool apply = true)
        {
            //Debug.Log("Setting Texture " + src.name + " " + System.IO.Path.GetFileName(UnityEditor.AssetDatabase.GetAssetPath(src)) + " " + src.imageContentsHash);

            if (dstArr.depth <= dstCh)
            {
                throw new System.IndexOutOfRangeException("Trying to set channel (" + dstCh + ") >= depth (" + dstArr.depth + ")");
            }

            //quick case if size and format match
            if (src.width == dstArr.width && src.height == dstArr.height && src.format == dstArr.format)
            {
                Graphics.CopyTexture(src, 0, dstArr, dstCh);
                if (apply)
                {
                    dstArr.Apply(updateMipmaps: false);
                }
                return;
            }

            if (!src.IsReadable())
            {
                src = src.ReadableClone();                                 //texture should be readable to uncompress
            }
            if (src.format.IsCompressed())
            {
                src = src.UncompressedClone();
            }

            if (src.width != dstArr.width || src.height != dstArr.height)
            {
                src = src.ResizedClone(dstArr.width, dstArr.height);
            }

                        #if UNITY_EDITOR
                        #if UNITY_2018_3_OR_NEWER
            UnityEditor.EditorUtility.CompressTexture(src, dstArr.format, 100);                            //de-compress and compress to change the format
                        #else
            UnityEditor.EditorUtility.CompressTexture(src, dstArr.format, TextureCompressionQuality.Best); //de-compress and compress to change the format
                        #endif
                        #else
            if (dstArr.format.IsCompressed())
            {
                src.Compress(true);
            }
                        #endif
            src.Apply(updateMipmaps: false);

            Graphics.CopyTexture(src, 0, dstArr, dstCh);
            if (apply)
            {
                dstArr.Apply(updateMipmaps: false);
            }
        }
Esempio n. 3
0
    public void UpdateData(Material material, float minHeight, float maxHeight)
    {
        this.minHeight = minHeight;
        this.maxHeight = maxHeight;

        material.SetInt("layerCount", layers.Length);
        material.SetFloat("minHeight", minHeight);
        material.SetFloat("maxHeight", maxHeight);
        material.SetColorArray("baseColors", layers.Select(x => x.tint).ToArray());
        material.SetFloatArray("baseStartHeights", layers.Select(x => x.startHeight).ToArray());
        material.SetFloatArray("baseBlends", layers.Select(x => x.blendStrength).ToArray());
        material.SetFloatArray("baseColorStrength", layers.Select(x => x.tintStrength).ToArray());
        material.SetFloatArray("baseTextureScales", layers.Select(x => x.textureScale).ToArray());

        Texture2D[]    textures     = layers.Select(x => x.texture).ToArray();
        Texture2DArray textureArray = new Texture2DArray(textureSize, textureSize, layers.Length, textureFormat, true);

        for (int i = 0; i < textures.Length; i++)
        {
            textureArray.SetPixels(textures[i].GetPixels(), i);
        }
        textureArray.Apply();

        material.SetTexture("baseTextures", textureArray);
    }
Esempio n. 4
0
            public void Build()
            {
                m_InitPreFGD = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/PreIntegratedFGD");

                // TODO: switch to RGBA64 when it becomes available.
                m_PreIntegratedFGD            = new RenderTexture(128, 128, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear);
                m_PreIntegratedFGD.filterMode = FilterMode.Bilinear;
                m_PreIntegratedFGD.wrapMode   = TextureWrapMode.Clamp;
                m_PreIntegratedFGD.Create();

                m_LtcData = new Texture2DArray(k_LtcLUTResolution, k_LtcLUTResolution, 3, TextureFormat.RGBAHalf, false /*mipmap*/, true /* linear */)
                {
                    hideFlags  = HideFlags.HideAndDontSave,
                    wrapMode   = TextureWrapMode.Clamp,
                    filterMode = FilterMode.Bilinear
                };

                LoadLUT(m_LtcData, 0, TextureFormat.RGBAHalf, s_LtcGGXMatrixData);
                LoadLUT(m_LtcData, 1, TextureFormat.RGBAHalf, s_LtcDisneyDiffuseMatrixData);
                // TODO: switch to RGBA64 when it becomes available.
                LoadLUT(m_LtcData, 2, TextureFormat.RGBAHalf, s_LtcGGXMagnitudeData, s_LtcGGXFresnelData, s_LtcDisneyDiffuseMagnitudeData);

                m_LtcData.Apply();

                isInit = false;
            }
Esempio n. 5
0
    void LateUpdate()
    {
        generationsLabel.text = ga.Generations.ToString();

        Graphics.Blit(lines.ReadTex, lines.WriteTex, updateMat, (int)LinesRenderMode.Update);
        lines.Swap();

        var prev = RenderTexture.active;

        {
            RenderTexture.active = lines.ReadTex;
            feedback.ReadPixels(new Rect(0.0f, 0.0f, lines.ReadTex.width, lines.ReadTex.height), 0, 0, false);
            feedback.Apply();

            bool flag = false;
            for (int x = 0; x < count; x++)
            {
                var line = feedback.GetPixel(x, 0);
                if (line.r >= 1f)
                {
                    flag = true;
                    Reset(x);
                }
            }
            if (flag)
            {
                array.Apply();
            }
        }
        RenderTexture.active = prev;

        Graphics.Blit(lines.ReadTex, lines.WriteTex, updateMat, (int)LinesRenderMode.Birth);
        lines.Swap();
    }
Esempio n. 6
0
    public void SetMaterialData(CloudAPI.FileParameterDataBin data, int layer)
    {
        int            num_dates = data.info.num_dates;
        int            w         = data.info.width;
        int            h         = data.info.height;
        int            l         = data.info.num_layers;
        int            offset    = w * h * layer;
        Texture2DArray array     = new Texture2DArray(w, h, num_dates, TextureFormat.RFloat, false, false);

        for (int t = 0; t < num_dates; t++)
        {
            array.SetPixelData <float>(data.data, 0, t, l * w * h * t + offset);
        }
        array.Apply(false);
        material.SetTexture("Texture2DArray_28e7e253cb18486a8c14899af2143136", array);                                     // Textures
        material.SetVector("Vector2_540929bd5a9e4b91803993f7ccde8e73", new Vector4(data.info.lon_min, data.info.lon_max)); // LonMinMax
        material.SetVector("Vector2_a03a182a418a49fd8146e64479d05bb6", new Vector4(data.info.lat_min, data.info.lat_max)); // LatMinMax
        material.SetFloat("Vector1_8211db379e8f4f01b70f108ef594b658", data.info.width);                                    // Width
        material.SetFloat("Vector1_51fb8cd46af548f6af8aef823b6bffa7", 0);                                                  // Overlay Opacity
        // material.SetFloat("Vector1_eb79a7293bb64596949928ce17eb143b", 0); // Texture Index

        currentLayer = layer;
        currentData  = data;

        ResetRange();
    }
Esempio n. 7
0
    private void LoadTextures(string[] texturePaths, Material chunkMaterial)
    {
        int            mipMapCount  = 1 + (int)Math.Floor(Math.Log(Math.Max(16, 16)));
        Texture2DArray textureArray = new Texture2DArray(16, 16, texturePaths.Length, TextureFormat.RGBA32, mipMapCount, false)
        {
            filterMode = FilterMode.Point
        };

        for (int i = 0; i < texturePaths.Length; i++)
        {
            string texturePath = texturePaths[i];
            if (!File.Exists(texturePath))
            {
                throw new FileNotFoundException("The provided path does not contain an image file!");
            }

            Texture2D textureData = new Texture2D(16, 16, TextureFormat.RGBA32, true, false);
            if (!textureData.LoadImage(File.ReadAllBytes(texturePath)))
            {
                throw new Exception("The provided image did not load correctly! Ensure that the file is a 32bit RGBA PNG, and that it isn't corrupted!");
            }

            textureData.Apply(true);

            for (int j = 0; j < mipMapCount; j++)
            {
                textureArray.SetPixelData(textureData.GetPixels32(j), j, i);
            }
        }

        textureArray.Apply(true);

        chunkMaterial.SetTexture("_TextureArray", textureArray);
    }
    public void CreateAsset(Texture2DArrayDescriptor descriptor)
    {
        Texture2D[] textures = descriptor.Sources;

        Texture2DArray array = new Texture2DArray(textures[0].width, textures[0].height, textures.Length, descriptor.TextureFormat, true);

        for (int i = 0; i < textures.Length; i++)
        {
            UnityEngine.Graphics.CopyTexture(textures[i], 0, array, i);
        }

        // to set the isReadable to false;
        array.Apply(false, true);
        string textureArrayPath = null;

        if (descriptor.Texture2DArray == null)
        {
            string descriptorPath = UnityEditor.AssetDatabase.GetAssetPath(descriptor);
            textureArrayPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(descriptorPath),
                                                      System.IO.Path.GetFileNameWithoutExtension(descriptorPath) + "TA.asset");
        }
        else
        {
            textureArrayPath = UnityEditor.AssetDatabase.GetAssetPath(descriptor.Texture2DArray);
        }


        UnityEditor.AssetDatabase.CreateAsset(array, textureArrayPath);
        this.needReload.Add(new System.Collections.Generic.KeyValuePair <Texture2DArrayDescriptor, string>(descriptor, textureArrayPath));
        this.needAssetDatabaseRefresh = true;
    }
Esempio n. 9
0
    //CREATE TEXTURE2DARRAY UNITY TYPE
    public static Texture2DArray CreateTexture2DArray(int w, int h, int d, Texture2D[] slices)
    {
        // Create Texture2DArray
        Texture2DArray texture2DArray = new Texture2DArray(w, h, d, TextureFormat.RGBA32, true, false);

        // Apply settings
        texture2DArray.wrapMode   = TextureWrapMode.Clamp;
        texture2DArray.filterMode = FilterMode.Bilinear;
        texture2DArray.anisoLevel = 6;

        Debug.Log($"Creating 2DTextureArray");

        // Loop through ordinary textures and copy pixels to the Texture2DArray
        for (int i = 0; i < slices.Length; i++)
        {
            texture2DArray.SetPixels(slices[i].GetPixels(0),
                                     i, 0);
        }

        Debug.Log($"Textures Loaded: {slices.Length}");

        // Apply our changes
        texture2DArray.Apply();

        Debug.Log($"Texture2DArray created");

        return(texture2DArray);
    }
Esempio n. 10
0
    IEnumerator Record()
    {
        yield return(fix);

        foreach (var i in targetAnimators)
        {
            i.Play(stateName, -1, 0);
        }
        int frameCount = (int)(targetFPS * targetSecond);

        readPixelShader.SetBuffer(0, "_TextureDatas", texDataBuffer);
        readPixelShader.SetTexture(0, "_TargetTexture", tempRT);
        readPixelShader.SetInt("_Width", targetSize);
        readPixelShader.SetInt("_Height", targetSize);
        for (int i = 0; i < frameCount; ++i)
        {
            cam.Render();
            readPixelShader.Dispatch(0, targetSize / 8, targetSize / 8, 1);
            texDataBuffer.GetData(colorArray);
            result.SetPixels(colorArray, i, 0);
            yield return(fix);
        }
        result.Apply();
        UnityEditor.AssetDatabase.CreateAsset(result, dataPath);
        Debug.Log("Finish");
        FinishSettings();
    }
Esempio n. 11
0
    public void SetUpTexture2DArrays()
    {
        if (customTerrainMaterial)
        {
            int _resolution = splats[0].terrainLayer.diffuseTexture.width;
            int _layerCount = splats.Length;

            texture2DArray_diffuse = new Texture2DArray(_resolution, _resolution, _layerCount, TextureFormat.RGBA32, true);
            texture2DArray_normal  = new Texture2DArray(_resolution, _resolution, _layerCount, TextureFormat.RGBA32, true);
            texture2DArray_height  = new Texture2DArray(_resolution, _resolution, _layerCount, TextureFormat.RGBA32, true);

            for (int i = 0; i < _layerCount; i++)
            {
                texture2DArray_diffuse.SetPixels32(splats[i].terrainLayer.diffuseTexture.GetPixels32(), i, 0);
                texture2DArray_normal.SetPixels32(splats[i].terrainLayer.normalMapTexture.GetPixels32(), i, 0);
                texture2DArray_height.SetPixels32(splats[i].terrainLayer.maskMapTexture.GetPixels32(), i, 0);
            }

            texture2DArray_diffuse.Apply();
            texture2DArray_normal.Apply();
            texture2DArray_height.Apply();


            customTerrainMaterial.SetTexture(NameIDs._TextureArrayDiffuse, texture2DArray_diffuse);
            customTerrainMaterial.SetTexture(NameIDs._TextureArrayNormal, texture2DArray_normal);
            customTerrainMaterial.SetTexture(NameIDs._TextureArrayMOHS, texture2DArray_height);
        }
    }
    /// <summary>
    /// Updates the Texture2DArray asset.
    /// </summary>
    public void Rebuild()
    {
        if (Validate())
        {
            Texture2DArray texture2DArray = new Texture2DArray(m_width, m_height, m_textures.Length, m_format, true);

            for (int i = 0; i < m_textures.Length; i++)
            {
                for (int m = 0; m < m_textures [i].mipmapCount; m++)
                {
                    Graphics.CopyTexture(m_textures [i], 0, m, texture2DArray, i, m);
                }
            }

            texture2DArray.name       = name;
            texture2DArray.anisoLevel = m_aniso;
            texture2DArray.wrapModeU  = m_wrapModeU;
            texture2DArray.wrapModeV  = m_wrapModeV;
            texture2DArray.Apply(false, true);

            if (m_texture2DArray == null)
            {
                m_texture2DArray = texture2DArray;
                AssetDatabase.AddObjectToAsset(m_texture2DArray, this);
            }
            else
            {
                EditorUtility.CopySerialized(texture2DArray, m_texture2DArray);
            }

            AssetDatabase.SaveAssets();
        }
    }
    static void Create()
    {
        // CHANGEME: Filepath must be under "Resources" and named appropriately. Extension is ignored.
        // {0:000} means zero padding of 3 digits, i.e. 001, 002, 003 ... 010, 011, 012, ...
        string filePattern = "depth_{0:000}";

        // CHANGEME: Number of textures you want to add in the array
        int slices = 15;

        // CHANGEME: TextureFormat.RGB24 is good for PNG files with no alpha channels. Use TextureFormat.RGB32 with alpha.
        // See Texture2DArray in unity scripting API.
        Texture2DArray textureArray = new Texture2DArray(512, 512, slices, TextureFormat.ARGB32, true);

        // CHANGEME: If your files start at 001, use i = 1. Otherwise change to what you got.
        for (int i = 1; i <= slices; i++)
        {
            string filename = string.Format(filePattern, i);
            Debug.Log("Loading " + filename);
            Texture2D tex = (Texture2D)Resources.Load(filename);
            textureArray.SetPixels(tex.GetPixels(0), i, 0);
        }
        textureArray.Apply();

        // CHANGEME: Path where you want to save the texture array. It must end in .asset extension for Unity to recognise it.
        string path = "Assets/Resources/DepthtextureArray.asset";

        AssetDatabase.CreateAsset(textureArray, path);
        Debug.Log("Saved asset to " + path);
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        if (GUILayout.Button("Generate"))
        {
            Texture2DArrayData component      = (Texture2DArrayData)target;
            Texture2D[]        textures       = component.textures;
            Texture2DArray     texture2DArray = new Texture2DArray(
                textures[0].width, textures[0].height, textures.Length, TextureFormat.RGBA32, true);

            for (int i = 0; i < textures.Length; i++)
            {
                texture2DArray.SetPixels32(textures[i].GetPixels32(), i);
            }
            texture2DArray.Apply();

            AssetDatabase.CreateAsset(texture2DArray, "Assets/Textures/" + component.name + ".asset");

            GameObject exampleMesh = GameObject.Find("ExampleTerrainMesh");
            Shader     texturedDynamicTerrainShader = exampleMesh.GetComponent <Shader>();

            component.NotifyOfUpdatedValues();
            EditorUtility.SetDirty(target);
        }
    }
        public void MakeArray()
        {
            string filePattern = prefix + "_{0:000}";

            Debug.Log(filePattern + ".png");

            // CHANGEME: TextureFormat.RGB24 is good for PNG files with no alpha channels. Use TextureFormat.RGB32 with alpha.
            // See Texture2DArray in unity scripting API.
            Texture2DArray textureArray = new Texture2DArray(resolution, resolution, slices, TextureFormat.ARGB32, true);

            // CHANGEME: If your files start at 001, use i = 1. Otherwise change to what you got.
            for (int i = 1; i <= slices; i++)
            {
                string filename = string.Format(filePattern, i);
                Debug.Log("Loading " + filename + ".png");
                // Texture2D tex = (Texture2D)Resources.Load(filename);
                Texture2D tex = LoadPNG(filename + ".png", 512);
                Debug.Log(filePattern + ".png");
                textureArray.SetPixels(tex.GetPixels(0), i - 1, 0);
            }
            textureArray.Apply();

            // CHANGEME: Path where you want to save the texture array. It must end in .asset extension for Unity to recognise it.
            string path = "Assets/Resources/texArray.asset";

            UnityEditor.AssetDatabase.CreateAsset(textureArray, path);
            Debug.Log("Saved asset to " + path);
        }
Esempio n. 16
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)
            {
            }
        }
    }
    private void CreateTextureArray(Texture2D[] ordinaryTextures)
    {
        // Create Texture2DArray
        Texture2DArray texture2DArray = new
                                        Texture2DArray(ordinaryTextures[0].width,
                                                       ordinaryTextures[0].height, ordinaryTextures.Length,
                                                       TextureFormat.RGBA32, true, false);

        // Apply settings
        texture2DArray.filterMode = FilterMode.Bilinear;
        texture2DArray.wrapMode   = TextureWrapMode.Repeat;
        // Loop through ordinary textures and copy pixels to the
        // Texture2DArray
        for (int i = 0; i < ordinaryTextures.Length; i++)
        {
            texture2DArray.SetPixels(ordinaryTextures[i].GetPixels(0),
                                     i, 0);
        }

        // Apply our changes
        texture2DArray.Apply();
        // Set the texture to a material
        // Set the texture to a material
        Material.SetTexture("_MainTex", texture2DArray);
    }
        public override void OnImportAsset(AssetImportContext ctx)
        {
            var srcTexture2Ds = new List <Texture2D>(m_Texture2Ds);

            srcTexture2Ds.RemoveAll(t => t == null);
            if (srcTexture2Ds.Count > 0 && srcTexture2Ds[0] != null)
            {
                var baseTex = srcTexture2Ds[0];
                srcTexture2Ds.RemoveAll(tex => tex.width != baseTex.width || tex.height != baseTex.height || tex.mipmapCount != baseTex.mipmapCount || tex.format != baseTex.format);
                var texture2DArray = new Texture2DArray(baseTex.width, baseTex.height, srcTexture2Ds.Count, baseTex.format, baseTex.mipmapCount > 1, m_ColorSpace == 0);
                for (var index = 0; index < srcTexture2Ds.Count; ++index)
                {
                    Graphics.CopyTexture(srcTexture2Ds[index], 0, texture2DArray, index);
                }
                texture2DArray.filterMode = m_FilterMode;
                texture2DArray.wrapModeU  = m_WrapModeU;
                texture2DArray.wrapModeV  = m_WrapModeV;
                texture2DArray.wrapModeW  = m_WrapModeW;
                texture2DArray.anisoLevel = m_AnisoLevel;
                texture2DArray.Apply(false, true);

                var baseTexEditor = Editor.CreateEditor(baseTex);
                var thumbnail     = baseTexEditor.RenderStaticPreview(AssetDatabase.GetAssetPath(baseTex), null, 64, 64);
                DestroyImmediate(baseTexEditor);
                ctx.AddObjectToAsset("Texture2DArray", texture2DArray, thumbnail);
                ctx.SetMainObject(texture2DArray);
            }
            else
            {
                var texture2DArray = new Texture2DArray(32, 32, 1, TextureFormat.ARGB32, false);
                texture2DArray.Apply(false, true);
                ctx.AddObjectToAsset("Texture2DArray", texture2DArray);
                ctx.SetMainObject(texture2DArray);
            }
        }
Esempio n. 19
0
    // reference: https://catlikecoding.com/unity/tutorials/hex-map/part-14/
    Texture2DArray CreateTextureArray(Texture2D[] textures)
    {
        if (textures == null || textures.Length == 0)
        {
            return(null);
        }

        Texture2D      firstTex = textures[0];
        Texture2DArray texArray = new Texture2DArray(firstTex.width,
                                                     firstTex.height,
                                                     textures.Length,
                                                     firstTex.format,
                                                     firstTex.mipmapCount > 0);

        texArray.anisoLevel = firstTex.anisoLevel;
        texArray.filterMode = firstTex.filterMode;
        texArray.wrapMode   = firstTex.wrapMode;

        for (int i = 0; i < textures.Length; i++)
        {
            for (int m = 0; m < firstTex.mipmapCount; m++)
            {
                Graphics.CopyTexture(textures[i], 0, m, texArray, i, m);
            }
        }

        texArray.Apply();

        return(texArray);
    }
Esempio n. 20
0
    void Start()
    {
        mTexture = new Texture2DArray(256, 256, 2, TextureFormat.RGBA32, false, true);

        var temp = new Texture2D(256, 256, TextureFormat.RGBA32, false);

        for (int x = 0; x < temp.width; x++)
        {
            for (int y = 0; y < temp.height; y++)
            {
                temp.SetPixel(x, y, Color.red);
            }
        }

        mTexture.SetPixels(temp.GetPixels(), 0);

        for (int x = 0; x < temp.width; x++)
        {
            for (int y = 0; y < temp.height; y++)
            {
                temp.SetPixel(x, y, Color.blue);
            }
        }

        mTexture.SetPixels(temp.GetPixels(), 1);

        mTexture.Apply();

        material.SetTexture("_TextureArray", mTexture);
    }
        static public Texture2DArray InsertRange(Texture2DArray texArr, int pos, Texture2DArray addArr)
        {
            //if (texArr==null || texArr.depth==0) { return addArr; }
            if (pos > texArr.depth || pos < 0)
            {
                pos = texArr.depth;
            }

            Texture2DArray newArr = new Texture2DArray(texArr.width, texArr.height, texArr.depth + addArr.depth, texArr.format, true, linear: texArr.IsLinear());

            newArr.name = texArr.name;

            if (pos != 0)
            {
                CopyTextures(texArr, newArr, pos);
            }
            CopyTextures(addArr, 0, newArr, pos, addArr.depth);
            if (pos != texArr.depth)
            {
                CopyTextures(texArr, pos, newArr, pos + addArr.depth, texArr.depth - pos);
            }

            newArr.Apply(updateMipmaps: false);
            return(newArr);
        }
Esempio n. 22
0
    void Start()// 注:测试用所以放在 FixedUpdate 实际上只要在Start执行一次
    {
        //AlbedoTextures[i].
        albedoArray = new Texture2DArray(1024, 1024, AlbedoTextures.Count, TextureFormat.RGBA32, true, false);
        normalArray = new Texture2DArray(1024, 1024, NormalTextures.Count, TextureFormat.RGBA32, true, true);



        for (int i = 0; i < AlbedoTextures.Count; i++)
        {
            // 以下两行都可以 //
            //texArr.SetPixels(textures[i].GetPixels(), i);
            albedoArray.SetPixels(AlbedoTextures[i].GetPixels(), i, 0);
        }

        albedoArray.Apply();



        for (int i = 0; i < NormalTextures.Count; i++)
        {
            // 以下两行都可以 //
            //texArr.SetPixels(textures[i].GetPixels(), i);
            normalArray.SetPixels(NormalTextures[i].GetPixels(), i, 0);
        }

        normalArray.Apply();
    }
Esempio n. 23
0
        public void Build()
        {
            Debug.Assert(m_refCounting >= 0);

            if (m_refCounting == 0)
            {
                m_LtcData = new Texture2DArray(k_LtcLUTResolution, k_LtcLUTResolution, (int)LTCLightingModel.Count, GraphicsFormat.R16G16B16A16_SFloat, TextureCreationFlags.None)
                {
                    hideFlags  = HideFlags.HideAndDontSave,
                    wrapMode   = TextureWrapMode.Clamp,
                    filterMode = FilterMode.Bilinear,
                    name       = CoreUtils.GetTextureAutoName(k_LtcLUTResolution, k_LtcLUTResolution, GraphicsFormat.R16G16B16A16_SFloat, depth: (int)LTCLightingModel.Count, dim: TextureDimension.Tex2DArray, name: "LTC_LUT")
                };

                LoadLUT(m_LtcData, (int)LTCLightingModel.GGX, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_GGX);
                LoadLUT(m_LtcData, (int)LTCLightingModel.DisneyDiffuse, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_Disney);

                LoadLUT(m_LtcData, (int)LTCLightingModel.Charlie, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_Charlie);
                LoadLUT(m_LtcData, (int)LTCLightingModel.FabricLambert, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_FabricLambert);

                LoadLUT(m_LtcData, (int)LTCLightingModel.KajiyaKaySpecular, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_KajiyaKaySpecular);
                LoadLUT(m_LtcData, (int)LTCLightingModel.KajiyaKayDiffuse, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_KajiyaKayDiffuse);

                LoadLUT(m_LtcData, (int)LTCLightingModel.CookTorrance, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_CookTorrance);
                LoadLUT(m_LtcData, (int)LTCLightingModel.Ward, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_Ward);
                LoadLUT(m_LtcData, (int)LTCLightingModel.OrenNayar, GraphicsFormat.R16G16B16A16_SFloat, s_LtcMatrixData_BRDF_OrenNayar);

                m_LtcData.Apply();
            }

            m_refCounting++;
        }
Esempio n. 24
0
    public static Texture2DArray UpdateTextureArray(Texture2DArray srcTexture2DArray, Texture2D dstTexture, int textureIndex)
    {
        srcTexture2DArray.SetPixels(dstTexture.GetPixels(), textureIndex);
        srcTexture2DArray.Apply();

        return(srcTexture2DArray);
    }
Esempio n. 25
0
        public override void Build(HDRenderPipelineAsset hdAsset)
        {
            m_InitPreFGD = CoreUtils.CreateEngineMaterial("Hidden/HDRenderPipeline/PreIntegratedFGD");

            m_PreIntegratedFGD            = new RenderTexture(128, 128, 0, RenderTextureFormat.ARGB2101010, RenderTextureReadWrite.Linear);
            m_PreIntegratedFGD.hideFlags  = HideFlags.HideAndDontSave;
            m_PreIntegratedFGD.filterMode = FilterMode.Bilinear;
            m_PreIntegratedFGD.wrapMode   = TextureWrapMode.Clamp;
            m_PreIntegratedFGD.hideFlags  = HideFlags.DontSave;
            m_PreIntegratedFGD.name       = CoreUtils.GetRenderTargetAutoName(128, 128, RenderTextureFormat.ARGB2101010, "PreIntegratedFGD");
            m_PreIntegratedFGD.Create();

            m_LtcData = new Texture2DArray(k_LtcLUTResolution, k_LtcLUTResolution, 3, TextureFormat.RGBAHalf, false /*mipmap*/, true /* linear */)
            {
                hideFlags  = HideFlags.HideAndDontSave,
                wrapMode   = TextureWrapMode.Clamp,
                filterMode = FilterMode.Bilinear,
                name       = CoreUtils.GetTextureAutoName(k_LtcLUTResolution, k_LtcLUTResolution, TextureFormat.RGBAHalf, depth: 3, dim: TextureDimension.Tex2DArray, name: "LTC_LUT")
            };

            LoadLUT(m_LtcData, 0, TextureFormat.RGBAHalf, s_LtcGGXMatrixData);
            LoadLUT(m_LtcData, 1, TextureFormat.RGBAHalf, s_LtcDisneyDiffuseMatrixData);
            // TODO: switch to RGBA64 when it becomes available.
            LoadLUT(m_LtcData, 2, TextureFormat.RGBAHalf, s_LtcGGXMagnitudeData, s_LtcGGXFresnelData, s_LtcDisneyDiffuseMagnitudeData);

            m_LtcData.Apply();

            m_isInit = false;
        }
Esempio n. 26
0
        public static Texture2DArray GifToTextureArray(string path)
        {
            Texture2DArray array = null;

#if DOT_NET_TWO_POINT_ZERO_OR_ABOVE
#if IMAGING_DLL_EXISTS
            EditorUtility.DisplayProgressBar("Creating Texture Array for " + path, "", 0);
            System.Drawing.Image IMG = System.Drawing.Image.FromFile(path);
            int Length = IMG.GetFrameCount(FrameDimension.Time);

            IMG.SelectActiveFrame(FrameDimension.Time, 0);
            array = new Texture2DArray(IMG.Width, IMG.Height, Length, TextureFormat.RGBA32, true, false);

            for (int i = 0; i < Length; i++)
            {
                EditorUtility.DisplayProgressBar("Creating Texture Array for " + path, "Converting frame #" + i, (float)i / Length);
                IMG.SelectActiveFrame(FrameDimension.Time, i);
                System.Drawing.Bitmap bitmap   = new System.Drawing.Bitmap(IMG);
                MemoryStream          msFinger = new MemoryStream();
                IMG.Save(msFinger, bitmap.RawFormat);
                Texture2D texture = new Texture2D(IMG.Width, IMG.Height);
                texture.LoadImage(msFinger.ToArray());
                array.SetPixels(texture.GetPixels(), i);
            }
            IMG.Dispose();
            EditorUtility.ClearProgressBar();

            array.Apply();
            string newPath = path.Replace(".gif", ".asset");
            AssetDatabase.CreateAsset(array, newPath);
#endif
#endif
            return(array);
        }
Esempio n. 27
0
        public override void Build(RenderPipelineResources renderPipelineResources)
        {
            m_InitPreFGD = Utilities.CreateEngineMaterial("Hidden/HDRenderPipeline/PreIntegratedFGD");

            // For DisneyDiffuse integration values goes from (0.5 to 1.53125). GGX need 0 to 1. Use float format.
            m_PreIntegratedFGD            = new RenderTexture(128, 128, 0, RenderTextureFormat.RGB111110Float, RenderTextureReadWrite.Linear);
            m_PreIntegratedFGD.filterMode = FilterMode.Bilinear;
            m_PreIntegratedFGD.wrapMode   = TextureWrapMode.Clamp;
            m_PreIntegratedFGD.hideFlags  = HideFlags.DontSave;
            m_PreIntegratedFGD.Create();

            m_LtcData = new Texture2DArray(k_LtcLUTResolution, k_LtcLUTResolution, 3, TextureFormat.RGBAHalf, false /*mipmap*/, true /* linear */)
            {
                hideFlags  = HideFlags.HideAndDontSave,
                wrapMode   = TextureWrapMode.Clamp,
                filterMode = FilterMode.Bilinear
            };

            LoadLUT(m_LtcData, 0, TextureFormat.RGBAHalf, s_LtcGGXMatrixData);
            LoadLUT(m_LtcData, 1, TextureFormat.RGBAHalf, s_LtcDisneyDiffuseMatrixData);
            // TODO: switch to RGBA64 when it becomes available.
            LoadLUT(m_LtcData, 2, TextureFormat.RGBAHalf, s_LtcGGXMagnitudeData, s_LtcGGXFresnelData, s_LtcDisneyDiffuseMagnitudeData);

            m_LtcData.Apply();

            m_isInit = false;
        }
Esempio n. 28
0
    Texture2DArray GetTexArray(Texture2D[] tex2Ds)
    {
        Texture2D      t            = tex2Ds[0];
        Texture2DArray textureArray = new Texture2DArray(
            t.width, t.height, tex2Ds.Length, t.format, t.mipmapCount > 1);

        textureArray.anisoLevel = t.anisoLevel;
        textureArray.filterMode = t.filterMode;
        textureArray.wrapMode   = t.wrapMode;

        for (int i = 0; i < tex2Ds.Length; i++)
        {
            if (tex2Ds[i].format != t.format)
            {
                Assert.IsTrue(false); // auto importer doesnt work so manually need to set everyone to same format!!
            }

            for (int m = 0; m < t.mipmapCount; m++)
            {
                Graphics.CopyTexture(tex2Ds[i], 0, m, textureArray, i, m);
            }
        }

        textureArray.Apply();

        return(textureArray);
    }
Esempio n. 29
0
    private static void TextureArrayItem()
    {
        Texture2D[] wew = Selection.GetFiltered <Texture2D>(SelectionMode.TopLevel);
        Array.Sort(wew, (UnityEngine.Object one, UnityEngine.Object two) => one.name.CompareTo(two.name));
        Selection.objects = wew;
        Texture2DArray texture2DArray = new Texture2DArray(wew[0].width, wew[0].height, wew.Length, wew[0].format, true);

        string assetPath = AssetDatabase.GetAssetPath(wew[0]);

        assetPath = assetPath.Remove(assetPath.LastIndexOf('/')) + "/Texture2DArray.asset";

        for (int i = 0; i < wew.Length; i++)
        {
            for (int m = 0; m < wew[i].mipmapCount; m++)
            {
                Graphics.CopyTexture(wew[i], 0, m, texture2DArray, i, m);
            }
        }

        texture2DArray.anisoLevel = wew[0].anisoLevel;
        texture2DArray.wrapModeU  = wew[0].wrapModeU;
        texture2DArray.wrapModeV  = wew[0].wrapModeV;
        texture2DArray.Apply(false, true);

        AssetDatabase.CreateAsset(texture2DArray, assetPath);
        AssetDatabase.SaveAssets();

        Selection.activeObject = texture2DArray;
    }
Esempio n. 30
0
        public Texture2DArray GetTextureArray()
        {
            var array           = new Texture2DArray(size, size, toneLevels, TextureFormat.RGB24, true);
            var readingTextures = new Texture2D[mipLevels];

            for (int mip = 0; mip < mipLevels; mip++)
            {
                var mipSize = size >> mip;
                readingTextures[mip] = new Texture2D(mipSize, mipSize, TextureFormat.RGB24, false);
            }

            var oldRt = RenderTexture.active;

            for (int tone = 0; tone < toneLevels; tone++)
            {
                for (int mip = 0; mip < mipLevels; mip++)
                {
                    RenderTexture.active = Textures[tone, mip];

                    var mipSize = size >> mip;

                    readingTextures[mip].ReadPixels(new Rect(0, 0, mipSize, mipSize), 0, 0, false);
                    var pixels = readingTextures[mip].GetPixels();
                    array.SetPixels(pixels, tone, mip);
                }
            }

            array.Apply(false, true);

            array.filterMode = FilterMode.Trilinear;

            RenderTexture.active = oldRt;

            return(array);
        }