hair and fur

Use this forum for general user support and related questions.
Forum rules
Please upload a testscene that allows developers to reproduce the problem, and attach some images.
User avatar
B.Y.O.B.
Developer
Developer
Posts: 4146
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: hair and fur

Post by B.Y.O.B. »

lacilaci wrote: Sun Sep 16, 2018 8:39 pm so i guess alpha v4?
Yes.

Everything I mentioned so far is implemented now, I'm currently trying to add one last feature that could be useful.
User avatar
B.Y.O.B.
Developer
Developer
Posts: 4146
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: hair and fur

Post by B.Y.O.B. »

Different root and tip colors, baked into vertex colors (they are multipliers and interpolated over the length of each hair).
Attachments
2018-09-17_12-45-42.png
with vertex color layer
with vertex color layer
User avatar
B.Y.O.B.
Developer
Developer
Posts: 4146
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: hair and fur

Post by B.Y.O.B. »

I'm finally done.

A test with 10000 hairs * 10 children * (2^5 + 1) points = 3,200,000 points:

Old:

Code: Select all

[Plane: ParticleSystem] Exporting hair
[LuxCore][26.161] Refining 100000 strands
[LuxCore][26.884] Strands mesh: 2133333 triangles
[LuxCore][27.365] Refining time: 1.2 secs
[SDL][27.369] Texture definition: 140050749790216
[SDL][27.369] Reading texture map: /tmp/tmpwc8palj5.jpg
[SDL][27.456] Material definition: Surface_Material__002_140050781808648
[SDL][27.458] Scene objects count: 1
[Plane: ParticleSystem] Hair export finished (20.579 s)
New:

Code: Select all

[Plane: ParticleSystem] Exporting hair
Changing resolution to RENDER took 1.523 s
Collecting Blender hair information took 5.661 s
[LuxCore][9.987] Removed 1 invalid points
Preparing strands took 0.097 s
[LuxCore][10.004] Refining 100000 strands
[LuxCore][10.636] Strands mesh: 6399996 triangles
[LuxCore][10.986] Refining time: 0.981 secs
[SDL][10.987] Texture definition: 139725391321096
[SDL][10.987] Reading texture map: /tmp/tmpumpaoxqy.jpg
[SDL][11.084] Material definition: Surface_Material__002_139725440133128
[SDL][11.085] Scene objects count: 1
[Plane: ParticleSystem] New Hair export finished (8.361 s)
The memory spike during the hair export is gone completely, and the export is faster.
There are new features, like the ability to only define UV coordinates for the hair without defining vertex colors. This is the new default behaviour since it saves memory and most people don't use vertex colors (it is not intuitive).
The user interface should now be easier to understand, the descriptions were improved and extended.

Also, the hair is no longer defined as an instanced mesh.
This means that rendering is faster.
However, the accelerator will use more memory if the mesh is not instanced. In the test above, the whole Blender process used 1.1 GiB with hair as instance and 1.7 GiB with non-instanced hair.
So the extra speed (930k Samples/sec vs. 770k Samples/sec) comes with a cost in memory.

I think I will add an option to enable instancing for hair, to save memory.
User avatar
lacilaci
Donor
Donor
Posts: 1969
Joined: Fri May 04, 2018 5:16 am

Re: hair and fur

Post by lacilaci »

That is some great improvement!
User avatar
B.Y.O.B.
Developer
Developer
Posts: 4146
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: hair and fur

Post by B.Y.O.B. »

B.Y.O.B. wrote: Mon Sep 17, 2018 2:46 pm Also, the hair is no longer defined as an instanced mesh.
This means that rendering is faster.
However, the accelerator will use more memory if the mesh is not instanced. In the test above, the whole Blender process used 1.1 GiB with hair as instance and 1.7 GiB with non-instanced hair.
So the extra speed (930k Samples/sec vs. 770k Samples/sec) comes with a cost in memory.

I think I will add an option to enable instancing for hair, to save memory.
Note: this only concerns Embree (CPU rendering) from what I could see in my tests, so the option will only be available if CPU rendering is selected.
acasta69
Developer
Developer
Posts: 472
Joined: Tue Jan 09, 2018 3:45 pm
Location: Italy

Re: hair and fur

Post by acasta69 »

Now I have a Windows build with the new hair support. I tried to render the scene linked before by lacilaci, but hair is not rendered and I get this message:

Code: Select all

