public static CustomRenderTexture GetPreViewNoise2DRT(Noise2DType type, int noiseID, bool isChange) { if (crtList[noiseID] == null) { CustomRenderTexture rt = GenerateNoise2DRT(type, 5, 256, 256); crtList[noiseID] = rt; crtMatList[noiseID] = rt.material; switch (type) { case Noise2DType.PerilinNoise2D: crtList[noiseID].material.SetFloatArray("_PERM", permutation); crtList[noiseID].material.SetFloatArray("_G", garray); break; case Noise2DType.PerilinNoise2D_Tileable: crtList[noiseID].material.SetFloatArray("_PERM", permutation); crtList[noiseID].material.SetFloatArray("_G4D", g4Darray); break; } } else if (isChange) { crtList[noiseID].material.shader = Shader.Find(noise2DDict[type]); switch (type) { case Noise2DType.PerilinNoise2D: crtList[noiseID].material.SetFloatArray("_PERM", permutation); crtList[noiseID].material.SetFloatArray("_G", garray); break; case Noise2DType.PerilinNoise2D_Tileable: crtList[noiseID].material.SetFloatArray("_PERM", permutation); crtList[noiseID].material.SetFloatArray("_G4D", g4Darray); break; } } return(crtList[noiseID]); }
public static CustomRenderTexture GenerateNoise2DRT(Noise2DType type, float scale, int width, int height, int depth = 128) { CustomRenderTexture noiseRT = new CustomRenderTexture(width, height); noiseRT.format = RenderTextureFormat.RFloat; noiseRT.wrapMode = TextureWrapMode.Repeat; noiseRT.filterMode = FilterMode.Bilinear; noiseRT.updateMode = CustomRenderTextureUpdateMode.Realtime; noiseRT.initializationMode = CustomRenderTextureUpdateMode.Realtime; noiseRT.initializationSource = CustomRenderTextureInitializationSource.Material; noiseRT.enableRandomWrite = true; noiseRT.dimension = UnityEngine.Rendering.TextureDimension.Tex2D; noiseRT.material = new Material(Shader.Find(noise2DDict[type])); noiseRT.initializationMaterial = noiseRT.material; noiseRT.shaderPass = 0; noiseRT.material.SetFloat("_Scale", scale); noiseRT.Initialize(); noiseRT.Update(); noiseRT.Create(); return(noiseRT); }