Javier-Garzo / Marching-cubes-on-Unity-3D

Terrain voxel engine with the use of Marching Cubes implemented in Unity 2020.3.17f1 (LTS).
MIT License
332 stars 43 forks source link

Is the overhang right above slopes expected? #14

Closed kinnexus closed 1 year ago

kinnexus commented 2 years ago

image

I have really enjoyed looking through this project, but it seems that there is an overhang that appears immediately above slopes like the image above. These overhangs look a little strange, but they also interfere with a character attempting to walk up these slopes. Is that overhang intentional?

Javier-Garzo commented 2 years ago

It's not intentional, I try to solve several times and I can't achieve it. I think is a problem related with the noise and the terrain or maybe the interpolation.

kinnexus commented 2 years ago

Looking through the code this evening, I’m guessing that the problem is in this function

public float3 interporlateVertex(float4 p1, float4 p2, out float interpolation) { interpolation = (isoLevel - p1.w) / (p2.w - p1.w); return math.lerp(new float3(p1.x,p1.y,p1.z), new float3(p2.x,p2.y,p2.z), interpolation); }

Specifically, I’m not sure that isoLevel is doing what you want it to, or perhaps you are sending in the wrong p1/p2 vertices. You are getting different vertex values for adjoining voxels that should have the same vertex value, which makes me think that the interpolation is giving a wrong outcome.

I’ll keep looking

From: Javier Garzo @.> Sent: Friday, September 9, 2022 12:31 PM To: Javier-Garzo/Marching-cubes-on-Unity-3D @.> Cc: Greg Coleman @.>; Author @.> Subject: Re: [Javier-Garzo/Marching-cubes-on-Unity-3D] Is the overhang right above slopes expected? (Issue #14)

It's not intentional, I try to solve several times and I can't achieve it. I think is a problem related with the noise and the terrain or maybe the interpolation.

— Reply to this email directly, view it on GitHubhttps://github.com/Javier-Garzo/Marching-cubes-on-Unity-3D/issues/14#issuecomment-1242197654, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEH6HEHJ5KYSWH2HG4PTOE3V5NQ43ANCNFSM6AAAAAAQIY44V4. You are receiving this because you authored the thread.Message ID: @.**@.>>

Javier-Garzo commented 2 years ago

I investigate about the problem and its related to a mix of the way of calculating the interpolation of the vertices, and the way to set the vertex weight of the surface of the terrain and the air ones. I am looking for a solution.

kinnexus commented 1 year ago

Well, after a ton of debug I have a pretty good idea what your code does and while I’m not 100% happy with this solution, it’s much, much better than where it was last week.

In your biome terrain generators try setting the lastVertexWeigh without adjusting for isoLevel, like so

                       int lastVertexWeigh = (int)(255 * ( height % 1));//Weigh of the last vertex

This gets a reasonably smooth interpolation. I settled on this because the terrain adjustment routines hooked to the mouse buttons do the same thing; they use the entire byte range 0 to 255 rather than adjusting for isoLevel and they get nice, smooth interpolation.

From: Javier Garzo @.> Sent: Sunday, September 11, 2022 3:25 PM To: Javier-Garzo/Marching-cubes-on-Unity-3D @.> Cc: Greg Coleman @.>; Author @.> Subject: Re: [Javier-Garzo/Marching-cubes-on-Unity-3D] Is the overhang right above slopes expected? (Issue #14)

I investigate about the problem and its related to a mix of the way of calculating the interpolation of the vertices, and the way to set the vertex weight of the surface of the terrain and the air ones. I am looking for a solution.

— Reply to this email directly, view it on GitHubhttps://github.com/Javier-Garzo/Marching-cubes-on-Unity-3D/issues/14#issuecomment-1243026987, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEH6HECYI5TUNM6WGEHKRJLV5YW2HANCNFSM6AAAAAAQIY44V4. You are receiving this because you authored the thread.Message ID: @.**@.>>

Javier-Garzo commented 1 year ago

Sorry for no find a solution a try changing the interpolation algorithm from bilinial to lineal, and other solutions in the same part of the biomes (all code related with the lastVertexWeigh). And a busy month.

I see your solution as the current best , but it need to solve the problems with the paint of the terrain.

image

There is also a strange generation in the height differences image

However , it's a more organic solution. Good job.