简体   繁体   中英

Procedural Planet Spherical Mesh Deformation C# Unity 5

I've been company many of question people post and all the answers you guys give, followed several tutorials and since all the links on my google search are marked as “already visited” I've decided to put my pride aside and post a question for you.

This is my first post so i don't know if im doing that right sorry if not, anyway the problems is this:

I'm working in a C# planetary exploration game on unity 5, I've already built a sphere out of an octagon following some tutorials mentioned here, and also could build the perlin textures and heightmaps with them as well, the problem comes on applying them to the sphere and produce the terrain on the mesh, I know I have to map the vertices and UVs of the sphere to do that, but the problem is that I really suck at the math thing and I couldn't find any step by step to follow, I've heard about Tessellation shaders, LOD, voronoi noise, perlin noise, and got lost on the process. To simplify:

What I have:

  1. I have the spherical mesh

  2. I have the heightmaps

  3. I've assigned them to a material along with the proper normal maps

what I think I; (since honestly, I don't know if this is the correct path anymore) need assistance with:

  1. the code to produce the spherical mesh deformation based on the heightmaps

  2. How to use those Tessellation LOD based shaders and such to make a real size procedural planet

Ty very much for your attention and sorry if I was rude or asked for too much, but any kind of help you could provide will be of a tremendous help for me.

I don't really think I have the ability to give you code specific information but here are a few additions/suggestions for your checklist.

  • If you want to set up an LOD mesh and texture system, the only way I know how to do it is the barebones approach where you physically create lower poly versions of your mesh and texture, then in Unity, write a script where you have an array of distances, and once the player reaches a certain distance away or towards the object, switch to the mesh and that texture that are appropriate for that distance. I presume you could do the same by writing a shader that would do the same thing but the basic idea remains the same. Here's some as an example (I don't know the Unity library too well): 作为示例(我不太了解Unity库):

     int distances[] = {10,100,1000} Mesh mesh[] = {hi_res_mesh, mid_res_mesh, low_res_mesh} Texture texture[] = {hi_res_texture, mid_res_texture, low_res_texture} void Update() { if(player.distance < distances[0]) { gameobject.Mesh = mesh[0] gameobject.Texture = texture[0] else { for(int i = 1; i < distances.length(); i++) { if (player.distance <= distances[i] && player.distance >= distances[i-1]): { gameobject.Texture = texture[i] gameobject.Mesh = mesh[i] } } } } 

If you want real Tesselation based LOD stuff which is more difficult to code: here are some links:

https://developer.nvidia.com/content/opengl-sdk-simple-tessellation-shader

http://docs.unity3d.com/Manual/SL-SurfaceShaderTessellation.html

Essentially the same concept applies. But instead of physically changing the mesh and texture you are using, you change the mesh and texture procedurally using the same idea of having set distances where you change the resolution of the mesh and texture inside of your shader code.

  • As for your issue with spherical mesh deformation. You can do it in a 3d editing software like 3dsMax, Maya, or Blender by importing your mesh and applying a mesh deform modifier and use your texture as the deform texture and then alter the level of deformation to your liking. But if you want to do something more procedural in real time you are going to have to physically alter the verticies of your mesh using the vertex arrays and then retriangulating your mesh or something like that. Sorry I'm less helpful about this topic as I am less knowledgeable about it. Here are the links I could find related to your problem:

http://answers.unity3d.com/questions/274269/mesh-deformation.html

http://forum.unity3d.com/threads/deform-ground-mesh-terrain-with-dynamically-modified-displacement-map.284612/

http://blog.almostlogical.com/2010/06/10/real-time-terrain-deformation-in-unity3d/

Anyways, good luck and please let me know if I have been unclear about something or you need more explanation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM