Ejemplo n.º 1
0
        public static Texture2D GenerateNoiseTexture(int textureSize, int lowerOctave, int upperOctave,
                                                     float persistence, ColorGradient colorGradient, int bitDepth = 64, float spectrumMultiplier = 1f)
        {
            var newTexture = new Texture2D(textureSize, textureSize);

            var outColors = new Color[textureSize * textureSize];

            int i = 0;

            for (int x = 0; x < textureSize; x++)
            {
                for (int y = 0; y < textureSize; y++)
                {
                    //outColors[i++] = Color.red;

                    int xS = Mathf.FloorToInt((x / (float)textureSize) * bitDepth) * (textureSize / bitDepth);
                    int yS = Mathf.FloorToInt((y / (float)textureSize) * bitDepth) * (textureSize / bitDepth);

                    outColors[i++] = colorGradient.Evaluate(
                        MultiplySpectrum(
                            Perlin2d(xS / (float)textureSize, yS / (float)textureSize, lowerOctave, upperOctave,
                                     persistence)
                            , spectrumMultiplier)
                        );
                }
                //outColors[i++] = Color.white*Mathf.PerlinNoise(5f * x / (float)TextureSize, 5f * y / (float)TextureSize), .5f, .5f)
                //    + new Color(.5f, Mathf.PerlinNoise(50f * x / (float)TextureSize, 50f * y / (float)TextureSize), .5f);
            }

            newTexture.SetPixels(outColors);
            newTexture.Apply();

            return(newTexture);
        }
Ejemplo n.º 2
0
        protected override void UpdateLeftToRightBar()
        {
            while (fillPieces.Count < MaxValue)
            {
                CreateFillPiece();
            }

            for (int i = 0; i < fillPieces.Count; i++)
            {
                fillPieces[i].gameObject.SetActive(i < MaxValue);

                if (i < Value)
                {
                    fillPieces[i].color = ColorGradient.Evaluate(0f);
                }
                else if (i < MaxValue && i < Value + PreviewValue)
                {
                    fillPieces[i].color = PreviewColor;
                }
                else if (i < MaxValue)
                {
                    fillPieces[i].color = UnfilledColor;
                }
            }
        }
Ejemplo n.º 3
0
        public static Texture2D GenerateGradientTexture(int textureSize, ColorGradient gradient)
        {
            var newTexture = new Texture2D(textureSize, textureSize);
            var outColors  = new Color[textureSize * textureSize];

            int i = 0;

            for (int x = 0; x < textureSize; x++)
            {
                for (int y = 0; y < textureSize; y++)
                {
                    float proportion = (x + y) / (float)(textureSize + textureSize);

                    outColors[i++] = gradient.Evaluate(proportion);
                }
            }

            newTexture.SetPixels(outColors);
            newTexture.Apply();

            return(newTexture);
        }
Ejemplo n.º 4
0
        public override IEnumerator ReceivePayload(VisualPayload payload)
        {
            var currentWidth = 0f;

            var flagColorImpact = FlagColorImpact.GetFirstValue(payload.Data);

            var sections = SectionScope.GetEntries(payload.Data).ToList();

            var totalSize = (float)(from entry in SectionScope.GetEntries(payload.Data)
                                    select
                                    SectionMemorySize.GetValue(entry)).Aggregate((a, b) => a + b);

            ColorGradient sectionGradient = new ColorGradient(2 * sections.Count);

            foreach (var section in SectionScope.GetEntries(payload.Data))
            {
                var bandColor = Color.Lerp(
                    SectionColorMapping.GetSectionTypeColor(SectionType.GetValue(section)),
                    SectionColorMapping.GetSectionFlagColor(SectionFlag.GetValue(section)),
                    flagColorImpact);
                sectionGradient.AddColorKey(new GradientColorKey(
                                                bandColor,
                                                currentWidth));

                currentWidth += SectionMemorySize.GetValue(section);

                sectionGradient.AddColorKey(new GradientColorKey(
                                                bandColor,
                                                currentWidth));

                currentWidth += Epsilon * totalSize;
            }

            var textureWidth  = TextureWidth.GetFirstValue(payload.Data);
            var textureHeight = TextureHeight.GetFirstValue(payload.Data);

            sectionGradient.RescaleColorKeys(currentWidth);


            var resultTexture = new Texture2D(textureWidth, textureHeight);

            var outColors = new Color[textureWidth * textureHeight];

            for (int x = 0; x < textureWidth; x++)
            {
                var localColor = sectionGradient.Evaluate(x / (float)textureWidth);
                for (int y = 0; y < textureHeight; y++)
                {
                    outColors[x + textureWidth * y] = localColor;
                }
            }

            resultTexture.SetPixels(outColors);
            resultTexture.Apply();

            var quadMaterial = GameObject.Instantiate(MaterialFactory.GetDefaultMaterial());

            quadMaterial.mainTexture = resultTexture;

            MaterialTarget.SetValue(quadMaterial, payload.Data);

            var iterator = Router.TransmitAll(payload);

            while (iterator.MoveNext())
            {
                yield return(null);
            }
        }