[null, {"document_url": "https://blog.michelanders.nl/2013/01/a-osl-leaf-shape-shader-for-cycles_26.html", "unformatted_src": "//2.bp.blogspot.com/-o_Dq5XRDG9M/UPKiW5XWOmI/AAAAAAAAAZU/ThZ3SvdF9oQ/s400/leaves001.png", "src": "http://2.bp.blogspot.com/-o_Dq5XRDG9M/UPKiW5XWOmI/AAAAAAAAAZU/ThZ3SvdF9oQ/s400/leaves001.png", "formatted_filename": "leaves", "rendered_width": 225, "rendered_height": 400}, null, {"document_url": "https://blog.michelanders.nl/2013/01/a-osl-leaf-shape-shader-for-cycles_26.html", "unformatted_src": "//4.bp.blogspot.com/-geWNUWcLDF4/UPKqyzkoskI/AAAAAAAAAZw/zqfTwEaYVxQ/s320/spline.png", "src": "http://4.bp.blogspot.com/-geWNUWcLDF4/UPKqyzkoskI/AAAAAAAAAZw/zqfTwEaYVxQ/s320/spline.png", "formatted_filename": "spline", "rendered_width": 320, "rendered_height": 267}, null, {"document_url": "https://blog.michelanders.nl/2013/01/a-osl-leaf-shape-shader-for-cycles_26.html", "unformatted_src": "//1.bp.blogspot.com/-18I18789NDU/UPKrUApoN-I/AAAAAAAAAZ8/D8Vx4hsAvbk/s400/leafshapes.png", "src": "http://1.bp.blogspot.com/-18I18789NDU/UPKrUApoN-I/AAAAAAAAAZ8/D8Vx4hsAvbk/s400/leafshapes.png", "formatted_filename": "leafshapes", "rendered_width": 400, "rendered_height": 98}, null, {"document_url": "https://blog.michelanders.nl/2013/01/a-osl-leaf-shape-shader-for-cycles_26.html", "unformatted_src": "//3.bp.blogspot.com/--XUxcEhbFDg/UPKsWHk2KlI/AAAAAAAAAaM/gpYzn3Mnw5U/s400/leafshapesnoodle.png", "src": "http://3.bp.blogspot.com/--XUxcEhbFDg/UPKsWHk2KlI/AAAAAAAAAaM/gpYzn3Mnw5U/s400/leafshapesnoodle.png", "formatted_filename": "leafshapesnoodle", "rendered_width": 400, "rendered_height": 151}, null, {"document_url": "https://blog.michelanders.nl/2013/01/a-osl-leaf-shape-shader-for-cycles_26.html", "unformatted_src": "//3.bp.blogspot.com/-D9qQmkm02q0/UPKu3LeWXUI/AAAAAAAAAas/bziWeik9p3g/s400/leafnoodle.png", "src": "http://3.bp.blogspot.com/-D9qQmkm02q0/UPKu3LeWXUI/AAAAAAAAAas/bziWeik9p3g/s400/leafnoodle.png", "formatted_filename": "leafnoodle", "rendered_width": 400, "rendered_height": 173}, null, null, null, null, null, null, null, null, null, null]
A OSL leaf shape shader for Cycles

In this first part of a series I present a simple shader that can be used to generate different leaf shapes. In later articles we will add shaders that produce the veins of the leaf.

Simple leaf shape with cubic splines In the example image we have used the IvyGen addon to generate a single limb of some climbing plant species and used the shader from this article to produce the leaf shapes The node setup for this specific material is dicussed later on. (the stone texture is from cgtextures.com and was converted to a normal map and a displacement map with Shadermap CL. The backplate and environment lighting are from the Topanga Forest B collection by Blochi as found on Sibl archive)

The leaf shape shader is essentially creates one side of a leaf from a cubic spline and mirrors that to the other side to create a symmetrical shape. The spline that is used has four controls. It starts on the left in the direction of P1 and ends on the right coming from the direction of P2. The lenght and angles of the vectors going to P1 and P2 are inputs to the shader. Some of the shapes you can create are shown below. Note that it is also possible to define a shape that crosses itself in which case the behavior of the shader is undefined.

The annotated code for the shader is shown below. It includes a small library of functions that will be reused by shaders that will appear on this blog in the near future and this include has its separate page where you can download it and find installation instructions.


The node setup used to create the sample shapes look like this: As you can see there is nothing fancy going on here. The leaves are simple squares with a reset uv-map and a mapping node is used to position the leave onto this square (in this case rotated 90 degrees). The output of the shader is then used to drive a mix shader which shows some green material where there is a leaf and a fully transparent material where there isn't.

Combining things with the Ivy Generator

The sample image at the beginning was create with the IvyGen addon. The leaves it produces are simple square faces that are not connected but nevertheless consist of a single mesh object. Because we want to orient each individual leaf a bit different we need a random number for each leaf. We therefore have to separate each face into its own object.

The workflow to achieve that then becomes:

Each leaf now is its own object we our leaf material attacthed.

Example node setup II The noodle consists of three distinct parts:

The rotation of the uv-map arond the z-axis is performed by an OSL shader because the vector mapping node has no inputs to control the rotation and it would take a lot of vector math nodes to achieve what we want whereas thanks to OSL this rotation is a no-brainer:


In a next article I will show how to add veins to the leaf shapes.
 Labels: add-ons, Blender, Ivy Generator, IvyGen, leaf, leaves, open shading language, osl, pattern, vein, veins
