/// <summary> /// 设置texture的信息 /// </summary> /// <param name="size"></param> private static void SetTextureConfig(TextureConfig textureConfig, string srcPath) { TextureImporter import = AssetImporter.GetAtPath(srcPath) as TextureImporter; if (import != null) { //设置Texture的最大大小 if (textureConfig.m_TextureSize != -1) { import.maxTextureSize = textureConfig.m_TextureSize; } //设置Texture的类型 if (textureConfig.m_TextureType != EnumTools.GetException <TextureImporterType>()) { import.textureType = textureConfig.m_TextureType; } //设置Texture的WrapMode if (textureConfig.m_WrapMode != EnumTools.GetException <TextureWrapMode>()) { import.wrapMode = textureConfig.m_WrapMode; } //设置Texture的FilterMode if (textureConfig.m_FilterMode != EnumTools.GetException <FilterMode>()) { import.filterMode = textureConfig.m_FilterMode; } //待扩展 } }
public TexturePool(TextureConfig cfg, int size, bool isLeft) { isReleased = false; // Editor doesn't need the texture queue. if (Application.isEditor) { size = 1; } this.isLeft = isLeft; this.size = size; for (int i = 0; i < size; i++) { currentRt = new RenderTexture(cfg.w, cfg.h, cfg.depth, cfg.format, RenderTextureReadWrite.Default); currentRt.useMipMap = cfg.useMipMap; currentRt.wrapMode = cfg.wrapMode; currentRt.filterMode = cfg.filterMode; currentRt.anisoLevel = cfg.anisoLevel; currentRt.antiAliasing = cfg.antiAliasing; currentRt.Create(); currentPtr = currentRt.GetNativeTexturePtr(); textures.Add(currentPtr, currentRt); } #if UNITY_EDITOR if (Application.isEditor) { return; } #endif var array = new IntPtr[textures.Count]; textures.Keys.CopyTo(array, 0); queue = WaveVR_Utils.WVR_StoreRenderTextures(array, size, isLeft); }
private static async UniTask <Plain> CreateFloor(WorldLayer layer) { var timing = layer.GetValidScreen().TimingPoints.Update; var plain = new Plain(); plain.Scale = new Vector3(40f); plain.Shader = new PhongShader(); var config = new TextureConfig(TextureExpansionMode.NearestNeighbor, TextureShrinkMode.NearestNeighbor, TextureMipmapMode.None, TextureWrapMode.ClampToEdge, TextureWrapMode.ClampToEdge); var texture = await Resources.Sandbox["floor.png"].LoadTextureAsync(config, timing); plain.AddComponent(texture); plain.Rotation = Quaternion.FromAxisAngle(Vector3.UnitX, -90.ToRadian()); plain.Updated += _ => { var k = plain.GetValidScreen().Keyboard; if (k.IsPress(Elffy.InputSystem.Keys.Down)) { plain.Position.Y -= 0.5f; } else if (k.IsPress(Elffy.InputSystem.Keys.Up)) { plain.Position.Y += 0.5f; } }; return(await plain.Activate(layer)); }
public static SplatPrototype getSplatPrototype(TextureConfig cfg) { SplatPrototype prt = new SplatPrototype(); prt.texture = cfg.texture; prt.normalMap = cfg.textureNormal; prt.tileSize = new Vector2(8, 8); prt.tileOffset = new Vector2(0, 0); return(prt); }
public static TextureConfig make(JSONNode obj) { TextureConfig config = new TextureConfig(); config.texture = (Texture2D)Resources.LoadAssetAtPath(obj["texture"].Value, typeof(Texture2D)); config.textureNormal = (Texture2D)Resources.LoadAssetAtPath(obj["normaltexture"].Value, typeof(Texture2D)); config.from = obj ["from"].AsFloat; config.to = obj ["to"].AsFloat; config.margins = obj ["margins"].AsFloat; config.strength = obj ["strength"].AsFloat; return(config); }
private Texture FromDDS(DDS dds) { TextureConfig config = new TextureConfig(); config.Width = dds.MainHeader.Width; config.Height = dds.MainHeader.Height; config.Format = FormatConverter[dds.ToGenericFormat()]; config.MipCount = dds.MainHeader.MipCount; config.Name = System.IO.Path.GetFileNameWithoutExtension(dds.FileName); Console.WriteLine("SurfaceFormat " + config.Format); return(FromBitMap(dds.GetImageData(), config)); }
public Texture FromBitMap(List <byte[]> arrayFaces, TextureConfig config) { if (config.MipCount == 0) { config.MipCount = 1; } Texture tex = new Texture(); tex.Name = config.Name; tex.Format = config.Format; tex.Width = config.Width; tex.Height = config.Height; tex.ChannelRed = config.RedComp; tex.ChannelGreen = config.GreenComp; tex.ChannelBlue = config.BlueComp; tex.ChannelAlpha = config.AlphaComp; tex.sparseBinding = config.sparseBinding; tex.sparseResidency = config.sparseResidency; tex.AccessFlags = config.AccessFlags; tex.MipCount = config.MipCount; tex.Depth = config.Depth; tex.Dim = config.Dim; tex.Flags = config.Flags; tex.TileMode = config.TileMode; tex.textureLayout = config.TextureLayout; tex.textureLayout2 = config.TextureLayout2; tex.Swizzle = config.Swizzle; tex.SurfaceDim = config.SurfaceDim; tex.SampleCount = config.SampleCount; tex.Regs = config.Regs; tex.Pitch = config.Pitch; tex.MipOffsets = new long[tex.MipCount]; tex.TextureData = new List <List <byte[]> >(); for (int i = 0; i < arrayFaces.Count; i++) { List <byte[]> mipmaps = SwizzleSurfaceMipMaps(tex, arrayFaces[i], tex.MipCount); tex.TextureData.Add(mipmaps); //Combine mip map data byte[] combinedMips = ByteUtils.CombineArray(mipmaps.ToArray()); tex.TextureData[i][0] = combinedMips; } return(tex); }
//Get texture configs of different types using elemsize public static List <TextureConfig> GetTextureConfigs(FileStream fs, int texturePointer, int textureCount, int elemSize, bool negate = false) { int idOffset = 0, startOffset = 0, sizeOffset = 0, modeOffset = 0; switch (elemSize) { case 0x10: idOffset = 0x00; startOffset = 0x04; sizeOffset = 0x08; modeOffset = 0x0C; break; case 0x18: idOffset = 0x00; startOffset = 0x08; sizeOffset = 0x0C; modeOffset = 0x14; break; } var textureConfigs = new List <TextureConfig>(); byte[] texBlock = ReadBlock(fs, texturePointer, textureCount * elemSize); int neg = 0; for (int i = 0; i < textureCount; i++) { TextureConfig textureConfig = new TextureConfig(); textureConfig.id = ReadInt(texBlock, (i * elemSize) + idOffset); textureConfig.start = ReadInt(texBlock, (i * elemSize) + startOffset); textureConfig.size = ReadInt(texBlock, (i * elemSize) + sizeOffset); textureConfig.mode = ReadInt(texBlock, (i * elemSize) + modeOffset); if (negate) { if (i == 0) { neg = textureConfig.start; } textureConfig.start -= neg; } textureConfigs.Add(textureConfig); } return(textureConfigs); }
public static void Apply(MenuCommand command) { textures = new List <TextureConfig>(); sceneTerrains = FindObjectsOfType(typeof(Terrain)) as Terrain[]; string json = File.ReadAllText(Application.dataPath + "/textures.json"); var config = JSON.Parse(json); cliff = TextureConfig.make(config["cliff"]); for (int i = 0; i < config["textures"].AsArray.Count; i++) { textures.Add(TextureConfig.make(config["textures"].AsArray[i])); } SplatPrototype[] texturesArray = new SplatPrototype[1 + textures.Count]; texturesArray [0] = getSplatPrototype(cliff); for (int i = 0; i < textures.Count; i++) { texturesArray[i + 1] = getSplatPrototype(textures[i]); } for (int t = 0; t < sceneTerrains.Length; t++) { Terrain terrain = sceneTerrains[t]; terrain.terrainData.splatPrototypes = texturesArray; float[,,] al = getAlphaLayers(terrain.terrainData /*terrain.terrainData.GetHeights(0,0,terrain.terrainData.heightmapHeight, terrain.terrainData.heightmapWidth), * terrain.terrainData.alphamapWidth*/); //Debug.Log(terrain.terrainData.GetAlphamaps); terrain.terrainData.SetAlphamaps(0, 0, al); } Debug.Log("DONE"); }
public static Texture2D FromBitmap([NotNull] this GLTextureFactory fact, string name, TextureConfig cfg, Bitmap bmp) { var rect = new Rectangle(0, 0, bmp.Width, bmp.Height); var bitmapData = bmp.LockBits(rect, ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); return fact.Create2D(name, cfg, bmp.Width, bmp.Height, bitmapData.Scan0); }
public static Texture2D FromEmbeddedImage([NotNull] this GLTextureFactory fact, TextureConfig cfg, string name) { var bmp = LoadFromRes(name); // update the name to not have the extension. name = Path.GetFileNameWithoutExtension(name); var rect = new Rectangle(0, 0, bmp.Width, bmp.Height); var bitmapData = bmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); return fact.Create2D(name, cfg, bmp.Width, bmp.Height, bitmapData.Scan0); }
public static float[,,] getAlphaLayers(TerrainData data /*float[,] heightMap, int alphamapSize*/) { //COEFFIECIENTS <layerIndex, height> -> streight float [,] strengthCoefficient = new float[textures.Count, 1000]; for (int l = 0; l < textures.Count; l++) { TextureConfig textureCfg = textures [l]; for (int h = 0; h < 1000; h++) { float h_01 = (float)h / 1000f; if (textureCfg.from <= h_01 && textureCfg.to >= (float)h_01) { strengthCoefficient [l, h] = textureCfg.strength; } if (textureCfg.from > h_01 && textureCfg.from - h_01 <= textureCfg.margins) { strengthCoefficient [l, h] = Mathf.SmoothStep(0, textureCfg.strength, 1 - ((textureCfg.from - h_01) / textureCfg.margins)); } if (textureCfg.to < h_01 && h_01 - textureCfg.to <= textureCfg.margins) { strengthCoefficient [l, h] = Mathf.SmoothStep(textureCfg.strength, 0, (h_01 - textureCfg.to) / textureCfg.margins); } } } float[,] heightMap = data.GetHeights(0, 0, data.heightmapHeight, data.heightmapWidth); int alphamapSize = data.alphamapWidth; float[,,] result = new float[alphamapSize, alphamapSize, textures.Count + 1]; float ratio = (float)alphamapSize / (float)heightMap.GetLength(0); for (int l = 0; l < textures.Count; l++) { for (int x = 0; x < alphamapSize; x++) { for (int z = 0; z < alphamapSize; z++) { float height = heightMap[ Mathf.Clamp(Mathf.RoundToInt(ratio * x), 0, data.heightmapHeight - 1), Mathf.Clamp(Mathf.RoundToInt(ratio * z), 0, data.heightmapWidth - 1)]; TextureConfig textureCfg = textures[l]; result[x, z, l + 1] = textureCfg.strength * strengthCoefficient[l, Mathf.Clamp(Mathf.RoundToInt(height * 1000), 0, 999)]; /*if(textureCfg.from < height && textureCfg.to > height) * result[x,z,l+1]= textureCfg.strength;*/ } } } //SLOPES for (int x = 0; x < alphamapSize; x++) { for (int z = 0; z < alphamapSize; z++) { // Normalise x/y coordinates to range 0-1 float x_01 = (float)x / (float)data.alphamapHeight; float z_01 = (float)z / (float)data.alphamapWidth; float steepness = data.GetSteepness(z_01, x_01); TextureConfig textureCfg = cliff; if (textureCfg.from < steepness && textureCfg.to > steepness) { result[x, z, 0] = textureCfg.strength; } } } //NORMALIZATION for (int x = 0; x < alphamapSize; x++) { for (int z = 0; z < alphamapSize; z++) { float total = 0f; for (int l = 0; l < result.GetLength(2); l++) { total += result[x, z, l]; } for (int l = 0; l < result.GetLength(2); l++) { result[x, z, l] = result[x, z, l] / total; } } } return(result); }
public PlayerTexture(Texture2D sprite, TextureConfig config) { this.sprite = sprite; this.config = config; }