Ulfheden Posted November 23, 2018 Share Posted November 23, 2018 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! Quote Link to comment Share on other sites More sharing options...
Sebavan Posted November 23, 2018 Share Posted November 23, 2018 It might be related to the space the normals are applied in. Did you try exporting the tanents as well in GLTF for instance ? I bet @PatrickRyan can help on the pipeline he is using to prevent this ? Ulfheden 1 Quote Link to comment Share on other sites More sharing options...
PatrickRyan Posted November 23, 2018 Share Posted November 23, 2018 @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. Sebavan and Ulfheden 2 Quote Link to comment Share on other sites More sharing options...
Ulfheden Posted November 24, 2018 Author Share Posted November 24, 2018 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! PatrickRyan 1 Quote Link to comment Share on other sites More sharing options...
PatrickRyan Posted November 26, 2018 Share Posted November 26, 2018 @Ulfheden would you be able to share the Blender file as well? I can't debug the mesh as easily with a Babylon file as I have to convert back to a DCC format to be able to see what may be going on. Thanks! Quote Link to comment Share on other sites More sharing options...
Ulfheden Posted November 26, 2018 Author Share Posted November 26, 2018 @PatrickRyan, sure thing! https://drive.google.com/open?id=1UkMj-BMo6ab4EaEhWGDVLA5IP2M1HYSB Quote Link to comment Share on other sites More sharing options...
PatrickRyan Posted November 26, 2018 Share Posted November 26, 2018 @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: 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: 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! Sebavan 1 Quote Link to comment Share on other sites More sharing options...
Ulfheden Posted November 27, 2018 Author Share Posted November 27, 2018 @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 Quote Link to comment Share on other sites More sharing options...
PatrickRyan Posted November 27, 2018 Share Posted November 27, 2018 @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. Quote Link to comment Share on other sites More sharing options...
Ulfheden Posted November 27, 2018 Author Share Posted November 27, 2018 @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. PatrickRyan 1 Quote Link to comment Share on other sites More sharing options...
PatrickRyan Posted November 28, 2018 Share Posted November 28, 2018 @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. Ulfheden 1 Quote Link to comment Share on other sites More sharing options...
kcoley Posted December 3, 2018 Share Posted December 3, 2018 @JCPalmer would you be able to take a look at this? I spent some time looking at the Blender exporter, though I am not sure how to generate normal maps from the tool. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted December 3, 2018 Share Posted December 3, 2018 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. Quote Link to comment Share on other sites More sharing options...
kcoley Posted December 4, 2018 Share Posted December 4, 2018 @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? Quote Link to comment Share on other sites More sharing options...
kcoley Posted December 5, 2018 Share Posted December 5, 2018 @JCPalmer btw, do you have plans for supporting tangent space normal maps, or adding support for PBR with Blender 2.8? PatrickRyan 1 Quote Link to comment Share on other sites More sharing options...
Ulfheden Posted December 5, 2018 Author Share Posted December 5, 2018 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. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted December 5, 2018 Share Posted December 5, 2018 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: Right click your mesh. Goto edit mode (tab key). If all the vertices are not selected, then hit 'A' a couple of times till they are bright orange. 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. If you are doing PBR, currently you need to use the gltf exporter. Quote Link to comment Share on other sites More sharing options...
PatrickRyan Posted December 5, 2018 Share Posted December 5, 2018 @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. Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted December 5, 2018 Share Posted December 5, 2018 So, would this be a bump texture or a normal texture? FYI, I am assigning it to a 'bumpTexture' in the JSON file, and it loads fine? I do not see the point of doing something special when the old way has worked for years. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.