Ulfheden

Normal map shows faces

Recommended Posts

Hi,

There have been numerous threads on this issue kind of, but I just can't find any answer to my problem. I'm using a PBRMaterial, and an xNormal-rendered normal map in tangent space, and I've tried all kind of swizzle coordinates but they all turn out the same it seems. It looks like the normal map causes the polygon shading to not be as smooth anymore. This can't be seen at all in the normal map itself. I've also tried using a pre-triangulated mesh in Xnormal and using that mesh all the way through the pipeline from Blender to Babylon, just in case the problem would be due to the normal map being rendered on a mesh triangulated differently from the way the Babylon-export did it, leading to the normal map and the mesh being slightly incompatible, but the problem persists. I've also tried 16-bit versions...

I've attached an image of what it looks like, from the left: Without normal, with normal, and with normal map and convertToFlatShadedMesh, all at the exact same camera position etc.

Any clues as to what might be the problem? Has anyone successfully used normal maps in BabylonJS without these issues, and, if so, how?

Cheers!

Namnlös.png

Share this post


Link to post
Share on other sites

@Ulfheden, would you be able to share your mesh and textures with us so we can take a look at what is happening. I have used XNormal in the past, but it is not currently a part of my pipeline. I am usually baking normals either in Substance or ZBrush. But we can successfully use normal maps in Babylon.js as can be seen in this demo asset I created. Happy to take a look at the files and debug what is going on. 

Share this post


Link to post
Share on other sites

Nope, haven't tried GLTF at all. So from Blender using the GLTF exporter instead, and then using the same normal map on that in Babylon?

Oh wow, thanks! Here's the mesh and the normal map used in those screenshots above. This normal map has some other artifact under the nose as well, but ignore that for now - it doesn't show up on new Xnormal-rendered normal maps so it might be because of some mistake on my part, but those artifacts in the OP have been persistent for all renders.

The mesh: https://drive.google.com/open?id=11EFFKHfR85aTQzWwJOSHWHQHNqqpsNAp
The normal map: https://drive.google.com/open?id=1miZZ8i6l30L5fQ2Q6LUlVbS1L26GKyyc

Cheers!

Share this post


Link to post
Share on other sites

@Ulfheden I looked into your mesh and the only thing I saw missing was your mesh had hard vertex normals, so when that exports you will see faceting in the mesh. The thing to do is select your mesh and soften your faces/edges:

Blender_Smooth.thumb.PNG.c8d7e7d19c8c06db3de69062b5ee8995.PNG

I also exported a glb (binary version of a glTF) from the Khronos glTF exporter and used that to test. You can drag/drop it right into the sandbox to see how it renders with Babylon, and other apps can handle it like 3D Viewer for Windows or Sketchfab. You can get the plugin and docs at https://github.com/KhronosGroup/glTF-Blender-Exporter. You can see that smoothing the normals renders correctly... I did make the material metallic just so you could see the normal map easier without building a whole lighting rig to see it: 

Babylon_glTF.thumb.PNG.83e9f27efad336cef21fd25b1dd7d531.PNG

I noticed that your rig breaks when exporting it, so I would look into your skeleton creation and where the bone hierarchy paths because this looks like there is a bin pose rotation on the jaw that is causing it to rotate into the skull. Hope this helps!

Share this post


Link to post
Share on other sites

@PatrickRyan, thanks! I managed to replicate what you did and I get the same results as you do in the Sandbox with a glTF file exported from Blender. The issue with the export is weird, I don't get that myself, so maybe we're using different versions of the exporter. I don't get this rotation of the jaw either?

However, in my application, no matter if I'm using StandardMaterial or PBRMaterial, I get the same issue still even after smoothing out the normals.

But after some more testing, I found that the issue was the rig. By unparenting the mesh from the rig, the problem doesn't show up anymore... I don't see what the issue is with my rig - I've limited the number of weights per vertex to 4, and normalized the weights and everything... Here's a RAR with the full package, from a very minimal website to the Babylon files and textures: https://drive.google.com/open?id=1S98dLumerNHDdQ3HOpNuzo1WoZb8j4ir

Share this post


Link to post
Share on other sites

@Ulfheden can you walk me through how you are creating your Babylon file of your mesh from Blender? I can't figure out why the parenting of the mesh would affect the normals of the mesh since you have normals written into the file so there must be something else going on. What exporter are you using and how are you setting up the export? Also, why aren't you getting a materialId in your Babylon file? Are you exporting the mesh with no material? If so, it makes it harder to debug with the sandbox inspector because I don't have access to some of the normal display options when there isn't a material in the file. I'd like to figure out if the issue lies in the file setup, the exporter, or the export process so that we can address any bugs or communicate broadly about the process. 

Share this post


Link to post
Share on other sites

@PatrickRyan of course! I'm using the Babylon exporter "Babylon.js ver 5.6.4" and export by simply going to File->Export and clicking on that exporter. Not many options in there though. I've also tried increasing the precision from three decimals for the various parameters to five (maximum) (these options can be found in the Scene data tab in Blender IIRC), but to no avail.

