private void RenderGeometryHeightMap(GStylizedTerrain terrain, RenderTexture targetRt) { GGeneralParams param = GTextureToolParams.Instance.General; RenderTexture rt = terrain.GetHeightMap(param.Resolution); GCommon.CopyToRT(rt, targetRt); }
public static void Render( RenderTexture rt, GConditionalStampLayer layer, GStylizedTerrain terrain, Matrix4x4 stamperTransform, Texture mask, Texture falloffTexture, Vector2[] uvPoints, bool useTerrainMask) { GCommon.ClearRT(rt); if (layer.Ignore) { return; } Material brushMat = GInternalMaterials.TextureStamperBrushMaterial; int resolution = Mathf.Max(rt.width, rt.height); //no need to release these maps RenderTexture heightMap = terrain.GetHeightMap(resolution); RenderTexture normalMap = layer.NormalMapMode == GNormalMapMode.Sharp ? terrain.GetSharpNormalMap(resolution) : layer.NormalMapMode == GNormalMapMode.Interpolated ? terrain.GetInterpolatedNormalMap(resolution) : layer.NormalMapMode == GNormalMapMode.PerPixel ? terrain.GetPerPixelNormalMap(resolution) : null; brushMat.SetTexture("_HeightMap", heightMap); Vector3 position = stamperTransform.MultiplyPoint(Vector3.zero); Vector3 scale = stamperTransform.lossyScale; float stamperMinHeight = terrain.WorldPointToNormalized(position).y; float stamperMaxHeight = terrain.WorldPointToNormalized(position + Vector3.up * scale.y).y; brushMat.SetFloat("_StamperMinHeight", stamperMinHeight); brushMat.SetFloat("_StamperMaxHeight", stamperMaxHeight); Vector3 terrainSize = new Vector3( terrain.TerrainData.Geometry.Width, terrain.TerrainData.Geometry.Height, terrain.TerrainData.Geometry.Length); brushMat.SetTexture("_Mask", mask); brushMat.SetTexture("_Falloff", falloffTexture); brushMat.SetFloat("_MinHeight", GUtilities.InverseLerpUnclamped(0, terrainSize.y, layer.MinHeight)); brushMat.SetFloat("_MaxHeight", GUtilities.InverseLerpUnclamped(0, terrainSize.y, layer.MaxHeight)); brushMat.SetTexture("_HeightTransition", layer.heightTransitionTexture); brushMat.SetFloat("_MinSlope", layer.MinSlope * Mathf.Deg2Rad); brushMat.SetFloat("_MaxSlope", layer.MaxSlope * Mathf.Deg2Rad); brushMat.SetTexture("_SlopeTransition", layer.slopeTransitionTexture); brushMat.SetVector("_NoiseOrigin", layer.NoiseOrigin); brushMat.SetFloat("_NoiseFrequency", layer.NoiseFrequency); brushMat.SetInt("_NoiseOctaves", layer.NoiseOctaves); brushMat.SetFloat("_NoiseLacunarity", layer.NoiseLacunarity); brushMat.SetFloat("_NoisePersistence", layer.NoisePersistence); brushMat.SetTexture("_NoiseRemap", layer.noiseRemapTexture); brushMat.SetTexture("_NormalMap", normalMap); if (useTerrainMask) { brushMat.SetTexture("_TerrainMask", terrain.TerrainData.Mask.MaskMap); } else { brushMat.SetTexture("_TerrainMask", Texture2D.blackTexture); } GCommon.SetMaterialKeywordActive(brushMat, BLEND_HEIGHT_KW, layer.BlendHeight); GCommon.SetMaterialKeywordActive(brushMat, BLEND_SLOPE_KW, layer.BlendSlope); GCommon.SetMaterialKeywordActive(brushMat, BLEND_NOISE_KW, layer.BlendNoise); DrawOnBrushTexture(rt, uvPoints, brushMat, 0); }