Render splines using Cycles hair primitives
I found no render engine that renders mesh-less splines as hair primitives with custom radii and data. So I edited Cycles and Blender, initially 2.79 and now 2.8 to do this.
This modification allows you to skip meshing splines entirely and render them as hair. Needless to say, with this method you can render lots of them (hello large-scale).
This is particularly useful in the visualisation of graph structures such as trees, random walks, cells, etc.
This is a Cycles modification that allows you to skip meshing splines entirely and render them as hair. Needless to say, with this method you can render lots of them (hello large-scale).
- Splines to hair: render all splines within a curve object as hair in one click in the UI, also easily scriptable.
- Radius variation: splines are rendered with their radii so this is more than simple tapering hair.
- Spline interpolation: all curve types are supported. Two interpolations may occur and affect hair, see Usage below.
- Per-spline material: supported. You need to add the materials to the curve object and then set the material_index of each spline.
- Two custom values on spline points:
value, two floats. This takes 8 bytes extra per spline point in memory but gives you the ability to modulate your shaders based on these values as they're available in
- Extra spline metrics available in HairInfo node:
- Increased transparency limit to enormous numbers to let the user play with transparency + many splines
Warning When you save .blend files with this version, do not save them with another version of Blender or custom values will be lost! You've been warned.
How to use it?
You need to compile Blender with these sources. You need to have git installed on your system or skip step 1 and download sources from github. Make sure you have python3.7+ installed as this is required by Blender 2.8.
In your console run the following commands (valid for Linux/MacOS/Windows):
git clone git://github.com/nantille/blender_28_mod
After that, you need to fetch submodules like addons, translation, etc.:
git remote set-url origin git://git.blender.org/blender.git
git submodule sync
git submodule update --init --recursive
git submodule foreach git checkout master
git submodule foreach git pull --rebase origin master
git remote set-url origin https://github.com/nantille/blender_28_mod.git
If you would like to compile Blender with the latest sources published by Blender Institute,
you can try rebasing with the following command but there might be conflicts:
git pull --rebase http://git.blender.org/blender.git master
If everything compiles fine (fingers crossed!), you will have a new Blender executable in relative path
The path to the blender executable is given at the end of the compilation.
If you have a Cmake Error mentioning
Python executable missing and you have Python installed, you probably have the wrong version. Blender 2.8 requires Python 3.7+.
This is a modification for Blender 2.8+.
- Open this custom version of Blender 2.8 and make sure Cycles is your render engine.
- Select or add a curve object on the scene.
Object Datapanel at the bottom, enable
Render as Hair.
- Make sure that in panel
Geometry, the option
Use Hairis enabled.
- Tweak options under
Use Hair, set
- Tweak the
Subdivisionparameter and also the
Resolution Preview Uand/or
Render Uparameters of your curve/splines
bpy.context.scene.cycles_curves.primitive = 'CURVE_SEGMENTS'
bpy.context.scene.cycles_curves.subdivisions = 3
Hair != beveled curves
Please note that when a spline is rendered as a hair primitive, it has no mesh and so all bevel/taper and meshing related features of splines/curves will be ignored. So with this method:
- no mesh-related feature like fill, twisting, taper, bevel, ...
- no uv mapping, though you can get U coordinate with HairInfo.Intercept multiplied with the new HairInfo.SplineLength.
- no cyclic property (you can manually move the last point of your curve to match the first one or...do a PR on this code)
- Copy-paste or import the code of
- At the bottom of the script, tweak how many splines you want to have generated.
- Run the script. If you generate a large number of splines, like 1 million, it will easily take 15 minutes.
- Add a material and play with HairInfo.Intercept, HairInfo.Key and HairInfo.Value
One issue: if you go in Preview mode and assign a material to a curve that had none, Blender crashes. Solution: you have to assign the material before Preview mode. Don't hesitate to report any issue you see.