public static Texture2DArray GenerateTextureArray(Texture2D[] textures, int size, TextureFormat format) { Texture2DArray textureArray = new Texture2DArray(size, size, textures.Length, format, true); for (int i = 0; i < textures.Length; i++) { textureArray.SetPixels(textures[i].GetPixels(), i); } textureArray.Apply(); return(textureArray); }
// Generate texture array data type from array of 2D textures Texture2DArray GenerateTextureArray(Texture2D[] textures) { Texture2DArray textureArray = new Texture2DArray(TEXTURE_SIZE, TEXTURE_SIZE, textures.Length, TEXTURE_FORMAT, true); for (int i = 0; i < textures.Length; i++) { textureArray.SetPixels(textures[i].GetPixels(), i); } textureArray.Apply(); return(textureArray); }
private void OnWizardCreate() { Texture2DArray arr = new Texture2DArray(textures[0].width, textures[0].height, textures.Length, textures[0].format, false, true); for (int i = 0; i < textures.Length; ++i) { arr.SetPixels(textures[i].GetPixels(), i); } arr.Apply(); AssetDatabase.CreateAsset(arr, path + fileName + ".asset"); }
Texture2DArray GenerateTextureArray(Texture2D[] textures) { Texture2DArray textureArray = new Texture2DArray(textureSize, textureSize, textures.Length, textureFormat, true); for (int i = 0; i < textures.Length; i++) { textureArray.SetPixels(textures[i].GetPixels(), i); } textureArray.Apply(); return(textureArray); }
/// Applying texture changes is slow - so keep it separate and only do it by request. public void ApplyTextures() { Texture2DArray array = new Texture2DArray(TEXTURE_SIZE, TEXTURE_SIZE, data.Length, TEXTURE_FORMAT, true); for (int i = 0; i < data.Length; i++) { array.SetPixels(data[i].texture.GetPixels(), i); } array.Apply(); TerrainMat.SetTexture("_DataTextures", array); }
public static Texture2DArray UpdateTextureArray(Texture2DArray srcArray, List <Texture2D> texture2DList) { for (int i = 0; i < texture2DList.Count; ++i) { Texture2D texture = texture2DList[i]; srcArray.SetPixels(texture.GetPixels(), i); } srcArray.Apply(); return(srcArray); }
private void OnWizardCreate() { ComputeShader shader = Resources.Load <ComputeShader>("ReadRTData"); foreach (var i in allSettings) { int res = (int)i.targetResolution; ComputeBuffer buffer = new ComputeBuffer(res * res * i.allTextures.Length, sizeof(float4)); int pass = i.textureType == TextureType.Normal ? 2 : 1; shader.SetBuffer(pass, "_TextureDatas", buffer); shader.SetInt("_Width", res); shader.SetInt("_Height", res); int offst = 0; foreach (var tx in i.allTextures) { shader.SetTexture(pass, "_TargetTexture", tx); shader.SetInt("_Offset", offst); offst++; shader.Dispatch(pass, res / 8, res / 8, 1); } Texture2DArray tex; switch (i.textureType) { case TextureType.Color: tex = new Texture2DArray(res, res, i.allTextures.Length, TextureFormat.ARGB32, false, true); break; case TextureType.HDR: tex = new Texture2DArray(res, res, i.allTextures.Length, TextureFormat.RGBAHalf, false, true); break; default: tex = new Texture2DArray(res, res, i.allTextures.Length, TextureFormat.RGHalf, false, true); break; } Color[] allCols = new Color[res * res]; for (int a = 0; a < i.allTextures.Length; ++a) { buffer.GetData(allCols, 0, allCols.Length * a, allCols.Length); tex.SetPixels(allCols, a); } buffer.Dispose(); if (path[path.Length - 1] != '/' && path[path.Length - 1] != '\\') { path += '/'; } AssetDatabase.CreateAsset(tex, path + i.fileName + ".asset"); } }
Texture2DArray CreateTextureArrayFromLayers() { Texture2DArray textureArray = new Texture2DArray(layers[0].texture.width, layers[0].texture.height, layers.Length, layers[0].texture.format, true); for (int i = 0; i < layers.Length; ++i) { textureArray.SetPixels(layers[i].texture.GetPixels(), i); } textureArray.Apply(); return(textureArray); }
private void CopyToArray(ref Texture2D from, ref Texture2DArray to, int arrayIndex, int mipLevel, bool compressed = true) { if (compressed) { Graphics.CopyTexture(from, 0, mipLevel, to, arrayIndex, mipLevel); } else { to.SetPixels(from.GetPixels(), arrayIndex, mipLevel); to.Apply(); } }
void PopulateTextureArray() { terrainTexArray = new Texture2DArray(1024, 1024, terrainTextures.Length, TextureFormat.ARGB32, false); for (int i = 0; i < terrainTextures.Length; i++) { // Set the pixes for each texture using the same index as we're storing them in our array. terrainTexArray.SetPixels(terrainTextures[i].GetPixels(0), i, 0); } terrainTexArray.Apply(); }
Texture2DArray GenerateTextureArray(Texture2D[] textures) { Debug.Assert(textures.All(x => x != null), "one ore more of the layers is missing a texture"); Texture2DArray textureArray = new Texture2DArray(textureSize, textureSize, textures.Length, textureFormat, true); for (int i = 0; i < textures.Length; i++) { textureArray.SetPixels(textures [i].GetPixels(), i); } textureArray.Apply(); return(textureArray); }
private void CreateTextureArray() { ordinaryTextures = new Texture2D[2]; ordinaryTextures[0] = Resources.Load("Textures/Blocks/000_Grass") as Texture2D; ordinaryTextures[1] = Resources.Load("Textures/Blocks/001_GrassColor2") as Texture2D; // var temptex = TextureScaler.scaled(ordinaryTextures[0], ordinaryTextures[0].width*8, ordinaryTextures[0].height*8, FilterMode.Point); // ordinaryTextures[0] = temptex; // temptex = TextureScaler.scaled(ordinaryTextures[1], ordinaryTextures[1].width*8, ordinaryTextures[1].height*8, FilterMode.Point); // ordinaryTextures[1] = temptex; // for (int i = 0; i < ordinaryTextures.Length; i++) // { // Texture2D item = ordinaryTextures[i]; // item = TextureScaler.scaled(item, 4, 4, FilterMode.Point); // } // Create Texture2DArray Texture2DArray texture2DArray = new Texture2DArray(ordinaryTextures[0].width / 3, ordinaryTextures[0].height, ordinaryTextures.Length * 3, TextureFormat.RGB24, false, false); // Apply settings var tWidth = ordinaryTextures[0].width / 3; var tHeight = ordinaryTextures[0].height; texture2DArray.filterMode = FilterMode.Point; texture2DArray.wrapMode = TextureWrapMode.Repeat; //texture2DArray.mipMapBias = -1.0f; // Loop through ordinary textures and copy pixels to the // Texture2DArray for (int i = 0; i < ordinaryTextures.Length * 3; i += 3) { texture2DArray.SetPixels(ordinaryTextures[i / 3].GetPixels(0, 0, tWidth, tHeight, 0), i, 0); texture2DArray.SetPixels(ordinaryTextures[i / 3].GetPixels(tWidth, 0, tWidth, tHeight, 0), i + 1, 0); texture2DArray.SetPixels(ordinaryTextures[i / 3].GetPixels(tWidth * 2, 0, tWidth, tHeight, 0), i + 2, 0); } // Apply our changes texture2DArray.Apply(); // Set the texture to a material objectToAddTextureTo.GetComponent <Renderer>() .sharedMaterial.SetTexture("_Block2DArray", texture2DArray); }
static void GifImport() { string path = AssetDatabase.GetAssetPath(Selection.activeObject); List <Texture2D> array = GetGifFrames(path); Texture2DArray arrayTexture = new Texture2DArray(array.First().width, array.First().height, array.Count, TextureFormat.RGBA32, true, false); for (int i = 0; i < array.Count; i++) { arrayTexture.SetPixels(array[i].GetPixels(0), i, 0); } arrayTexture.Apply(); AssetDatabase.CreateAsset(arrayTexture, path.Replace(".gif", ".asset")); }
// Load LUT with one scalar in alpha of a tex2D void LoadLUT(Texture2DArray tex, int arrayElement, TextureFormat format, float[] LUTScalar) { const int count = k_LtcLUTResolution * k_LtcLUTResolution; Color[] pixels = new Color[count]; for (int i = 0; i < count; i++) { pixels[i] = new Color(0, 0, 0, LUTScalar[i]); } tex.SetPixels(pixels, arrayElement); }
private Texture2DArray ConvertToTextureArray(Texture2D[] textures) { Texture2DArray texture2DArray = new Texture2DArray(textureResolution, textureResolution, textures.Length, textureFormat, true); for (int index = 0; index < textures.Length; index++) { texture2DArray.SetPixels(textures[index].GetPixels(), index); } texture2DArray.Apply(); return(texture2DArray); }
public void GenTextureArray() { int sourceWidth = SourceTextures[0].width; int sourceHeight = SourceTextures[0].height; textureArray = new Texture2DArray(sourceWidth, sourceHeight, SourceTextures.Length, TextureFormat.ARGB32, true); for (int i = 0; i < SourceTextures.Length; i++) { textureArray.SetPixels(SourceTextures[i].GetPixels(), i); } textureArray.Apply(); }
private void AddNewPoints() { for (int i = 0; i < POINT_BATCH; i++) { if (_points.Count == 0) { break; } if (_points.TryTake(out Vector3 p)) { if (_index <= _positionMapArray.width - 1) { _colorarray[_depth][_index] = new Color(p.x, p.y, p.z); _index++; } else { _positionMapArray.SetPixels(_colorarray[_depth], _depth); if (_depth > _positionMapArray.depth) { Debug.LogError("maximum depth reached: try increasing point skip"); break; } _depth++; _index = 0; _colorarray.Add(new Color[_positionMapArray.width]); } } } _positionMapArray.SetPixels(_colorarray[_depth], _depth); _positionMapArray.Apply(false, false); //Force effect update since UpdateBinding doesn't seem to be called if depth is 0 UpdateBinding(_effect); }
public void CreateTextureArray() { Texture2DArray array = new Texture2DArray(AlbedoTextures[0].width, AlbedoTextures[0].height, AlbedoTextures.Length, AlbedoTextures[0].format, false); for (int i = 0; i < AlbedoTextures.Length; i++) { array.SetPixels(AlbedoTextures[i].GetPixels(), i); } array.Apply(); AssetDatabase.CreateAsset(array, AlbedoTextureURL); }
/// <summary> /// 创建Texture2DArray /// </summary> /// <param name="textureList"></param> /// <param name="pixelWidth"></param> /// <param name="pixelHeight"></param> /// <returns></returns> public static Texture2DArray CreateTextureArray(List <Texture2D> textureList, int pixelWidth, int pixelHeight) { Texture2DArray textureArr = new Texture2DArray(pixelWidth, pixelHeight, textureList.Count, TextureFormat.RGB24, false); for (int i = 0; i < textureList.Count; ++i) { Texture2D texture = textureList[i]; textureArr.SetPixels(texture.GetPixels(), i); } textureArr.Apply(); return(textureArr); }
public static Texture GenerateDummyTextureArray(IntVector2 textureSize, int textureArrayDepth, TextureFormat textureArrayFormat) { var ceilHeightTexture = new Texture2DArray(textureSize.X, textureSize.Y, textureArrayDepth, textureArrayFormat, false, true); for (int layer = 0; layer < textureArrayDepth; layer++) { ceilHeightTexture.SetPixels(Enumerable .Range(0, textureSize.X * textureSize.Y) .Select(c => new Color(layer / (float)(textureArrayDepth - 1), 0, 0, 0)).ToArray(), layer); } ceilHeightTexture.Apply(); return(ceilHeightTexture); }
static void CreateTexture2DArrayFromSpriteSheet() { Texture2D[] tileTextures = GameObject.Find("Texture2DArrayCreator").GetComponent <Texture2DArrayCreator>().tiles; Texture2DArray array = new Texture2DArray(tileTextures[0].width, tileTextures[0].height, tileTextures.Length, tileTextures[0].format, false); for (int i = 0; i < tileTextures.Length; i++) { array.SetPixels(tileTextures[i].GetPixels(), i); } array.Apply(); AssetDatabase.CreateAsset(array, "Assets/ASCII/Image Effect/Tile Texture2DArray.asset"); }
/// <summary> /// Generates a Texture2DArray from a Texture2D[]. /// </summary> /// <param name="textures">The array of textures that is being turned into a texture array.</param> /// <returns>A texture array from the array of textures.</returns> private Texture2DArray GenerateTextureArray(Texture2D[] textures) { // creates a new texture array based on the texture settings Texture2DArray textureArray = new Texture2DArray(m_textureSize, m_textureSize, textures.Length, m_textureFormat, true); // the texture array gets the pixels from each texture for (int i = 0; i < textures.Length; i++) { textureArray.SetPixels(textures[i].GetPixels(), i); } textureArray.Apply(); return(textureArray); }
private static void CreateTexture3D() { List <Texture2D> textures = new List <Texture2D>(); foreach (Object o in Selection.objects) { if (o.GetType() == typeof(Texture2D)) { textures.Add((Texture2D)o); } } textures = textures.OrderBy(a => a.name).ToList(); int xSize = textures[0].width; int ySize = textures[0].height; int zSize = textures.Count; uint zPow2 = (uint)zSize; zPow2--; zPow2 |= zPow2 >> 1; zPow2 |= zPow2 >> 2; zPow2 |= zPow2 >> 4; zPow2 |= zPow2 >> 8; zPow2 |= zPow2 >> 16; zPow2++; Color[] colorArray = new Color[xSize * ySize]; Texture2DArray texture = new Texture2DArray(xSize, ySize, (int)zPow2, TextureFormat.RGBA32, true); for (int z = 0; z < zSize; z++) { for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { colorArray[x + (y * xSize)] = textures[z].GetPixel(x, y); } } texture.SetPixels(colorArray, z); } texture.Apply(); AssetDatabase.CreateAsset(texture, AssetDatabase.GetAssetPath(Selection.activeObject) + "3dTexture.asset"); }
public void createTextureArray() { textureArray = new Texture2DArray(texturesToLoad[0].width, texturesToLoad[0].height, texturesToLoad.Length, texArrayFormat, true); for (int i = 0; i < texturesToLoad.Length; i++) { textureArray.SetPixels(texturesToLoad[i].GetPixels(0), i, 0); } textureArray.Apply(); //Graphics.CopyTexture(texturesToLoad[0], textureArray); AssetDatabase.CreateAsset(textureArray, directory + "/" + filename + ".asset"); }
void Start() { Texture2DArray texture2DArray = new Texture2DArray(_textures[0].width, _textures[0].height, _textures.Length, TextureFormat.RGBA32, false, false); texture2DArray.filterMode = FilterMode.Bilinear; texture2DArray.wrapMode = TextureWrapMode.Repeat; for (int i = 0; i < _textures.Length; i++) { texture2DArray.SetPixels(_textures[i].GetPixels(0), i, 0); } texture2DArray.Apply(); gameObject.GetComponent <Renderer>().sharedMaterial.SetTexture("_Textures", texture2DArray); }
public static Texture2DArray GenerateTextureArray(int textureSize, Texture2D[] textures) { Texture2DArray textureArray = new Texture2DArray(textureSize, textureSize, textures.Length, TextureFormat.RGB565, true); for (int i = 0; i < textures.Length; i++) { if (textures[i]) { textureArray.SetPixels(textures[i].GetPixels(), i); } } textureArray.Apply(); return(textureArray); }
// Special-case function for 'm_LtcMultiGGXFresnelDisneyDiffuse'. void LoadLUT(Texture2DArray tex, int arrayElement, TextureFormat format, float[] LtcGGXMagnitudeData, float[] LtcGGXFresnelData, float[] LtcDisneyDiffuseMagnitudeData) { const int count = k_LtcLUTResolution * k_LtcLUTResolution; Color[] pixels = new Color[count]; for (int i = 0; i < count; i++) { // We store the result of the subtraction as a run-time optimization. // See the footnote 2 of "LTC Fresnel Approximation" by Stephen Hill. pixels[i] = new Color(LtcGGXMagnitudeData[i] - LtcGGXFresnelData[i], LtcGGXFresnelData[i], LtcDisneyDiffuseMagnitudeData[i], 1); } tex.SetPixels(pixels, arrayElement); }
// Use this for initialization void Start() { Texture2DArray textureArray = new Texture2DArray(textureWidth, textureHeight, textures.Length, TextureFormat.RGBA32, false); for (int i = 0; i < textures.Length; i++) { //Graphics.CopyTexture(textures[i], 0, 0, textureArray, i, 0); textureArray.SetPixels(textures[i].GetPixels(0), i, 0); } //terrainMaterial.SetTexture("_Textures", textureArray); Terrain terrain = gameObject.GetComponent <Terrain>(); terrain.materialTemplate.SetTexture("_Textures", textureArray); }
void CreateTexture2DAsset() { //Texture2DArray array = new Texture2DArray(textures[0].width, textures[0].height, textures.Length, GraphicsFormatUtility.GetGraphicsFormat(TextureFormat.ARGB32, false), TextureCreationFlags.None); Texture2DArray array = new Texture2DArray(textures[0].width, textures[0].height, textures.Length, texFormat, mipmaps); Debug.Log(array); Debug.Log(array.format); for (int i = 0; i < textures.Length; i++) { array.SetPixels(textures[i].GetPixels(), i); } array.Apply(); AssetDatabase.CreateAsset(array, "Assets/TextureArray.asset"); }
void Create() { #if UNITY_EDITOR Texture2DArray textureArray = new Texture2DArray(resolution, resolution, textureList.Length, TextureFormat.RGB24, false); for (int i = 0; i < textureList.Length; i++) { Texture2D tex = (Texture2D)textureList[i]; textureArray.SetPixels(tex.GetPixels(0), i, 0); } textureArray.Apply(); AssetDatabase.CreateAsset(textureArray, savePath); Debug.Log("Saved asset to " + savePath); #endif }