public Texture2DArray Generate(TamIdSoleImagesPack pack, List <TAMTone> tones, List <TAMMipmapLevel> levels, int layersCount) { var mipmapLevelsCount = levels.Count; var tonesCount = tones.Count; var maxResolution = new IntVector2( pack.Columns[tones[0]][levels[mipmapLevelsCount - 1]][0].width, pack.Columns[tones[0]][levels[mipmapLevelsCount - 1]][0].height); var slicesCount = tonesCount * layersCount; var tamIdTexture = new Texture2DArray(maxResolution.X, maxResolution.Y, slicesCount, TextureFormat.RGBA32, true, true) { filterMode = FilterMode.Point, wrapMode = TextureWrapMode.Clamp }; var currentResolution = maxResolution; for (var mipmapLevelIndex = 0; mipmapLevelIndex < mipmapLevelsCount; mipmapLevelIndex++) { for (int toneIndex = 0; toneIndex < tonesCount; toneIndex++) { for (int layerIndex = 0; layerIndex < layersCount; layerIndex++) { var array = new Color[currentResolution.X * currentResolution.Y]; for (int x = 0; x < currentResolution.X; x++) { for (int y = 0; y < currentResolution.Y; y++) { Color newColor = pack.Columns[tones[toneIndex]][levels[mipmapLevelsCount - 1 - mipmapLevelIndex]][layerIndex].GetPixel(x, y); array[x + (y * currentResolution.X)] = newColor; } } tamIdTexture.SetPixels(array, toneIndex * layersCount + layerIndex, mipmapLevelIndex); } } currentResolution = new IntVector2(currentResolution.X / 2, currentResolution.Y / 2); } var neededMipLevelsCount = (int)Mathf.Log(currentResolution.X, 2); for (int toneIndex = 0; toneIndex < tonesCount; toneIndex++) { for (int layerIndex = 0; layerIndex < layersCount; layerIndex++) { var depthIndex = toneIndex * layersCount + layerIndex; var lastSetMipmapIndex = mipmapLevelsCount - 1; var lowerLevelMipmapTexture = CreateAutomaticGeneratedLowerMipmaps(currentResolution * 2, tamIdTexture.GetPixels(depthIndex, lastSetMipmapIndex)); for (var mipmapLevelIndex = 0; mipmapLevelIndex < neededMipLevelsCount; mipmapLevelIndex++) { tamIdTexture.SetPixels32(lowerLevelMipmapTexture.GetPixels32(mipmapLevelIndex + 1), depthIndex, mipmapLevelIndex + mipmapLevelsCount); } } } tamIdTexture.Apply(false); return(tamIdTexture); }
public TamIdSoleImagesPack GenerateTamPack(TamIdPackGenerationConfiguration configuration, bool generateDebugPlates, ComputeShaderContainerGameObject shaderContainerGameObject) { var tones = configuration.Tones; var levels = configuration.Levels; var templateGenerator = new TAMTemplateGenerator( new PoissonTAMImageDiagramGenerator( new TAMPoissonDiskSampler(), new StrokesGenerator(configuration.StrokesGeneratorConfiguration), configuration.PoissonTamImageDiagramGeneratorConfiguration) ); var template = templateGenerator.Generate(new TAMTemplateSpecification() { Tones = tones, MipmapLevels = levels }); var margin = configuration.Margin; var smallestLevelSoleImageResolution = configuration.SmallestLevelSoleImageResolution; Debug.Log("XXXy: " + configuration.StrokeImagePath); var a1 = Image.FromFile(configuration.StrokeImagePath); var a2 = Image.FromFile(configuration.BlankImagePath); var renderer = new TamIdDeckRenderer( Image.FromFile(configuration.StrokeImagePath), Image.FromFile(configuration.BlankImagePath), new TAMDeckRendererConfiguration() { UseSmoothAlpha = configuration.UseSmoothAlpha, UseDithering = configuration.UseDithering, SoleImagesResolutionPerLevel = levels .Select((level, i) => new { level, i }) .ToDictionary(c => c.level, c => c.i) .ToDictionary(pair => pair.Key, pair => (smallestLevelSoleImageResolution * Mathf.Pow(2, pair.Value)).ToIntVector()), Margin = margin, StrokeHeightMultiplierPerLevel = levels .Select((level, i) => new { level, i }) .ToDictionary(c => c.level, c => c.i) .ToDictionary(pair => pair.Key, pair => configuration.StrokeHeightMultiplierForZeroLevel / Mathf.Pow(2, pair.Value)) }, configuration.LayersCount); var deck = renderer.Render(template); var wrapper = new TAMMarginsWrapper(new UTTextureRendererProxy(new TextureRendererService( new MultistepTextureRenderer(shaderContainerGameObject), new TextureRendererServiceConfiguration() { StepSize = configuration.RendererOneStepSize })), new TAMMarginsWrapperConfiguration() { Margin = margin, }); var soleImagesPack = new TamIdSoleImagesPack(deck.Columns.ToDictionary( c => c.Key, c => c.Value.ToDictionary( k => k.Key, k => { var x1 = k.Value.Select(r => wrapper.WrapTexture(TAMUtils.ImageToTexture2D(r))).ToList(); return(x1); }))); deck.DisposeImages(); return(soleImagesPack); }
public void Save(string directoryPath, List <TAMTone> tones, List <TAMMipmapLevel> levels, int layersCount, TamIdSoleImagesPack pack) { for (int toneIndex = 0; toneIndex < tones.Count; toneIndex++) { for (int levelIndex = 0; levelIndex < levels.Count; levelIndex++) { for (int layerIndex = 0; layerIndex < layersCount; layerIndex++) { var image = pack.Columns[tones[toneIndex]][levels[levelIndex]][layerIndex]; SavingFileManager.SaveTextureToPngFile(directoryPath + CreateFileNameToSoleImage(toneIndex, levelIndex, layerIndex), image); } } } }