[null, {"document_url": "https://blog.michelanders.nl/2014/03/a-new-tree-addon-part-iv-volume_22.html", "unformatted_src": "https://1.bp.blogspot.com/-E6W-J9DAVcU/Uy2tarXY3nI/AAAAAAAABMU/A74Bqz6vJYk/s320/distant_side_by_side.png", "src": "https://1.bp.blogspot.com/-E6W-J9DAVcU/Uy2tarXY3nI/AAAAAAAABMU/A74Bqz6vJYk/s320/distant_side_by_side.png", "formatted_filename": "distant side by side"}, null, {"document_url": "https://blog.michelanders.nl/2014/03/a-new-tree-addon-part-iv-volume_22.html", "unformatted_src": "https://4.bp.blogspot.com/-NeztmJDX-no/Uy2th3rD0HI/AAAAAAAABMc/m8ARSbkz_xc/s320/geometry.png", "src": "https://4.bp.blogspot.com/-NeztmJDX-no/Uy2th3rD0HI/AAAAAAAABMc/m8ARSbkz_xc/s320/geometry.png", "formatted_filename": "geometry"}, null, {"document_url": "https://blog.michelanders.nl/2014/03/a-new-tree-addon-part-iv-volume_22.html", "unformatted_src": "https://4.bp.blogspot.com/-rjIB8CHY3gQ/Uy2tmc4pFmI/AAAAAAAABMk/sTwjivs3tBQ/s320/bits_noodle.png", "src": "https://4.bp.blogspot.com/-rjIB8CHY3gQ/Uy2tmc4pFmI/AAAAAAAABMk/sTwjivs3tBQ/s320/bits_noodle.png", "formatted_filename": "bits noodle"}, null, null, null, null, null, null, null, null, null, null]
A new tree addon, Part IV: volume rendering experiments with OSL

With the new volume shading options offered by Blenders OSL implementation it is tempting to try this on the trees generated by the space tree addon. Without adding any extra geometry or particles apart form a basic ahape a volume shader might give the impression of a much denser crown as shown in the image below: This effect was achieved by inserting a scaled icosphere that covers about 90% of the crown interior (see below) and adding a volume shader to this icosphere that scatters and absorbs light in a non-uniform manner, i.e. the shader mimics a bunch of small scattered disks, which when seen from the distance add to the illusion of leaves. Note that we cannot do without all the leaves because volume scattering adds no specular reflections as real leaves might do. 
Shader code and example node setup

The code for this shader consists of the shader proper, which merely checks which randomly scattered point we are closest to and then calls the indisk function with the position of this closest point and a random direction. indisk checks whether we are inside a disk with its axis in some direction and returns 1 if this is indeed so. Note that the include at the start of the code refers to a file that is distriubted with Blender and contains a number of useful functions, including a number of Voronoi/Worley related ones.
The node setup to use this shader as seen in the opening image of this article looks like this: Whether using a volume shader this way is really useful remains to be seen: rendering this way is still rather slow. Of course, getting a comparable dense crown with extra particles also slows down rendering: in my tests doubling the number of particles from 1000 to 2000 resulted in a render time that was actually slower than adding the volume shader. In other words, your mileage may vary but it might be worth to experiment.


The space tree addon itself is introduced in a few articles on this blog and is available on GitHub. Relevant links are listed below:
 Labels: add-ons, Blender, cycles, open shading language, osl, shader, space colonization algorithm, tree, volume shader, volumetrics