[Exporter] create_session
[SDL][11.216] Camera type: perspective
[SDL][11.216] Camera position: Point[1.44414, -0.914483, 0.491676]
[SDL][11.216] Camera target: Point[1.43705, -0.90897, 0.487281]
[SDL][11.216] Camera clipping plane disabled
Unpacking image "productimage-picture-30716-diamond-grid-368.jpg" to temp file "
C:\Users\xxx\AppData\Local\Temp\tmpu8_ji3io.jpg"
[Plane: ParticleSystem] Exporting hair
Changing resolution to RENDER took 0.011 s
WARNING: [Plane: ParticleSystem] 'NoneType' object has no attribute 'source'
Traceback (most recent call last):
  File "C:\Users\xxx\AppData\Roaming\Blender Foundation\Blender\2.79\scripts\addons\BlendLuxCore\export\hair.py", line 176, in convert_hair
    image_filename = ImageExporter.export(settings.image, settings.image_user, scene)
  File "C:\Users\xxx\AppData\Roaming\Blender Foundation\Blender\2.79\scripts\addons\BlendLuxCore\export\image.py", line 43, in export
    if image.source == "GENERATED":
AttributeError: 'NoneType' object has no attribute 'source'
[SDL][11.357] Texture definition: 246930504
[SDL][11.357] Reading texture map: C:\Users\xxx\AppData\Local\Temp\tmpu8_ji3io.jpg
[SDL][11.497] Material definition: Surface_Material__002_247016120
[SDL][11.497] Scene objects count: 1
Any idea what this means? Some problem with data packed in blend file, or what else?
Support LuxCoreRender project with salts and bounties

Windows 10 64 bits, i7-4770 3.4 GHz, RAM 16 GB, GTX 970 4GB v445.87
User avatar
B.Y.O.B.
Developer
Developer
Posts: 4146
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: hair and fur

Post by B.Y.O.B. »

It was an oversight from me (i.e. a bug), I fixed it. Thanks for the report :)
Silverlan
Posts: 7
Joined: Tue Feb 09, 2021 7:54 am

Re: hair and fur

Post by Silverlan »

B.Y.O.B. wrote: Mon Sep 17, 2018 2:46 pm I think I will add an option to enable instancing for hair, to save memory.
Sorry for the bump, but I was wondering, was this ever added as an option? I'm using the C++-API and I'm trying to render an animal with ~3m hair, but it requires too much memory to be viable (I'm using TESSEL_RIBBON_ADAPTIVE). I wouldn't mind slower rendering if it meant saving memory, but I couldn't find an option for instancing anywhere.
User avatar
B.Y.O.B.
Developer
Developer
Posts: 4146
Joined: Mon Dec 04, 2017 10:08 pm
Location: Germany
Contact:

Re: hair and fur

Post by B.Y.O.B. »

Yes, it's implemented here: https://github.com/LuxCoreRender/BlendL ... ir.py#L229

If use_instancing is True here, instancing is enabled for the mesh by setting an identity matrix for the "transformation" property. If this property is not defined, the mesh is not instanced.
Silverlan
Posts: 7
Joined: Tue Feb 09, 2021 7:54 am

Re: hair and fur

Post by Silverlan »

B.Y.O.B. wrote: Sun Mar 14, 2021 8:56 pm Yes, it's implemented here: https://github.com/LuxCoreRender/BlendL ... ir.py#L229

If use_instancing is True here, instancing is enabled for the mesh by setting an identity matrix for the "transformation" property. If this property is not defined, the mesh is not instanced.
Thank you! Turns out I've already used instancing without realizing.
I'm assuming instancing only works if the hair are all defined the same?

In my test scene I have a cube with 3 million hair, each defined by 3 points (2 segments) on a straight line:
Image

The memory usage for this scene is reasonable (approximately 2 GiB), and if I export the scene, the resulting hair mesh file has a size of approximately 451 MiB:
Image

So far so good, however if I change it so the points of each hair are no longer on a straight line, but an individual curve (still 3 points), the memory usage skyrockets and eats up more than my available 16 GiB of memory (I'm assuming it's because it's no longer instancing the hair). When exporting the scene, the resulting hair mesh file is also quite a bit larger at ~4 GiB:
Image

I know that 3 million hair is a lot, but that still seems a little excessive to me, even without instancing.
The parameters I'm using for "DefineStrands" are as follows:
- tesselType: TESSEL_RIBBON_ADAPTIVE
- adaptiveMaxDepth: 12
- adaptiveError: 0.0075
- solidSideCount: 12
- solidCapBottom: false
- solidCapTop: false
- useCameraPosition: true

Here's the console output of luxcoreui up to the point where the memory usage starts to skyrocket: https://pastebin.com/9HdpwDfQ

Is there some way to reduce the memory footprint without reducing the number of hair / defining all hair the same?
I haven't uploaded the scene due to the large file size, but I can do so if needed.
Post Reply