Пример #1
0
 public Translate(float x, float y, float z, ModuleBase m1)
 {
     module1 = m1;
     this.x = x;
     this.y = y;
     this.z = z;
 }
Пример #2
0
 public Terrace(float min, float max, float power, ModuleBase m1)
 {
     module1 = m1;
     this.min = min;
     this.max = max;
     this.power = power;
 }
Пример #3
0
 public BlendColorModule(ModuleBase m1, ModuleBase m2, ModuleBase m3)
 {
     colorOutput = true;
     module1 = m1;
     module2 = m2;
     module3 = m3;
 }
Пример #4
0
 public Clamp(float min, float max, ModuleBase m1)
 {
     this.min = min;
     this.max = max;
     module1 = m1;
 }
Пример #5
0
 public Exponent(float exp, ModuleBase m1)
 {
     exponent = exp;
     module1 = m1;
 }
Пример #6
0
 public Multiply(ModuleBase m1, ModuleBase m2)
 {
     module1 = m1;
     module2 = m2;
 }
Пример #7
0
        public static Texture2D Generate(int texwidth, ModuleBase module)
        {
            // measure execution time
            System.DateTime startTime = System.DateTime.UtcNow;

            // creates a rectangular heightmap with "distorted" poles from the planet, texture height is calculated from width
            int texheight = texwidth / 2, ty, tx;
            Texture2D tex = new Texture2D(texwidth, texheight, TextureFormat.ARGB32, false);
            Color32[] colors = new Color32[texwidth * texheight];
            float x, y, z, polar, azimut, onebyty, onebytx, halfx, halfy, sinpolar, cospolar;

            onebytx = 1.0f / (float)texwidth;   // onebytx/y is an optimization to prevent recurring divisions
            onebyty = 1.0f / (float)texheight;

            halfx = onebytx * 0.5f;             // halfx/y is the width/height of a half pixel to calculate the midpoint of a pixel
            halfy = onebyty * 0.5f;

            for (ty = 0; ty < texheight; ++ty) {// calculate the 3d position of each pixel on the surface of a normalized sphere (radius 1)

            // description of spherical coordinate system (polar + azimut) can be found here: http://upload.wikimedia.org/wikipedia/commons/8/82/Sphericalcoordinates.svg and here http://en.wikipedia.org/wiki/Spherical_coordinate_system
            polar = ( (float)ty * onebyty + halfy ) * Mathf.PI;     // calculate the polar angle (between positive y in unity (northpole) and the line to the point in space), required in radians 0 to pi

            sinpolar = Mathf.Sin ( polar ); // cache these values as they are the same for each column in the next line
            cospolar = Mathf.Cos ( polar );

            for (tx = 0; tx < texwidth; ++tx) {
                azimut = ( ( ( (float)(tx+texwidth/4) * onebytx + halfx ) * 2.0f ) - 1.0f ) * Mathf.PI;      // calculate the azimut angle (between positive x axis and the line to the point in space), required in radians -pi to +pi,
                x = sinpolar * Mathf.Cos ( azimut );
                z = sinpolar * Mathf.Sin ( azimut );// this is y in the wikipedia formula but because unitys axis are differerent (y and z swapped) its changed here
                y = cospolar;// this is z in the wikipedia formula but because unitys axis are differerent (y and z swapped) its changed here
                Vector3 position = new Vector3(x, y, z);

                Color32 color;
                if(module.colorOutput)
                    color = module.GetColor(position);  // retrieve the height on the actual planet surface by passing the normalized position to the terrain module
                else {
                    float value = (module.GetValue(position) + 1f) / 2f;
                    color = new Color(value, value, value);
                }

                colors[(texheight - ty - 1) * texwidth + tx] = color;
                //tex.SetPixel(tx, texheight - ty - 1,new Color(height,height,height));    // the y direction needs to be reversed to match unity up (+y) equals texture up, otherwise the texture is y-reversed compared with the planet (maybe due to v-definition)
            }
            }
            tex.SetPixels32(colors);
            tex.Apply(); // apply the texture to make the changes persistent

            Debug.Log("Global map generated in " + (float)(System.DateTime.UtcNow - startTime).TotalSeconds * 1000f + "ms");

            return tex;

            /*string fileName = "Planetary_MiniMap.png";
            byte[] bytes = tex.EncodeToPNG();
            System.IO.FileStream   fs = new System.IO.FileStream(fileName,  System.IO.FileMode.Create);
            System.IO.BinaryWriter bw = new System.IO.BinaryWriter(fs);
            bw.Write(bytes);
            bw.Close();
            fs.Close();*/

            // exiguous ***************************************************************************************************
            // exiguous ***************************************************************************************************
        }
