• 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 /
avatar image
Question by vik.vega · Oct 03, 2012 at 05:25 PM · meshproceduralvertexheightmap

using grayscale texture as heightmap, vertices and pixel don't match

Hello, my problem is shown in the following picture:

alt text

In my scene, I render 6 textures, and use them on a spheriphied cube, as heightmaps. Now, aside the seams at the borders of the faces, ( I've been addressed that it's because of different normals direction, but have no idea on how to deal with them now, tho)

But mainly, there is something wrong, probably in my texture-to-mesh adaptation procedure. In fact, looking at the attached image, you can see that the southern mountains (circled in green) is erroneously repeated on the last vertices of the upper border (the one vertex-wide "cliff" circled in red)

I don't know if it's clear from the image, or from my words, but I have no idea of a better and more precise way of interpreting a pixel-vertex perfect heightmap.

here's the code for rendering the 6 heightmaps

 function rendercubemap()
 {
     var go = new GameObject ("SkyboxCamera", Camera);
     go.camera.backgroundColor = Color.black;
     go.camera.clearFlags = CameraClearFlags.Skybox;
     go.camera.fieldOfView = 90;    
     go.camera.aspect = 1.0;
         
     go.transform.position = transform.position;     
     go.transform.rotation = Quaternion.identity;
 
     for (var orientation = 0; orientation < 2 ; orientation++)
         {
         renderSkyImage(orientation, go);
         singleplane[orientation].renderer.material.mainTexture = top_tex;
         }
 }
 
 
     function renderSkyImage(orientation : int, go : GameObject)
 {
     go.transform.eulerAngles = direzione_angolo[orientation];
     var screenSize = 128;
     
     var rt = new RenderTexture (screenSize, screenSize, 24);
     go.camera.targetTexture = rt;
     
     var screenShot = new Texture2D (screenSize, screenSize, TextureFormat.RGB24, false);
     var screenShotdiff = new Texture2D (screenSize, screenSize, TextureFormat.RGB24, false);
     
     go.camera.Render();
     
     
     RenderTexture.active = rt;
 
     screenShot.ReadPixels (Rect (0, 0, screenSize, screenSize), 0, 0); 
     screenShotdiff.ReadPixels (Rect (0, 0, screenSize, screenSize), 0, 0);
     screenShotdiff = colorizza(screenShotdiff);
     
     
     screenShot.Apply();
     screenShotdiff.Apply();
     
     top_tex=screenShot;
     top_dif=screenShotdiff;
 
     RenderTexture.active = null;
     DestroyImmediate (rt);
 
 }



and here is the part where i use it as a heightmap on the spheriphied planes:

 function elevate()
 {
     
 for (var orientation = 0; orientation < direzione_angolo.length ; orientation++)
     {
         heightMap = singleplane[orientation].renderer.material.mainTexture;
         var baseVertices : Vector3[];
         var mesh : Mesh = singleplane[orientation].GetComponent(MeshFilter).mesh;
         if (baseVertices == null)
         baseVertices = mesh.vertices;
         var vertices = new Vector3[baseVertices.Length];
     //    print(baseVertices.Length);
         var i=16640;
         
         
         
     //texture    
         var y = 0;
         var x = 0;
         var maxvertices = Mathf.Sqrt(baseVertices.Length);
 
         var counter = 0;
     
         for (y=maxvertices;y>0;y--)
         {
             for (x=0;x<maxvertices;x++)
             {
             var pixelHeight = heightMap.GetPixel(x, y).grayscale;
             counter++;
             var vertex = baseVertices[i];
             
             //that is just a temporary workaround to avoid extruding border vertices    
             if(x<1)
             {
             vertex = vertex*1;
             }
             if(y<2)
             {
             vertex = vertex*1;
             }
             if(x>(maxvertices-2))
             {
             vertex = vertex*1;
             }
             if(y>(maxvertices-1))
             {
             vertex = vertex*1;
             }
             
             //if it's not a border vertex, then :
             else if (x>=1 && y>=2 && x<=(maxvertices-2) && y<=(maxvertices-1))
             {
             vertex = vertex*((pixelHeight/10)+1);
             }
             vertices[i] = vertex;
             i--;
             }
         }
         print(counter);
         
     mesh.vertices = vertices;
     mesh.RecalculateNormals();
     mesh.RecalculateBounds();
     print(mesh.vertexCount);
     DestroyImmediate(collider);
     }
 }



thank you all for your time.

immagine.jpg (62.7 kB)
Comment

People who like this

0 Show 0
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

Procedurally generated, vertex colored mesh self-shadowing problem 0 Answers

How to split UV in Mesh 1 Answer

Mesh based on noise 1 Answer

The most efficient method of turning a voronoi graph into unity terrain object? 0 Answers

Vertex count on a procedurally generated map and some related doubts 2 Answers


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