LuxCore not uses Blender custom normals
System Information
Kubuntu Linux 16.04 x64
Software Version
- Blender version: 2.79b official
- LuxCore version: 2.0 beta2
Error message from Blender console
none
Short description of error
LuxCore not uses Blender custom normals, while Viewport, Blender Internal and Cycles are using them. In case of other renders, custom normals are used if present, but not with LuxCore.
Exact steps for others to reproduce the error
- Open custom-normals-test.blend, ensure active scene is "Scene LuxCore".
- Hit Render (F12) and see LuxCore rendering Icosphere with normals split in the middle.
- Enable DataTransfer modifier on Icosphere for render and render again - nothing changes. But modifier transfers normals from intact Icosphere and normals should be smooth.
- Switch to Scene Cycles or Scene Blender Internal and do the same test. See Icosphere smooth when DataTransfer modifier is enabled and split when not.
To custom normals to work Blender requires enabling Auto Smooth. But Auto Smooth option isn't supported by LuxCore according to https://github.com/LuxCoreRender/BlendLuxCore/issues/39 So these could be related issues.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
~~Yes, this is a known limitation of LuxCore meshes at the moment (along with other stuff like only one UV map and no autosmooth).~~ Dade can probably comment better on how long it would take to implement custom normals, but I think it is something for after the v2.0 release.
So it is not only LuxBlend not writing custom normals to the output, but also LuxCore itself not ready to accept them, like not reading normals at all? Computing them on-the-fly for example.
Mmm, what do you (or better Blender) mean exactly with "custom" normals ? LuxCore uses the normals received with the mesh. They can be whatever you want.
Do you want to specify multiple normals for the same vertex (like multiple UVs) and used in different triangles sharing the same vertex ?
So it is not only LuxBlend not writing custom normals to the output, but also LuxCore itself not ready to accept them, like not reading normals at all? Computing them on-the-fly for example.
Hm it seems to be a BlendLuxCore only problem.
According to people on stackoverflow we should be able to get the custom normals with to_mesh (which we already use), but it does not seem to work.
Might be useful: https://github.com/Aadjou/blender-scripts/blob/master/utils_split_normals.py
Mmm, what do you (or better Blender) mean exactly with "custom" normals ? LuxCore uses the normals received with the mesh. They can be whatever you want.
You gave me a hope :) If there are arbitrary per vertex normals that LuxCore can use, than the thing I trying to achieve is relatively "cheap" to implement.
Do you want to specify multiple normals for the same vertex (like multiple UVs) and used in different triangles sharing the same vertex ?
By custom normals I mean per vertex normals different from normals calculated automatically. But it is also important what Blender means by them. Blender has them since 2.74. According to this feature is also named custom split normals in Blender and defined for each face corner, i.e. more than 1 per vertex.
So while my test case requires only per-vertex normals so shouldn't be hard to implement, the whole custom split normals thing is the same as in auto-smooth issue #39 and requires changes in LuxCore, if I got it right.
Hm it seems to be a BlendLuxCore only problem. According to people on stackoverflow we should be able to get the custom normals with to_mesh (which we already use), but it does not seem to work.
Probably custom normals are stored and extracted separately because In Blender's Editmode there are options to see per-vertex, per-polygon and these custom split normals. Now I'm trying to get these custom split normals from Blender via its Python API and have found a lot of different normals: vertex normals, polygon normals, loop normals, tessface normals and tessface split normals to name a few.
In case you want to take a look at our code: Here we export the mesh in BlendLuxCore: https://github.com/LuxCoreRender/BlendLuxCore/blob/master/export/blender_object.py#L47 It uses this C++ function in pyluxcore for Blender for fast export: https://github.com/LuxCoreRender/LuxCore/blob/master/src/luxcore/pyluxcoreforblender.cpp#L454
I have reworked the mesh export a bit in commit a63f6a3cd267a0a9be92fa0fb0bccc930e9c0a5d and I think custom normals are somewhat working now (at least the shading changes when I tune values in an Normal Edit modifier).
@starkdd, could you test custom normals, if they are working correctly? You'll have to use the latest BlendLuxCore sources from the repo. If you need help with this, I can explain how to set it up.
Hi @Theverat !
I got luxcore 2.1 beta 2 by updating LuxCore from Blender. Then I downloaded latest BlendLuxCore from GitHub and I think correctly replaced files used by Blender with HitHub version. Commit a63f6a3 is present.
But my test case provided in the first message still not working.
With your hints I experimented with reading custom split normal values in Blender and here what I ended up with:
- need to check
mesh.use_auto_smoothto yield correct result. If use_auto_smooth is on then - call
mesh.calc_normals_split()to make custom split normals ready for reading - access them with like
for loop in mesh.loops: loop.normal - if use_auto_smooth is off then
- use vertex normals like
for vertex in mesh.vertices: vertex.normalHere my test blend file. It has a mesh and a script and prints normals to console. custom-normals-test-print.blend.zip Output reacts to enabling/disabling of the Data Transfer modifier and enabling/disabling of the Auto Smooth flag. Mesh has 10 vertices and 6 triangles, so script reports 10 vertex and 18 face corner normals.
I looked at https://github.com/LuxCoreRender/LuxCore/blob/master/src/luxcore/pyluxcoreforblender.cpp and as I see it uses Vertex normals if face is smooth and calculates flat face corner normals if face is flat. So custom split normals accessible through loop normals are still not used by now.
I know issue isn't first on TODO list, feature is used not very much and it looks rather complex to solve so I'm not complaining :) Method Scene_DefineBlenderMesh even is not receiving enough information at present, if I get it correctly.
Apparently it's not possible to get a direct pointer to the loop normals: https://devtalk.blender.org/t/accessing-raw-loop-array/3048 (Note that the linked topic is only about auto smooth, not custom normals).
We could use foreach_get, it would be a bit slower but would work (we could only use it when custom normals are present). (we would copy the values into a Python or numpy array and pass a reference to this to Scene_DefineBlenderMesh)
If you want to implement this yourself I would be happy to help.
So, as can be concluded from your post, now LuxCore/BlendLuxCore takes pointers on arrays inside Blender mesh object and then uses reinterpret_cast on them to read data. And, as mentioned at the thread https://devtalk.blender.org/t/accessing-raw-loop-array/3048 , this technique not possible for loop normals cause they are not forming one consistent array to work with them that way. And Brecht advises using foreach_get from Blender Python API. And you suggest creating an array and passing its pointer.
If you want to implement this yourself I would be happy to help.
If no one need this feature except of me and you guys are busy (and sure you are :) ), than it looks reasonable to implement it myself eventually. I have no deep knowledge of LuxCore/BlendLuxCore sources, but at least I can try.
The place where the pointers are passed to Scene_DefineBlenderMesh is here:
https://github.com/LuxCoreRender/BlendLuxCore/blob/master/export/blender_object.py#L190
https://github.com/LuxCoreRender/BlendLuxCore/blob/master/export/blender_object.py#L190
Thank you, that should help.
Hey, are there any News on this topic? It is the only thing I miss at the moment from LuxCore so it would be nice to have this feature in the near future :)
No news, unfortunately. With all the other stuff I have to do, I doubt this will make it into v2.3.
Until it is implemented, a possible workaround is the EdgeSplit modifier. May not work for all use cases, of course.
Thanks for the Info! Yes the EdgeSplit modifier is some kind of a workaround but it doesn't give the same result when using for example CAD-Files with custom split normals. Are there plans for implementing it in the next v2.4 release?
Implemented in v2.4.