Пример #8
0
 public MultiplyColorModule(ModuleBase m1, ModuleBase m2)
 {
     colorOutput = true;
     module1 = m1;
     module2 = m2;
 }
Пример #9
0
 public Abs(ModuleBase m1)
 {
     module1 = m1;
 }
Пример #10
0
 public Abs(ModuleBase m1)
 {
     module1 = m1;
 }
Пример #11
0
 public Subtract(ModuleBase m1, ModuleBase m2)
 {
     module1 = m1;
     module2 = m2;
 }
Пример #12
0
 public Add(ModuleBase m1, ModuleBase m2)
 {
     module1 = m1;
     module2 = m2;
 }
Пример #13
0
 public Blend(ModuleBase m1, ModuleBase m2, ModuleBase m3)
 {
     module1 = m1;
     module2 = m2;
     module3 = m3;
 }
Пример #14
0
 public Power(ModuleBase m1, ModuleBase m2)
 {
     module1 = m1;
     module2 = m2;
 }
Пример #15
0
 public Select(ModuleBase m1, float t, float r)
 {
     module1 = m1;
     this.target = t;
     this.range = r;
 }
Пример #16
0
 public Weight(ModuleBase m1, float weight, float target)
 {
     module1 = m1;
     this.weight = weight;
     this.target = target;
 }
Пример #17
0
        /// <summary>
        /// Generates a preview texture 
        /// </summary>
        private Texture2D Generate(int size)
        {
            Texture2D texture = new Texture2D(size, size, TextureFormat.ARGB32, false);
            Color[] colors = new Color[size * size];

            // get module from the node
            module = node.GetModule();

            // check that node is not null
            if(module != null) {

            node.minValue = Mathf.Infinity;
            node.maxValue = Mathf.NegativeInfinity;

            for(int y = 0; y < size; y++) {
                for(int x = 0; x < size; x++) {
                    Vector3 position = new Vector3((x / (float)size) * zoom + tx, 0f, (y / (float)size) * zoom + ty);
                    if(module.colorOutput) {
                        colors[y * size + x] = module.GetColor(position);
                    }
                    else {
                        float value = module.GetValue(position);
                        if(value < node.minValue)
                            node.minValue = value;
                        if(value > node.maxValue)
                            node.maxValue = value;
                        value = (value + 1f) / 2f;
                        colors[y * size + x] = new Color(value, value, value);
                    }
                }
            }

            node.SetOutputOptions();

            texture.SetPixels(colors);
            texture.Apply();
            }

            return texture;
        }
Пример #18
0
 public Invert(ModuleBase m1)
 {
     module1 = m1;
 }
Пример #19
0
 public Divide(ModuleBase m1, ModuleBase m2)
 {
     module1 = m1;
     module2 = m2;
 }
Пример #20
0
 public Invert(ModuleBase m1)
 {
     module1 = m1;
 }
Пример #21
0
        public void ReloadModules()
        {
            // recreate noise modules
            nodes = new List<Node>(serializedNodes);

            SetSeeds();
            SetFrequencyScale();

            FindOutputNode();
            module = output.GetModule();
        }
Пример #22
0
 public OverlayColorModule(ModuleBase m1, ModuleBase m2)
 {
     colorOutput = true;
     module1 = m1;
     module2 = m2;
 }
Пример #23
0
 public Power(ModuleBase m1, ModuleBase m2)
 {
     module1 = m1;
     module2 = m2;
 }
