Пример #1
0
        public Texture2DArray Generate(TAMSoleImagesPack pack, List <TAMTone> tones, List <TAMMipmapLevel> levels)
        {
            var levelsCount   = levels.Count;
            var tonesCount    = tones.Count;
            var maxResolution = new IntVector2(
                pack.Columns[tones[0]][levels[levelsCount - 1]].width,
                pack.Columns[tones[0]][levels[levelsCount - 1]].height);

            var tamTexture        = new Texture2DArray(maxResolution.X, maxResolution.Y, tonesCount, TextureFormat.RGBA32, true, true);
            var currentResolution = maxResolution;

            for (var levelIndex = 0; levelIndex < levelsCount; levelIndex++)
            {
                for (int toneIndex = 0; toneIndex < tonesCount; toneIndex++)
                {
                    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[levelsCount - 1 - levelIndex]].GetPixel(x, y);
                            array[x + (y * currentResolution.X)] = newColor;
                        }
                    }
                    tamTexture.SetPixels(array, toneIndex, levelIndex);
                }
                currentResolution = new IntVector2(currentResolution.X / 2, currentResolution.Y / 2);
            }

            var lowerLevelTam = CreateAutomaticGeneratedLowerMipmaps(currentResolution * 2, tones,
                                                                     pack.Columns.ToDictionary(
                                                                         p => p.Key,
                                                                         p => p.Value[levels[0]]
                                                                         ));

            var neededMipLevelsCount = (int)Mathf.Log(currentResolution.X, 2);

            for (var levelIndex = 0; levelIndex < neededMipLevelsCount; levelIndex++)
            {
                for (int toneIndex = 0; toneIndex < tonesCount; toneIndex++)
                {
                    tamTexture.SetPixels32(lowerLevelTam.GetPixels32(toneIndex, levelIndex + 1), toneIndex, levelIndex + levelsCount);
                }
            }

            tamTexture.Apply(false);
            return(tamTexture);
        }
Пример #2
0
        public TAMSoleImagesPack GenerateTamPack(TAMPackGenerationConfiguration configuration, bool generateDebugPlates, ComputeShaderContainerGameObject shaderContainerGameObject)
        {
            var tones             = configuration.Tones;
            var levels            = configuration.Levels;
            var tonesCount        = tones.Count;
            var levelsCount       = levels.Count;
            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;

            var renderer = new TAMDeckRenderer(
                Image.FromFile(configuration.StrokeImagePath),
                Image.FromFile(configuration.BlankImagePath),
                new TAMDeckRendererConfiguration()
            {
                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))
            });
            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,
            });

            for (int toneIndex = 0; toneIndex < tonesCount; toneIndex++)
            {
                for (int levelIndex = 0; levelIndex < levelsCount; levelIndex++)
                {
                    var image        = deck.Columns[tones[toneIndex]][levels[levelIndex]];
                    var soleTexture  = wrapper.WrapTexture(TAMUtils.ImageToTexture2D(image));
                    var strokesCount = template.Columns[tones[toneIndex]][levels[levelIndex]].Strokes.Count;
                    if (generateDebugPlates)
                    {
                        CreateTexturedPlate(soleTexture, 11f * new Vector2(toneIndex, levelIndex),
                                            "Tone " + toneIndex + " Level " + levelIndex + " Count" + strokesCount);
                    }
                }
            }

            var soleImagesPack = new TAMSoleImagesPack(deck.Columns.ToDictionary(
                                                           c => c.Key,
                                                           c => c.Value.ToDictionary(
                                                               k => k.Key,
                                                               k => wrapper.WrapTexture(TAMUtils.ImageToTexture2D(k.Value)))));

            return(soleImagesPack);
        }
Пример #3
0
 public void Save(string directoryPath, List <TAMTone> tones, List <TAMMipmapLevel> levels, TAMSoleImagesPack pack)
 {
     for (int toneIndex = 0; toneIndex < tones.Count; toneIndex++)
     {
         for (int levelIndex = 0; levelIndex < levels.Count; levelIndex++)
         {
             var image = pack.Columns[tones[toneIndex]][levels[levelIndex]];
             SavingFileManager.SaveTextureToPngFile(directoryPath + CreateFileNameToSoleImage(toneIndex, levelIndex), image);
         }
     }
 }