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 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 DrawOnTerrain(GStylizedTerrain t) { Vector3[] worldCorners = GCommon.GetBrushQuadCorners(transform.position, Radius, 0); Vector2[] uvCorners = new Vector2[worldCorners.Length]; for (int i = 0; i < uvCorners.Length; ++i) { uvCorners[i] = t.WorldPointToUV(worldCorners[i]); } Rect dirtyRect = GUtilities.GetRectContainsPoints(uvCorners); if (!dirtyRect.Overlaps(new Rect(0, 0, 1, 1))) { return; } RenderTexture rt = t.GetGrassVectorFieldRenderTexture(); Material mat = GInternalMaterials.InteractiveGrassVectorFieldMaterial; mat.SetFloat("_Opacity", t.TerrainData.Foliage.BendSensitive); int pass = 0; GCommon.DrawQuad(rt, uvCorners, mat, pass); }