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(); }
internal void Internal_CreateNewSubDivisionMap(Texture altHeightMap) { if (subDivisionMap != null) { if (subDivisionMap.width != GCommon.SUB_DIV_MAP_RESOLUTION || subDivisionMap.height != GCommon.SUB_DIV_MAP_RESOLUTION) { Object.DestroyImmediate(subDivisionMap); } } if (subDivisionMap == null) { subDivisionMap = new Texture2D(GCommon.SUB_DIV_MAP_RESOLUTION, GCommon.SUB_DIV_MAP_RESOLUTION, TextureFormat.ARGB32, false); } int resolution = GCommon.SUB_DIV_MAP_RESOLUTION; RenderTexture rt = new RenderTexture(resolution, resolution, 0, RenderTextureFormat.ARGB32); Material mat = GInternalMaterials.SubDivisionMapMaterial; Graphics.Blit(altHeightMap, rt, mat); GCommon.CopyFromRT(subDivisionMap, rt); rt.Release(); Object.DestroyImmediate(rt); }
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."); } }
private void RestoreHeightMap(Texture2D heightMap) { if (heightMapBackup != null && heightMapBackup.IsCreated()) { GCommon.CopyFromRT(heightMap, heightMapBackup); } }
public void ConvertSplatsToAlbedo() { if (Splats == null) { return; } RenderTexture albedoRt = new RenderTexture(AlbedoMapResolution, AlbedoMapResolution, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); Material mat = GInternalMaterials.SplatsToAlbedoMaterial; for (int i = 0; i < SplatControlMapCount; ++i) { Texture2D controlMap = GetSplatControl(i); mat.SetTexture("_Control0", controlMap); for (int channel = 0; channel < 4; ++channel) { int prototypeIndex = i * 4 + channel; if (prototypeIndex < Splats.Prototypes.Count) { GSplatPrototype p = Splats.Prototypes[prototypeIndex]; mat.SetTexture("_Splat" + channel, p.Texture); Vector2 terrainSize = new Vector2(TerrainData.Geometry.Width, TerrainData.Geometry.Length); Vector2 textureScale = new Vector2( p.TileSize.x != 0 ? terrainSize.x / p.TileSize.x : 0, p.TileSize.y != 0 ? terrainSize.y / p.TileSize.y : 0); Vector2 textureOffset = new Vector2( p.TileOffset.x != 0 ? terrainSize.x / p.TileOffset.x : 0, p.TileOffset.y != 0 ? terrainSize.y / p.TileOffset.y : 0); mat.SetTextureScale("_Splat" + channel, textureScale); mat.SetTextureOffset("_Splat" + channel, textureOffset); } else { mat.SetTexture("_Splat" + channel, null); mat.SetTextureScale("_Splat" + channel, Vector2.zero); mat.SetTextureOffset("_Splat" + channel, Vector2.zero); } } GCommon.DrawQuad(albedoRt, GCommon.FullRectUvPoints, mat, 0); } GCommon.CopyFromRT(AlbedoMap, albedoRt); albedoRt.Release(); GUtilities.DestroyObject(albedoRt); }
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); }
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); }
private void CopyTo(RenderTexture rt, Texture2D targetTex) { GCommon.CopyFromRT(targetTex, rt); targetTex.Apply(); }