The official response on AnswerHubis that it is not a bug. I’m not so sure yet. Either way, hiding the seams is not an option for me because I’m writing a procedural building generation tool that heavily relies on instanced meshes.
I’ve spent almost three full days trying to come up with a solution, but while I’ve made some progress, I haven’t been able to fully understand or solve the problem.
The problem will affect almost everyone who’s using scaled instanced meshes, and I’d really be grateful for any help I can get.
Here’s an in-depth look at my findings:
The Problem
Non-uniformly scaled instanced meshes are lit incorrectly, even in fully dynamic lighting. I’ve established that this is a result of incorrect normal data. This problem occurs only on instanced meshes, and not on static meshes. Check out the first post in this thread for a screenshot of the incorrect lighting artifacts.
My Observations
I made a simple blueprint script to equally scale instanced meshes and static meshes. Using a simple material, I visualize normals in local space. (Instanced mesh on top, static mesh on bottom, both scaled on the local X axis.
Result: Click to see GIF
Here’s the same operation, but now the material displays normals in tangent space.
Result: Click to see GIF
I had a hunch that I could solve this issue by dynamically generating a normal map to correct the normals. However, this is more tricky than just supplying (0,0,1) (the color blue) into the normal. Observe what happens when I input (1, 0, 0) (red) into the normals.
Result: Click to see GIF
Note that as the instanced mesh stretches, the normals no longer “obey” the normal map. This leads me to believe that the tangent space itself is being distorted. This is the part of the problem I don’t fully understand.
My Attempts
I tried a lot of things to make this work, but none of them worked completely. Here are two attempts that worked to some extent:
Attempt 1
Here’s a material that successfully corrects the “green faces” (with normals along the Y axis) when the mesh is stretched on X upto a certain point, but fails when stretched along the Z axis.
Attempt 2
Here’s a material that works in tangent space, and works for the X stretch, but again, fails for the Z stretch.
Important Considerations
The dimensions of this mesh are 200x20x250. The mesh was created in blender, all of the edges were split, and the mesh was exported with smoothing groups set to ‘Off’.
The same issue occurs even on a four vertex plane (a quad), and is not a problem with this specific mesh.
This is not a problem with the UV mapping, because (1) the problem doesn’t occur on static meshes which use the same mesh asset, (2) the lighting is fully dynamic, and (3) I’ve shown clearly that this is a result of normals distortion.
Hiding the seams is not a solution. Instanced meshes are critical to rendering large amounts of geometry, and I think this is a rather large functional hole.
Reproducing the Issue
I’ve provided the blueprint and the mesh for download at the AnswerHub link.
Closing Notes
This is a rather large roadblock to progress in my current project, and it’d be a huge help if you guys could help.
If you want to get in touch, you can post here, or contact me at apoorva.ramesh.joshi@gmail.com.