Пример #24
0
 public GradientModule(ModuleBase m1, Gradient g)
 {
     colorOutput = true;
     module1 = m1;
     gradient = g;
 }
Пример #25
0
        /// <summary>
        /// Generates the textures
        /// </summary>
        private void GenerateTextures(int detail, out Color32[][] colors)
        {
            // measure execution time
            System.DateTime startTime = System.DateTime.UtcNow;

            // texture & colors
            int textureCount = 0;
            for(int i = 0; i < planet.textureNodeInstances.Length; i++) {
            if(planet.textureNodeInstances[i].generateSurfaceTextures)
                textureCount++;
            }
            colors = new Color32[textureCount][];
            ModuleBase[] textureModules = new ModuleBase[textureCount];

            int ii = 0;
            for(int i = 0; i < planet.textureNodeInstances.Length; i++) {
            if(planet.textureNodeInstances[i].generateSurfaceTextures) {
                colors[ii] = new Color32[detail * detail];
                textureModules[ii] = planet.textureNodeInstances[i].node.GetModule();
                ii++;
            }
            }

            // calculate interpolation between coordinates
            float stepX = (bottomright.x - topleft.x) / (detail-1);
            float stepY = (bottomright.y - topleft.y) / (detail-1);
            float stepZ = (bottomright.z - topleft.z) / (detail-1);

            // check which axis remains stationary
            bool staticX = false, staticY = false, staticZ = false;
            if(stepX == 0)
            staticX = true;
            if(stepY == 0)
            staticY = true;
            if(stepZ == 0)
            staticZ = true;

            Vector3 position = Vector3.zero;

            // loop through pixels
            for(int col = 0; col < detail; col++) {
            for(int row = 0; row < detail; row++) {
                // set vertex position
                if(staticX)
                    position = new Vector3(topleft.x, topleft.y + stepY * col, topleft.z + stepZ * row);
                if(staticY)
                    position = new Vector3(topleft.x + stepX * row, topleft.y, topleft.z + stepZ * col);
                if(staticZ)
                    position = new Vector3(topleft.x + stepX * row, topleft.y + stepY * col, topleft.z);

                // map the point on to the sphere
                position = SperifyPoint(position);

                // displace with noise values
                //float displacement = planet.Terrain.module.GetValue(position, -position);

                // take painted heights to account
                /*float rx = modifierStartX + row * modifierMultiplier;
                float cy = modifierStartY + col * modifierMultiplier;
                if(planet.useBicubicInterpolation)
                    displacement += planet.GetBicubicInterpolatedModifierAt(rx, cy, surfacePosition);
                else
                    displacement += planet.GetBilinearInterpolatedModifierAt(rx, cy, surfacePosition);*/

                // get color for each texture
                ii = 0;
                for(int i = 0; i < planet.textureNodeInstances.Length; i++) {
                    if(planet.textureNodeInstances[i].generateSurfaceTextures) {
                        colors[ii][col * detail + row] = textureModules[i].GetColor(position);
                        ii++;
                    }
                }
            }
            }

            if(planet.logGenerationTimes)
            Debug.Log("Texture generated in " + (float)(System.DateTime.UtcNow - startTime).TotalSeconds * 1000f + "ms");
        }
Пример #26
0
 public Multiply(ModuleBase m1, ModuleBase m2)
 {
     module1 = m1;
     module2 = m2;
 }
Пример #27
0
 public Max(ModuleBase m1, ModuleBase m2)
 {
     module1 = m1;
     module2 = m2;
 }
Пример #28
0
 public Curve(SerializableKeyframe[] keyframes, ModuleBase m1)
 {
     this.keyframes = keyframes;
     module1 = m1;
 }
Пример #29
0
 public Blend(ModuleBase m1, ModuleBase m2, ModuleBase m3)
 {
     module1 = m1;
     module2 = m2;
     module3 = m3;
 }
Пример #30
0
 public Subtract(ModuleBase m1, ModuleBase m2)
 {
     module1 = m1;
     module2 = m2;
 }