private void ResizeSplatControlMaps() { for (int i = 0; i < SplatControlMapCount; ++i) { Texture2D t = GetSplatControl(i); if (t == null) { return; } Texture2D tmp = GCommon.CreateTexture(SplatControlResolution, Color.clear); RenderTexture rt = new RenderTexture(SplatControlResolution, SplatControlResolution, 32, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); GCommon.CopyToRT(t, rt); GCommon.CopyFromRT(tmp, rt); rt.Release(); Object.DestroyImmediate(rt); tmp.name = t.name; tmp.filterMode = t.filterMode; tmp.wrapMode = t.wrapMode; Object.DestroyImmediate(t, true); SplatControls[i] = tmp; GCommon.TryAddObjectToAsset(tmp, TerrainData); } UpdateMaterials(); }
private void ReFormatHeightMap() { if (heightMap == null) { return; } if (heightmapVersion < HEIGHT_MAP_VERSION_ENCODE_RG) { Texture2D tmp = new Texture2D(HeightMapResolution, HeightMapResolution, HeightMapFormat, false); RenderTexture rt = new RenderTexture(HeightMapResolution, HeightMapResolution, 32, HeightMapRTFormat); Material mat = GInternalMaterials.HeightmapConverterEncodeRGMaterial; mat.SetTexture("_MainTex", heightMap); GCommon.DrawQuad(rt, GCommon.FullRectUvPoints, mat, 0); GCommon.CopyFromRT(tmp, rt); rt.Release(); Object.DestroyImmediate(rt); tmp.name = heightMap.name; tmp.filterMode = heightMap.filterMode; tmp.wrapMode = heightMap.wrapMode; Object.DestroyImmediate(heightMap, true); heightMap = tmp; GCommon.TryAddObjectToAsset(heightMap, TerrainData); heightmapVersion = HEIGHT_MAP_VERSION_ENCODE_RG; Debug.Log("Polaris auto upgrade: Converted Height Map from RGBAFloat to RGBA32."); } }
public void SetMesh(string key, Mesh mesh) { if (GeneratedMeshes.ContainsKey(key)) { Mesh oldMesh = GeneratedMeshes[key]; if (oldMesh != null) { GUtilities.DestroyObject(oldMesh); } GeneratedMeshes.Remove(key); } GCommon.TryAddObjectToAsset(mesh, this); GeneratedMeshes.Add(key, mesh); GCommon.SetDirty(this); }
private void ResampleMaskMap() { if (maskMap == null) { return; } Texture2D tmp = new Texture2D(MaskMapResolution, MaskMapResolution, TextureFormat.RGBA32, false); RenderTexture rt = new RenderTexture(MaskMapResolution, MaskMapResolution, 32, RenderTextureFormat.ARGB32); GCommon.CopyToRT(maskMap, rt); GCommon.CopyFromRT(tmp, rt); rt.Release(); Object.DestroyImmediate(rt); tmp.name = maskMap.name; tmp.filterMode = maskMap.filterMode; tmp.wrapMode = maskMap.wrapMode; Object.DestroyImmediate(maskMap, true); maskMap = tmp; GCommon.TryAddObjectToAsset(maskMap, TerrainData); }
public Texture2D GetSplatControl(int index) { if (index < 0 || index >= SplatControlMapCount) { throw new System.ArgumentException("Index must be >=0 and <=SplatControlMapCount"); } else { Texture2D t = SplatControls[index]; if (t == null) { Color fillColor = (index == 0 && SplatControlMapCount == 1) ? new Color(1, 0, 0, 0) : new Color(0, 0, 0, 0); t = GCommon.CreateTexture(SplatControlResolution, fillColor); t.filterMode = FilterMode.Bilinear; t.wrapMode = TextureWrapMode.Clamp; t.name = SPLAT_CONTROL_MAP_NAME + " " + index; SplatControls[index] = t; } GCommon.TryAddObjectToAsset(t, TerrainData); return(t); } }
private void ResizeMetallicMap() { if (metallicMap == null) { return; } Texture2D tmp = GCommon.CreateTexture(MetallicMapResolution, Color.black); RenderTexture rt = new RenderTexture(MetallicMapResolution, MetallicMapResolution, 32, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); GCommon.CopyToRT(metallicMap, rt); GCommon.CopyFromRT(tmp, rt); rt.Release(); Object.DestroyImmediate(rt); tmp.name = metallicMap.name; tmp.filterMode = metallicMap.filterMode; tmp.wrapMode = metallicMap.wrapMode; Object.DestroyImmediate(metallicMap, true); metallicMap = tmp; GCommon.TryAddObjectToAsset(metallicMap, TerrainData); UpdateMaterials(); }
private void ResampleHeightMap() { if (heightMap == null) { return; } Texture2D tmp = new Texture2D(HeightMapResolution, HeightMapResolution, HeightMapFormat, false); RenderTexture rt = new RenderTexture(HeightMapResolution, HeightMapResolution, 32, HeightMapRTFormat); GCommon.CopyToRT(heightMap, rt); GCommon.CopyFromRT(tmp, rt); rt.Release(); Object.DestroyImmediate(rt); tmp.name = heightMap.name; tmp.filterMode = heightMap.filterMode; tmp.wrapMode = heightMap.wrapMode; Object.DestroyImmediate(heightMap, true); heightMap = tmp; GCommon.TryAddObjectToAsset(heightMap, TerrainData); Internal_CreateNewSubDivisionMap(); SetRegionDirty(GCommon.UnitRect); }
public void UpdateLookupTextures() { if (colorByHeightMap != null) { Object.DestroyImmediate(colorByHeightMap, true); } if (colorByNormalMap != null) { Object.DestroyImmediate(colorByNormalMap, true); } if (colorBlendMap != null) { Object.DestroyImmediate(colorBlendMap, true); } int width = 256; int height = 8; colorByHeightMap = new Texture2D(width, height, TextureFormat.ARGB32, false, true); colorByHeightMap.filterMode = FilterMode.Bilinear; colorByHeightMap.wrapMode = TextureWrapMode.Clamp; colorByHeightMap.name = COLOR_BY_HEIGHT_MAP_NAME; colorByNormalMap = new Texture2D(width, height, TextureFormat.ARGB32, false, true); colorByNormalMap.filterMode = FilterMode.Bilinear; colorByNormalMap.wrapMode = TextureWrapMode.Clamp; colorByNormalMap.name = COLOR_BY_NORMAL_MAP_NAME; colorBlendMap = new Texture2D(width, height, TextureFormat.ARGB32, false, true); colorBlendMap.filterMode = FilterMode.Bilinear; colorBlendMap.wrapMode = TextureWrapMode.Clamp; colorBlendMap.name = COLOR_BLEND_MAP_NAME; Color[] cbhColors = new Color[width * height]; Color[] cbnColors = new Color[width * height]; Color[] cbColors = new Color[width * height]; for (int x = 0; x < width; ++x) { float f = Mathf.InverseLerp(0, width - 1, x); Color cbh = ColorByHeight.Evaluate(f); Color cbn = ColorByNormal.Evaluate(f); Color cb = Color.white * ColorBlendCurve.Evaluate(f); for (int y = 0; y < height; ++y) { int index = GUtilities.To1DIndex(x, y, width); cbhColors[index] = cbh; cbnColors[index] = cbn; cbColors[index] = cb; } } colorByHeightMap.SetPixels(cbhColors); colorByHeightMap.Apply(); GCommon.TryAddObjectToAsset(colorByHeightMap, TerrainData); colorByNormalMap.SetPixels(cbnColors); colorByNormalMap.Apply(); GCommon.TryAddObjectToAsset(colorByNormalMap, TerrainData); colorBlendMap.SetPixels(cbColors); colorBlendMap.Apply(); GCommon.TryAddObjectToAsset(colorBlendMap, TerrainData); }