コード例 #1
0
    void OnGUI()
    {
        if (GUILayout.Button("Build Perlin Noise Texture Maps", GUILayout.MinHeight(60)))
        {
            var perlinNoiseMap = GenerateMap(1.0f / 8.0f);

            PG_Tools.SaveAsPNG(perlinNoiseMap, Application.dataPath + "/Maps/Perlin Noise/perlin_noise.png");
        }
    }
コード例 #2
0
    void OnGUI()
    {
        if (GUILayout.Button("Build Atmosphere Skybox", GUILayout.MinHeight(60)))
        {
            GenerateMaps(out var bottomMap, out var sideMap, out var topMap);

            PG_Tools.SaveAsPNG(bottomMap, Application.dataPath + "/Maps/Skyboxes/Planet/planet_bottom.png");
            PG_Tools.SaveAsPNG(sideMap, Application.dataPath + "/Maps/Skyboxes/Planet/planet_sides.png");
            PG_Tools.SaveAsPNG(topMap, Application.dataPath + "/Maps/Skyboxes/Planet/planet_top.png");
        }
    }
コード例 #3
0
    void OnGUI()
    {
        if (GUILayout.Button("Build Atmosphere Normal Map", GUILayout.MinHeight(60)))
        {
            m_filename = EditorUtility.SaveFilePanel("Image File Name", Path.GetDirectoryName(m_filename), Path.GetFileName(m_filename), "png");

            if (m_filename.Length > 0)
            {
                var baseFileName = Path.GetDirectoryName(m_filename) + "/" + Path.GetFileNameWithoutExtension(m_filename);

                Debug.Log("baseFileName = " + baseFileName);

                GenerateMaps(out var normalMap, out var opacityMap);

                PG_Tools.SaveAsPNG(normalMap, baseFileName + " - Normal.png");
                PG_Tools.SaveAsPNG(opacityMap, baseFileName + " - Opacity.png");
            }
        }
    }
