示例#1
0
        private void RenderNoiseTexture(RenderTexture noiseMap, GStylizedTerrain terrain)
        {
            GNoisePainterParams      param    = GTexturePainterCustomParams.Instance.Noise;
            GNoiseMapGenerator       gen      = new GNoiseMapGenerator();
            GNoiseMapGeneratorParams genParam = new GNoiseMapGeneratorParams();

            genParam.Type = param.Type;
            if (param.UseWorldSpace && terrain != null)
            {
                Vector3 terrainSize = new Vector3(
                    terrain.TerrainData.Geometry.Width,
                    terrain.TerrainData.Geometry.Height,
                    terrain.TerrainData.Geometry.Length);
                Vector3 terrainPos = terrain.transform.position;

                if (genParam.Type == GNoiseType.Voronoi)
                {
                    genParam.Origin = param.Origin + new Vector2(terrainPos.x / terrainSize.x, terrainPos.z / terrainSize.z);
                }
                else
                {
                    genParam.Origin = param.Origin + new Vector2(terrainPos.x * param.Frequency / terrainSize.x, terrainPos.z * param.Frequency / terrainSize.z);
                }
            }
            else
            {
                genParam.Origin = param.Origin;
            }
            genParam.Frequency   = param.Frequency;
            genParam.Lacunarity  = param.Lacunarity;
            genParam.Persistence = param.Persistence;
            genParam.Octaves     = param.Octaves;
            genParam.Seed        = param.Seed;
            gen.Generate(noiseMap, genParam);
        }
示例#2
0
        public void Editor_DrawCustomParamsGUI()
        {
#if UNITY_EDITOR
            string label = "Noise Painting";
            string id    = "noise-painter";

            GCommonGUI.Foldout(label, true, id, () =>
            {
                GNoisePainterParams param = GTexturePainterCustomParams.Instance.Noise;

                EditorGUILayout.GetControlRect(GUILayout.Height(1));
                Rect r = EditorGUILayout.GetControlRect(GUILayout.Height(200));
                RenderTexture preview = GTerrainTexturePainter.Internal_GetRenderTexture(null, 200, 0);
                RenderNoiseTexture(preview, null);
                EditorGUI.DrawPreviewTexture(r, preview, null, ScaleMode.ScaleToFit);
                EditorGUILayout.GetControlRect(GUILayout.Height(1));

                param.Type          = (GNoiseType)EditorGUILayout.EnumPopup("Type", param.Type);
                param.Origin        = GCommonGUI.InlineVector2Field("Origin", param.Origin);
                param.Frequency     = EditorGUILayout.FloatField("Frequency", param.Frequency);
                param.Lacunarity    = EditorGUILayout.FloatField("Lacunarity", param.Lacunarity);
                param.Persistence   = EditorGUILayout.FloatField("Persistence", param.Persistence);
                param.Octaves       = EditorGUILayout.IntField("Octaves", param.Octaves);
                param.Seed          = EditorGUILayout.FloatField("Seed", param.Seed);
                param.UseWorldSpace = EditorGUILayout.Toggle("World Space", param.UseWorldSpace);

                GTexturePainterCustomParams.Instance.Noise = param;

                EditorUtility.SetDirty(GTexturePainterCustomParams.Instance);
            });
#endif
        }