Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Googoo04 · Mar 26, 2018 at 10:54 PM · meshproceduralsphereplanetperlin noise

Seamless Terrain on Quad Sphere

Hi everybody, I am trying to make a procedural planet using a quad sphere with mapped 3D noise. However, I cannot find anywhere on the internet how to implement the Z component of the 3d noise. If I place in the vertex's position, No result is received. How can I find a z component for a quad sphere?

code here, in case I made an error somewhere.

 using UnityEngine;
 using System.Collections;
 
 public struct PatchConfig
 {
     public string name;
     public Vector3 uAxis;
     public Vector3 vAxis;
     public Vector3 height;
     public PatchConfig(string aName, Vector3 aUAxis, Vector3 aVAxis)
     {
         name = aName;
         uAxis = aUAxis;
         vAxis = aVAxis;
         height = Vector3.Cross(vAxis, uAxis);
     }
 }
 
 public class Sphere : MonoBehaviour
 {
     private static PatchConfig[] patches = new PatchConfig[]
     {
          new PatchConfig("top", Vector3.right, Vector3.forward),
          new PatchConfig("bottom", Vector3.left, Vector3.forward),
          new PatchConfig("left", Vector3.up, Vector3.forward),
          new PatchConfig("right", Vector3.down, Vector3.forward),
          new PatchConfig("front", Vector3.right, Vector3.down),
          new PatchConfig("back", Vector3.right, Vector3.up)
     };
 
     public int uPatchCount = 2;
     public int vPatchCount = 2;
     public int xVertCount = 250;
     public int yVertCount = 250;
     public float radius = 5f;
     public float seed;
     public float scale;
 
     public Material patchMaterial;
 
     void Start()
     {
         GeneratePatches();
     }
     public static float Perlin3d(float x, float y, float z)
     {
         float AB = Mathf.PerlinNoise(x, y);
         float BC = Mathf.PerlinNoise(y, z);
         float AC = Mathf.PerlinNoise(x, z);
 
         float BA = Mathf.PerlinNoise(y, x);
         float CB = Mathf.PerlinNoise(z, y);
         float CA = Mathf.PerlinNoise(z, x);
 
         float ABC = AB + BC + AC + BA + CB + CA;
         return ABC / 6f;
     }
 
     void GeneratePatch(PatchConfig aConf, int u, int v)
     {
         GameObject patch = new GameObject(aConf.name + "_" + u + v);
         MeshFilter mf = patch.AddComponent<MeshFilter>();
         MeshRenderer rend = patch.AddComponent<MeshRenderer>();
 
         patch.AddComponent<regionTexture>();
 
         rend.sharedMaterial = patchMaterial;
         Mesh m = mf.sharedMesh = new Mesh();
         patch.transform.parent = transform;
         patch.transform.localEulerAngles = Vector3.zero;
         patch.transform.localPosition = Vector3.zero;
         Vector2 UVstep = new Vector2(1f / uPatchCount, 1f / vPatchCount);
         Vector2 step = new Vector2(UVstep.x / (xVertCount - 1), UVstep.y / (yVertCount - 1));
         Vector2 offset = new Vector3((-0.5f + u * UVstep.x), (-0.5f + v * UVstep.y));
         Vector3[] vertices = new Vector3[xVertCount * yVertCount];
         Vector3[] normals = new Vector3[vertices.Length];
         Vector2[] uvs = new Vector2[vertices.Length];
         for (int y = 0; y < yVertCount; y++)
         {
             for (int x = 0; x < xVertCount; x++)
             {
                 
                 
                 int i = x + y * xVertCount;
                 Vector2 p = offset + new Vector2(x * step.x, y * step.y);
                 uvs[i] = p + Vector2.one * 0.5f;
                 Vector3 vec = (aConf.uAxis * p.x + aConf.vAxis * p.y + aConf.height * 0.5f);
                 vec = vec.normalized;
                 
                 float xx = (float)vec.x/ (xVertCount*scale);
                 float yy = (float)vec.y / (yVertCount*scale);
                 float zz = (float)vec.z/(yVertCount*scale);
                 
                 
                 
                 vec = vec * (1.0f+Perlin3d(xx+seed,yy+seed,zz+seed));
                 normals[i] = vec;
                 vertices[i] = vec * radius;
 
             }
         }
 
         int[] indices = new int[(xVertCount - 1) * (yVertCount - 1) * 4];
         for (int y = 0; y < yVertCount - 1; y++)
         {
             for (int x = 0; x < xVertCount - 1; x++)
             {
                 int i = (x + y * (xVertCount - 1)) * 4;
                 indices[i] = x + y * xVertCount;
                 indices[i + 1] = x + (y + 1) * xVertCount;
                 indices[i + 2] = x + 1 + (y + 1) * xVertCount;
                 indices[i + 3] = x + 1 + y * xVertCount;
             }
         }
         m.vertices = vertices;
         m.normals = normals;
         m.uv = uvs;
         m.SetIndices(indices, MeshTopology.Quads, 0);
         m.RecalculateBounds();
     }
 
     void GeneratePatches()
     {
         for (int i = 0; i < 6; i++)
         {
             for (int u = 0; u < uPatchCount; u++)
             {
                 for (int v = 0; v < vPatchCount; v++)
                 {
                     GeneratePatch(patches[i], u, v);
                 }
             }
         }
     }
 }

Please help.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

141 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Triangles for sphere 0 Answers

How to place a mesh on a sphere at a certain point? 0 Answers

Example of Procedural Planet generation? 3 Answers

Procedural Generation : Grass placement 2 Answers

Speherical Planet spawning objects 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges