WorldKit icon indicating copy to clipboard operation
WorldKit copied to clipboard

Blend Layers. Stamping Layers

Open ddutchie opened this issue 6 years ago • 2 comments

Hello There.

I am looking to integrate this into a infinite runner type game. What I would like to do do is create a couple of base textures with a road in the middle. image

And stamp/blend this into the overall result so I can have control over the ground level of my runner.

Is this currently possible or do I need to blit the images together with a custom shader?

Regards

ddutchie avatar Aug 10 '19 08:08 ddutchie

Okay, I figured something out. Might be useful to convert to shader, but works quite well.

First, pass in old float array, create new float array from stamp (resize to right resolution) Apply float values.

Return the new float array



    public float[] ApplyClamp(float[] map, Texture2D overlay)
    {
        Texture2D resized = Resize(overlay, (int)Mathf.Sqrt(map.Length), (int)Mathf.Sqrt(map.Length));
        Color[] cs = resized.GetPixels();
        for (int i = 0; i < cs.Length; i++)
        {
            map[i] *= cs[i].r;
        }
        return map;


    }

    public static Texture2D Resize(Texture2D source, int newWidth, int newHeight)
    {
        source.filterMode = FilterMode.Bilinear;
        RenderTexture rt = RenderTexture.GetTemporary(newWidth, newHeight);
        rt.filterMode = FilterMode.Point;
        RenderTexture.active = rt;
        Graphics.Blit(source, rt);
        Texture2D nTex = new Texture2D(newWidth, newHeight);
        nTex.ReadPixels(new Rect(0, 0, newWidth, newWidth), 0, 0);
        nTex.Apply();
        RenderTexture.active = null;
        return nTex;

    }


ddutchie avatar Aug 10 '19 09:08 ddutchie

Could be a way to add peaks and stamp specific features. These could also be generated with noise. Or texture based.

ddutchie avatar Aug 10 '19 09:08 ddutchie