コード例 #4
0
    // call this to generate the planet texture maps
    bool GeneratePlanetTextureMaps(PG_Planet pgPlanet, string filename)
    {
        // vars for the progress bar
        var currentStep = 1;
        var totalSteps  = 8;

        // update the progress bar
        EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Preparing color map...", (float)currentStep++ / totalSteps);

        // prepare the color map
        var preparedColorMap = PrepareColorMap(pgPlanet);

        if (m_debugMode)
        {
            EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Saving prepared color map...", 0.0f);

            PG_Tools.SaveAsPNG(preparedColorMap, Application.dataPath + "/Exported/Debug - Prepared Color Map.png");
        }

        // update the progress bar
        EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Preparing height map...", (float)currentStep++ / totalSteps);

        // prepare the height map
        var preparedHeightMap = PrepareHeightMap(pgPlanet);

        if (m_debugMode)
        {
            EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Saving prepared height map...", 0.0f);

            PG_Tools.SaveAsPNG(preparedHeightMap, Application.dataPath + "/Exported/Debug - Prepared Height Map.png");
        }

        float minimumDifference = 0.0f;
        float maximumDifference = 0.0f;

        byte[] differenceBuffer = null;

        if (pgPlanet.m_surfaceId != 1)
        {
            // scale to power of two
            EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Scaling to power of two...", (float)currentStep++ / totalSteps);

            var bicubicScale = new PG_BicubicScaleElevation();

            var elevation = bicubicScale.Process(preparedHeightMap, m_textureMapWidth, m_textureMapHeight);

            if (m_debugMode)
            {
                EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Saving bicubic scale map...", 0.0f);

                var contourMap = new PG_ContourMap();

                var tempBuffer = contourMap.Process(elevation, pgPlanet.m_waterElevation);

                PG_Tools.SaveAsEXR(tempBuffer, Application.dataPath + "/Exported/Debug - Bicubic Scale.exr");
            }

            // craters pass
            EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Creating craters...", (float)currentStep++ / totalSteps);

            if (pgPlanet.m_atmosphericDensityId == 0)
            {
                var craters = new PG_Craters();

                elevation = craters.Process(elevation, pgPlanet.m_id, m_craterGain, pgPlanet.m_waterElevation);

                if (m_debugMode)
                {
                    EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Saving craters map...", 0.0f);

                    var contourMap = new PG_ContourMap();

                    var tempBuffer = contourMap.Process(elevation, pgPlanet.m_waterElevation);

                    PG_Tools.SaveAsEXR(tempBuffer, Application.dataPath + "/Exported/Debug - Craters.exr");
                }
            }

            // at this point we want to save the current elevation buffer to use when calculating the difference map later
            var baseElevationBuffer = elevation;

            // mountains pass
            EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Creating mountains...", (float)currentStep++ / totalSteps);

            if (pgPlanet.m_atmosphericDensityId != 0)
            {
                var mountains = new PG_Mountains();

                elevation = mountains.Process(elevation, pgPlanet.m_id, m_octaves, m_mountainScale, m_mountainLacunarity, m_mountainPersistence, m_mountainGain, pgPlanet.m_waterElevation);

                if (m_debugMode)
                {
                    EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Saving mountains map...", 0.0f);

                    var contourMap = new PG_ContourMap();

                    var tempBuffer = contourMap.Process(elevation, pgPlanet.m_waterElevation);

                    PG_Tools.SaveAsEXR(tempBuffer, Application.dataPath + "/Exported/Debug - Mountains.exr");
                }
            }

            // hydraulic erosion pass
            var minimumElevation = pgPlanet.m_waterElevation - (pgPlanet.m_waterElevation / 16.0f);

            EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Hydraulic erosion pass...", (float)currentStep++ / totalSteps);

            if (m_doHydraulicErosionPass)
            {
                if (pgPlanet.m_atmosphericDensityId != 0)
                {
                    var hydraulicErosion = new PG_HydraulicErosion();

                    var gravityConstant = m_gravityConstant * pgPlanet.m_gravity;
                    var rainWaterAmount = m_rainWaterAmount * (float)pgPlanet.m_atmosphericDensityId / 3.0f;

                    elevation = hydraulicErosion.Process(elevation, minimumElevation, m_xyScaleToMeters, m_zScaleToMeters, rainWaterAmount, m_sedimentCapacity, gravityConstant, m_frictionConstant, m_evaporationConstant, m_depositionConstant, m_dissolvingConstant, m_stepDeltaTime, m_finalBlurRadius);

                    if (elevation == null)
                    {
                        return(false);
                    }

                    if (m_debugMode)
                    {
                        EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Saving hydraulic erosion map...", 0.0f);

                        var contourMap = new PG_ContourMap();

                        var tempBuffer = contourMap.Process(elevation, pgPlanet.m_waterElevation);

                        PG_Tools.SaveAsEXR(tempBuffer, Application.dataPath + "/Exported/Debug - Hydraulic Erosion.exr");
                    }
                }
            }

            if (m_debugMode)
            {
                // generate and save the albedo map
                EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Saving albedo map...", 0.0f);

                var albedoMap = new PG_AlbedoMap();

                var albedoBuffer = albedoMap.Process(elevation, preparedColorMap, pgPlanet.m_waterElevation, pgPlanet.m_waterColor, pgPlanet.m_groundColor);

                PG_Tools.SaveAsPNG(albedoBuffer, Application.dataPath + "/Exported/Debug - Albedo Map.png");

                // generate and save the normal map
                EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Saving normal map...", 0.0f);

                var normalMap = new PG_NormalMap();

                var normalsBuffer = normalMap.Process(elevation, 256.0f, pgPlanet.m_waterElevation, 1);

                PG_Tools.SaveAsPNG(normalsBuffer, Application.dataPath + "/Exported/Debug - Normal Map.png");

                // generate and save the specular map
                EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Saving specular map...", 0.0f);

                var waterSpecularColor = new Color(1.0f, 1.0f, 1.0f);

                var specularMap = new PG_SpecularMap();

                var specularBuffer = specularMap.Process(elevation, albedoBuffer, pgPlanet.m_waterElevation, waterSpecularColor, 0.75f, 1);

                PG_Tools.SaveAsPNG(specularBuffer, Application.dataPath + "/Exported/Debug - Specular Map.png", true);

                // generate and save the water mask map
                EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Saving water mask map...", 0.0f);

                var waterMaskMap = new PG_WaterMaskMap();

                var waterMaskBuffer = waterMaskMap.Process(elevation, pgPlanet.m_waterElevation, 1);

                PG_Tools.SaveAsPNG(waterMaskBuffer, Application.dataPath + "/Exported/Debug - Water Mask Map.png", true);

                // generate and save the elevation map (for the terrain grid)
                EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Saving elevation map...", 0.0f);

                PG_Tools.SaveAsEXR(elevation, Application.dataPath + "/Exported/Debug - Elevation Map.exr");
            }

            // figure out what our minimum and maximum deltas are
            EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Computing deltas...", (float)currentStep++ / totalSteps);

            minimumDifference = 0;
            maximumDifference = 0;

            for (var y = 0; y < m_textureMapHeight; y++)
            {
                for (var x = 0; x < m_textureMapWidth; x++)
                {
                    var difference = elevation[y, x] - baseElevationBuffer[y, x];

                    if (difference < minimumDifference)
                    {
                        minimumDifference = difference;
                    }

                    if (difference > maximumDifference)
                    {
                        maximumDifference = difference;
                    }
                }
            }

            // rescale float deltas to 0 to 255
            var elevationScale = 255.0f / (maximumDifference - minimumDifference);

            differenceBuffer = new byte[m_textureMapWidth * m_textureMapHeight];

            for (var y = 0; y < m_textureMapHeight; y++)
            {
                for (var x = 0; x < m_textureMapWidth; x++)
                {
                    var difference = (byte)Mathf.RoundToInt((elevation[y, x] - baseElevationBuffer[y, x] - minimumDifference) * elevationScale);

                    differenceBuffer[y * m_textureMapWidth + x] = difference;

                    elevation[y, x] = difference / 255.0f;
                }
            }

            if (m_debugMode)
            {
                EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Saving difference buffer...", 0.0f);

                PG_Tools.SaveAsPNG(elevation, Application.dataPath + "/Exported/" + "Debug - Difference Buffer.png");

                AssetDatabase.Refresh();
            }
        }

        // save the map!
        EditorUtility.DisplayProgressBar("Planet " + (pgPlanet.m_id + 1), "Compressing and saving the planet data...", (float)currentStep++ / totalSteps);

        SavePlanetMap(filename, pgPlanet, preparedHeightMap, preparedColorMap, minimumDifference, maximumDifference, differenceBuffer);

        return(true);
    }