Actually, even without the rig, the problem is still kind of there... it's just much more difficult to spot and probably won't be a problem when a diffuse texture is in place as well.

That's correct, I don't apply any materials or textures in Blender. All textures are applied in BabylonJS in the JavaScript file. Just for the sake of trying it out, I tried applying the normal map in Blender now and then exporting, and removed the commands importing/setting the textures and materials from the JavaScript code but the problem persists. Still, I've uploaded another Blender file here with the normal map applied in Blender if you prefer that: https://drive.google.com/open?id=1tfxacZW5kMej1WYFry9Sq9DKbkMSNKx3

I also tried exporting the mesh as OBJ and rendering a new normal map with it as the low poly and then importing it to Blender again and exporting to Babylon, to make sure it's the same normals as used when making the normal map, but still got the same result.

Share this post


Link to post
Share on other sites

@Ulfheden I dug into the exporters to the Babylon format for Blender and Maya and am finding some strange behavior that may be bugs. I don't know if its directly related to the normals being sharpened because the normal data is present in the Babylon file. However, I noticed that while the materials are exporting with the mesh coming out of Blender using the Babylon 5.6.4 exporter, the textures aren't being read correctly. I am pinging @kcoley to take a look as he is the one working on our exporters. We've been focused on glTF export lately so neither of us are sure if all the new exporter features are pathing correctly to the Babylon format.

Share this post


Link to post
Share on other sites

The current exporter is an exporter, it is not for generating stuff.  It also does not do PBR.  If by normal map you mean a what the geo values for normals are, then get those values assigned by whatever means you know of in Blender.  The exporter will push them out.  The only thing I have ever done is use the Split Edge modifier to give a flat shaded look.

If you require normals at a finer level than your geometry, add a bump texture to the material.

Share this post


Link to post
Share on other sites

@JCPalmer thank you for the clarification. 

Quote

The current exporter is an exporter, it is not for generating stuff

My apologies, when I mentioned generating normal maps, I meant exporting a normal texture attached to a normal input of a material node.  But I see now that you must attach a bump texture to the normal input, which I was able to verify with the Diffuse Material.  Also thanks for the clarification on PBR not being supported.  

@Ulfheden does this help clear things up for you?

Share this post


Link to post
Share on other sites
18 hours ago, kcoley said:

@JCPalmer thank you for the clarification. 

My apologies, when I mentioned generating normal maps, I meant exporting a normal texture attached to a normal input of a material node.  But I see now that you must attach a bump texture to the normal input, which I was able to verify with the Diffuse Material.  Also thanks for the clarification on PBR not being supported.  

@Ulfheden does this help clear things up for you?

Well, the issue isn't really solved. If I can't get the normal map to render correctly when using a rig, I'd be interested in knowing whether anybody else is able to use normal maps successfully with rigs or if this is specific to my rig (even though I've normalized and limited the number of influences etc.)?

If it has to do with my normal map itself, should I render in Zbrush instead, and using what settings etc.? A description of a working pipeline would be great, because normal maps seem to be so poorly documented in BJS.

Share this post


Link to post
Share on other sites

Do not want to clog this topic with my plans.  Will put out a new topic later today on this.

@Ulfheden, I have little idea of what a 'normal map' is.  Unless it is something new, this is NOT Babylonian terminology.  I tend to ignore people speaking Unity, maya, or whatever.

That said, I'll give you one.  I do not think this has anything to do with exporting.  In general, if a model looks like shit in Blender, then exporting it is not going to improve it.  If you want a smooth mesh without increasing your vertex count:

  1. Right click your mesh.
  2. Goto edit mode (tab key).
  3. If all the vertices are not selected, then hit 'A' a couple of times till they are bright orange.
  4. Select menu item Mesh->Faces->Shade Smooth.

Now it is as smooth as a babies bottom without adding a single vertex.  Looks a little shiny hear, but that where your material comes in.

smooth_faces.JPG.0c1f3e16a0c3d4a0e5aca9f24bb5f9b5.JPG

If you are doing PBR, currently you need to use the gltf exporter.

Share this post


Link to post
Share on other sites

@JCPalmer a normal map isn't a new concept, nor is it something that does not apply to Babylon.js. We have support for normal maps as can be seen at https://doc.babylonjs.com/how_to/more_materials. There isn't a lot of information on creating them on this doc page, mostly because the information can be easily found elsewhere and all mesh bakers will give you the option for baking them if you can supply a high-poly mesh to project to. The difference between a bump map, which your exporter supports, and a tangent space normal map is the amount of detail that the map contains. Bump maps are black and white images that convey the offset along the face normal for a texel from 0-1. This means that all texels from your texture have a normal parallel with the face normal and light will bounce in the same directions across the face. A normal texture stores a Vector3 per texel (R, G, and B values) so that you can calculate a vector at that texel rather than just an offset giving more realistic and detailed microsurface representation of your model. Due to the extra information you get from a tangent space normal, you won't find a lot of 3D artists opting for a bump map instead of a normal map anymore. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.