I use RenderTexture to read the texture generated by a shader and apply it to the tile. The shader simply mixes _MainTex1(mainColor) and _MainTex2(secondColor) with a simple lerp.
fixed4 frag(v2f i) : SV_Target {
fixed4 mainColor = tex2D(_MainTex1, i.uv*_Scale);
fixed4 secondColor = tex2D(_MainTex2, i.uv*_Scale);
//float mixColor = tex2D(_NoiseTex, i.uv).r;
return lerp(mainColor,secondColor,0.1);
}
Tile s = mapSettings.mapRenderer.dongtu;
Tile t = mapSettings.mapRenderer.shamo_qinling;
RenderTexture renderTexture = RenderTexture.GetTemporary(128,128,0);
Graphics.SetRenderTarget(renderTexture);
Shader shader = Shader.Find("Custom/TileBlend");
Material m = new Material(shader);
m.SetTexture("_MainTex1", t.sprite.texture);
m.SetTexture("_MainTex2", s.sprite.texture);
Graphics.Blit(null, renderTexture, m);
RenderTexture.active = renderTexture;
Texture2D texture = new Texture2D(128, 128, TextureFormat.ARGB32, false);
texture.ReadPixels(new Rect(0, 0, 128, 128), 0, 0);
texture.Apply();
t.sprite = Sprite.Create(texture, new Rect(0.0f, 0.0f, texture.width, texture.height), new Vector2(0.5f, 0.5f), 128f);
RenderTexture.active = null; // Jic
renderTexture.Release();
RenderTexture.ReleaseTemporary(renderTexture);
renderTexture = null;
GL.Clear(true, true, Color.clear);
UnityEngine.Object.Destroy(renderTexture);
mapSettings.mapRenderer.map.SetTile(new Vector3Int(1, 1, 0),t);
I have used many methods, such as GetTemporary and ReleaseTemporary, But every time this method is called, the sprite generated gets closer and closer to MainTex1 (mainColor).
By the way, I clicked on the button to run the method while in editing mode, not in the game
Every time Unity is closed and reopened, the sprite will become the same as the first execution method