void UpdateNoiseTexture(int frame, float stripLength) { int fcount = Time.frameCount; if (fcount % frame != 0) { return; } var color = XPostProcessingUtility.RandomColor(); for (var y = 0; y < _noiseTexture.height; y++) { for (var x = 0; x < _noiseTexture.width; x++) { if (UnityEngine.Random.value > stripLength) { color = XPostProcessingUtility.RandomColor(); } _noiseTexture.SetPixel(x, y, color); } } _noiseTexture.Apply(); }
void UpdateNoiseTexture(int frame, int noiseTextureWidth, int noiseTextureHeight, float stripLength) { int frameCount = Time.frameCount; if (frameCount % frame != 0) { return; } _noiseTexture = new Texture2D(noiseTextureWidth, noiseTextureHeight, TextureFormat.ARGB32, false); _noiseTexture.wrapMode = TextureWrapMode.Clamp; _noiseTexture.filterMode = FilterMode.Point; _trashFrame1 = new RenderTexture(Screen.width, Screen.height, 0); _trashFrame2 = new RenderTexture(Screen.width, Screen.height, 0); _trashFrame1.hideFlags = HideFlags.DontSave; _trashFrame2.hideFlags = HideFlags.DontSave; Color32 color = XPostProcessingUtility.RandomColor(); for (int y = 0; y < _noiseTexture.height; y++) { for (int x = 0; x < _noiseTexture.width; x++) { //随机值若大于给定strip随机阈值,重新随机颜色 if (UnityEngine.Random.value > stripLength) { color = XPostProcessingUtility.RandomColor(); } //设置贴图像素值 _noiseTexture.SetPixel(x, y, color); } } _noiseTexture.Apply(); var bytes = _noiseTexture.EncodeToPNG(); }