Closed: Water Vertex Displacement Issue with CombineMeshes and Shader Graph

Description:
I am seeking assistance with a challenge I’m facing in Unity regarding CombineMeshes and Shader Graph. My objective is to combine water meshes to reduce draw calls, considering that each mesh is unique in its own way, and everything is procedural generated at runtime.

m_CombineInstance = new CombineInstance[filters.Length];
for (var i = 0; i < m_CombineInstance.Length; i++)
{
    m_CombineInstance[i].mesh = filters[i].sharedMesh;
    m_CombineInstance[i].transform = filters[i].transform.localToWorldMatrix;
    filters[i].gameObject.SetActive(false);
}

Problem Overview:

  • When testing individual meshes independently, everything behaves as anticipated with no discernible gaps; the meshes maintain their integrity even when combined.
  • Upon combining meshes using CombineMeshes, the world space position becomes slightly misaligned.
  • While all water features are correctly placed in the world space, a gap appears specifically at the four outer edges of the mesh when combined.
  • I can confirm that the issue is not related to the parent, as transforms are reset to defaults (zero).
  • The combined meshes represent the water features nearest to the island, and upon closer inspection, it’s evident that the edges are not animating as expected.
  • In this current example, there are a total of 64 meshes combined.

9671594--1377962--Screenshots.gif

Mesh Details:
The meshes represent SubMeshes and share the same material, utilizing Matrix transforms of the CombineMeshes function.

 mesh.CombineMeshes(m_CombineInstance, true);

Troubleshooting Steps:
Attempted to use the filters Matrix without success.

meshFilters[i].transform.localToWorldMatrix

Tried setting the vertices Matrix to world space, without success.

newVerts[i] = m.MultiplyPoint3x4(origVerts[i])

Observations:

  • Noticed that the vertex displacement doesn’t extend beyond the rendering bounds of the parent GameObject of the CombineMeshes.
  • Considering that the meshes are now SubMeshes, there is a suspicion that they might not be returning the correct world space position, despite attempting to set the vertices to world space positions (as shown in the snippet above).

Additional Details:
Unity Version: 2022.2
OS: SteamDeck

Request for Assistance:
Seeking insights, suggestions, or solutions from the community regarding the misalignment issue when combining meshes and its impact on Shader Graph rendering. Any help or guidance would be greatly appreciated!

Update:
It appears that the problem may be attributed to the rendering bounds of CombineMeshes. In the provided test screenshot, the ShaderGraph accurately calculates the shader world positions. However, during wave animation, synchronization issues arise when combining the Ocean meshes into a single combined mesh.

Post:
Perhaps this post is no longer suitable for the Shader Graph thread.

Update:
I can verify that this is not the root cause of the problem. Even after enlarging the rendering bounds of the combined meshes, the outcomes remain consistent.

var mesh = new Mesh { name = "OceanCombinedMesh" };
mesh.CombineMeshes(m_CombineInstance, true);
var size = 512.0f;
mesh.bounds = new Bounds(mesh.bounds.center, mesh.bounds.size + new Vector3(size, size, size));

After conducting numerous tests to identify potential issues and rule out various possibilities, I have reached an impasse. My speculation is that the problem may stem from the fact that the combined mesh is treated as a single entity with all vertices stored in a single array, possibly causing the shader’s vertex displacement to be slightly out of sync.

I have decided to abandon this approach and revert to what has been proven to work. I will no longer pursue the combining of meshes.

I have read everything and I am not sure what is your exact problem to be honest, I can see first gif, but it’s hard to read what is that, plus you never show us your shader graph, so it is impossible to determine what is wrong.

Also where are your meshes, is all water combined into single mesh or we are talking only about the ligher blue square?

I don’t understand logic behind this, why it’s out of sync?

Thank you for your assistance. After extensive testing, I have determined that Shader Graph is not the issue. The problem lies with the CombinedMesh. I would like to remove this entire thread, but I am unsure how to do so. I have changed the status to “other” because the issue remains unresolved, and it would have been helpful to have the option to close the thread.

You could ask to move this thread to other section, but if you managed to determine what caused your issues then it might be helpful to others with similar problem in the future.

1 Like