Texture2D JoinTextures(RHOTextureTable table, RHOTextureJoin join, TextureImporterFormat format) { var t = new Texture2D(table.roughness[0].width, table.roughness[0].height, TextureFormat.ARGB32, true); var pixels = t.GetPixels32(); var r = table.roughness[join.roughnessIndex]; var h = table.height[join.heightIndex]; var ao = table.height[join.aoIndex]; var rPixels = r.GetPixels32(); var hPixels = h.GetPixels32(); var aoPixels = ao.GetPixels32(); var numPixels = pixels.Length; for (int i = 0; i < numPixels; ++i) { var p = new Color32(rPixels[i].a, aoPixels[i].a, 0, hPixels[i].a); pixels[i] = p; } t.SetPixels32(pixels); t.Apply(); if ((format == TextureImporterFormat.DXT1) || (format == TextureImporterFormat.DXT5)) { EditorUtility.CompressTexture(t, (TextureFormat)format, TextureCompressionQuality.Best); t.Apply(); } return(t); }
void AddTextureSet(WorldAtlasMaterial atlasMaterial, RHOTextureTable table, RHOTextureSet textureSet) { CheckThrowTextureSet(atlasMaterial, textureSet.roughness, "Roughness"); CheckThrowTextureSet(atlasMaterial, textureSet.ao, "AO"); CheckThrowTextureSet(atlasMaterial, textureSet.height, "Height"); var tSet = new TextureSet() { top = table.AddTextureJoin(textureSet.roughness.top, textureSet.height.top, textureSet.ao.top), sides = table.AddTextureJoin(textureSet.roughness.sides, textureSet.height.sides, textureSet.ao.sides), bottom = table.AddTextureJoin(textureSet.roughness.bottom, textureSet.height.bottom, textureSet.ao.bottom) }; table.indices.Add(tSet); }
RHOTextureTable LoadRHOTextureTable(WorldAtlas atlas) { var table = new RHOTextureTable(); for (int i = 0; i < atlas.materials.Length; ++i) { var m = atlas.materials[i]; if (m == null) { ThrowAssetException(atlas, "Material for terrain type '" + ((EVoxelBlockType)(i + 1)).ToString() + "' is not set!"); } if (m.textures != null) { var set = new RHOTextureSet() { roughness = m.textures.roughness, height = m.textures.height, ao = m.textures.ao }; AddTextureSet(m, table, set); } else { ThrowAssetException(m, "Missing textures for atlas material."); } } int w = -1; int h = -1; int mm = -1; var settings = new ImportSettings_t() { alphaSource = TextureImporterAlphaSource.FromGrayScale, alphaIsTransparency = false, aniso = 16, filterMode = FilterMode.Trilinear, mipmap = false, readable = true, type = TextureImporterType.Default, format = TextureImporterFormat.Alpha8 }; foreach (var t in table.roughness) { CheckTextureSizeAndFormatAndThrow(ref w, ref h, ref mm, settings, t, "Roughness"); } foreach (var t in table.height) { CheckTextureSizeAndFormatAndThrow(ref w, ref h, ref mm, settings, t, "Height"); } foreach (var t in table.ao) { CheckTextureSizeAndFormatAndThrow(ref w, ref h, ref mm, settings, t, "AO"); } return(table); }