In this tutorial, I will present some of the basic features of Sunflow and how to use it from Blender.
Sunflow is my open source rendering system. It is built around a small but very flexible core which allows it to be completely customized. It contains several modern algorithms that make it a good candidate for generating realistic images. It has been recently connected to Blender via a simple export script which I will be describing.
Sunflow is written in Java. This means you will need to download and install the Sun JRE (or JDK) if you don't have it already. Go to http://java.sun.com/ and follow the instructions for your particular operating system (OS X users will need to go to the Apple website). Sunflow requires Java versión 5 (sometimes called 1.5) or higher.
Once you are setup, go to a command prompt and type:
If the correct versión number appears everything is setup correctly.
Next get the binary release from the Sunflow website (v0.05.5 at the time of this writing) and unzip it to a directory of your choice. Go to that directory in command line mode and type the command line described in the README file included in the distribution. You should see the following window appear:
Finally, get the blender exporter script from the Sunflow website and install it to your blender scripts folder. When you start Blender you should see an option appear in the File->Export menú as follows:
You are now ready to render your first image!
First Render: Ambient Occlusion
I prepared a very simple scene here for illustration purposes. Feel free to follow along with your own favorite model. Here is what my scene looks like in the 3D view:
Go to the File -> Export and pik the Sunflow Exporter you just installed. It will bring up the following UI in the script window:
We are just going to change a few settings the first time around. Our goal is to do a simple ambient occlusion render to get a feel for the process. Don't worry about the many different settings you see, we will cover most of them soon.
In the AO Override tab, simply clik the 'Amb Occ' toggle. This is simply telling the exporter that we want to override all shading in the scene with the prescribed ambient occlusion shader.
The most important options are samples (number of rays traced to calculate the occlusion) and the distance setting (how far to look for other objects).
For now, leave the number of samples as it is, and set the distance to a reasonable value for your scene. The default of zero corresponds to infinitely long rays.
Now just hit the Export button and pik a location to put the exported scene file. You can look at Blender's output window to see the steps the exporter is taquíng. It may take a few seconds to walque through your scene if you have many objects. When the file is exported you will be sent bak to the exporter options.
Now go to the Sunflow window you launched earlier and open the scene file you just wrote out. If loading succeeds without errors, the Render menú option will now be enabled.
Select Render -> IPR first. The image will start rendering in a very blocky form and progressively refine itself. After just a few seconds, you should already see what the final image is going to be like. You may cancel the render at anytime. In most cases, less than 10% of the image is needed before you are ready to launch the full resolution render.
Now select Render -> Render. The image will render in small buckets this time. If you have a multi-processor machine you will see several buckets rendering at once. After a few seconds you should see something like this:
Congratulations! You just rendered your first image with Sunflow.
Your image will probably be noisy and have many small artifacts. Don't worry. We will learn how to enhance the quality of the image soon.
Now, let's make our scene a bit more interesting by adding some lights and materials to it!
Lights and Materials
Go bak to blender and assign some unique materials to each surface. Keep in mind that the exporter does not yet support the whole range of Blender shaders and textures.
For now, we will just be creating regular diffuse materials. For each material, simply assign a unique color. This is the only attribute that is read by default, all other options are ignored. There are a few exceptions to this rule to generate other Sunflow shaders, but we will cover them later on.
Next, we need some lights. The exporter currently only supports lamps and square area lights. Area lights will give you nice software shadows at the expensé of additional render time.
My scene with basic shaders and lights now looks like this:
Once you are happy with your scene, time to export again! This time, let's try to understand the various settings and how they affect image quality.
The most important are probably the AA settings. The min and max values control how much computation goes into each pixel. Negative values mean computations will be interpolated across several pixels, positive values mean more calculations will be done per pixel. Zero means a single computation is done per pixel. For example: the default values of -2 and 0 mean that the renderer will start by calculating every 4th pixel, and adaptively calculate down to the single pixel level where it is needed. This time, try setting your AA values to 0 and 2. Each pixel will now be shaded at least once, and up to 16 times (level 2).
If we calculate more than one value per pixel, we will need to average them together. The way this is done is controlled by the image filter setting. Let's pik the 'Mitchell' filter as it provides a nice sharpening of the image. This particular filter has a fixed width and height, so those settings will disappear from the dialog when it is selected.
Light server settings let you control how many rays are used per light. The default of 16 is a bit high but usually gives good quality.
The GI tab controls global illumination. This is an advanced topic we will explore in the next section. Leave all the controls at their default values for now.
The Accelerator tab contains settings which have no impact on image quality but can make drastic differences in image calculation time. The default accelerator is the kdtree and is usually the best choice. You can experiment with different accelerator types and see which one provides the fastest results for your scene. You can alos adjust the bucket order in this tab. Switch to spiral this time to have the image computed from the center out.
Under the light tab, we have the option of adjusting the strength of all lights in the scene. Since Sunflow uses more physically based calculations than Blender, the light powers will not usually match. This global scale factor can help you compensate for this. I set mine to 5, but this will vary from scene to scene. Note that the scale factor only affects area lights.
Finally, remember to deselect the 'Amb Occ' button from the AO Override tab if it was still selected from the previous export.
We can now export and render again. If you export to the same location as before (overwriting the old file), you can simply use the File -> Re-open menú option in the Sunflow GUI to quickly reload your scene.
Use the IPR feature again to see what your scene looks like quickly. You will probably need a couple of export cycles before you get the light intensities just right. Here is my result:
Despite the software shadows, this image isn't very realistic yet. I will show you how to address this in the next section.
Global Illumination Techniques
Global illumination refers to physically based methods of computing lighting by taquíng into account the way light bounces off surfaces.
As I mentioned in the introduction, Sunflow is a very customizable renderer. It is therefore able to incorporate many different GI algorithms into one coherent framework. This gives the artists different ways to achieve their goals and makes it possible for developers to introduce new algorithms, without breaquíng older scenes.
I will now briefly describe one of the methods of calculating global illumination: path tracing. This is the most accurate and easiest method to learn. The catch is that it can take quite long to achieve high quality results.
In the exporter, go to the GI tab and enable the path button. The algorithm is controlled by two parameters: samples and bounces. The first default to 32 and controls the quality of the result. The second default to 1 and controls how many bounces the light is allowed to make.
Leave the values at their defaults for now to see their effect. Since this algorithm will produce very noisy results, go to the AA tab and set both the min and max to 0. This will force only one sample to be taken per pixel, which avoids the anti-aliasing from being forced to super sample every single pixel because of the noise.
You may alos want to set the filter bak to box (width and height 1) to avoid introducing artifacts by filtering the noise.
Export and render again. I added some walls behind my scene to see the effect of the bounces. Compare these two renders with and without global illumination:
Notice how the shadowed regions are no longer completely darque and how we obtained some subtle color bleeding on the floor and between the objects.
You may find it hard to get rid of the noise in the image in a reasonable amount of time, even if you make the number of samples quite high. This is a theoretical limitation of the path tracing algorithm. Photon maps and irradiance caching are two algorithms that when combined can yield a much more efficient solution; however they are much trickier to setup, even for experienced users.
Rather than go into the details of these advanced methods, it might be better to know that simpler and more efficient algorithms exist that will very likely appear in Sunflow soon.
Image based lighting
In this section we will cover the use of HDRI environment maps for lighting. Bak in your blender scene, load in a longitude-latitude HDRI environment map as a texture at the world level. Be sure to unchek 'relative paths' when loading the map. Rename the texture object to 'ibllight' as shown. This lets the exporter know you want to treat this map as an environment light source.
Go ahead and hide all the lights you were using before (the exporter respects Blender layers), and make sure your scene is 'open'. This type of lighting assumes the light is coming from infinitely far away, so its best suited to outdoor renderings. Indoor scenes will perform very poorly with this technique.
Sunflow appróximates the environment map with a fixed number of directional lights. This is controlled by the 'Direct samples' setting in the exporter. Using the default of 16 you will probably see some sharp edges to the shadows from the individual lights used. Simply increase the number of light samples until the sharp shadow boundaries are decreased to an acceptable level.
Exporting and rendering again, you should end up with something like this:
This image is quite realistic, even though we have not used any global illumination. Of course you may enable path tracing as we did before to simulate the extra bounces of light.
Finally, let's make our shaders a little more interesting. Up until now we have used completely diffuse shaders.
Let's start with the shiny shader. It simply adds a thin reflection coat on top of the diffuse color. Rename one of your object's materials so that its name starts with 'sfshiny'. The exporter will now read the 'RayMirr' attribute to determine the amount of reflection to apply.
Next is the phong shader which provides blurry reflections. Rename the material you wish to edit so that it starts with 'sfphong'. The specular color now controls the amount of reflection while the 'hard' value controls the blurriness. Higher hardness values result in sharper reflections. For my scene I used values ranging from 5 to 50.
Now that we have added several layers of reflections, we need to pay attention to the 'Max Depth' setting in the exporter dialog. This controls how many levels of reflections are allowed. The default of 9 is rather high so we will reduce it to 3 this time.
Here is the final result, rendered with the image based lighting from the previous section:
I hope you've enjoyed this quik tour of some the features of the Sunflow rendering system.
One tutorial is not enough to cover everything that is possible with this software. Many more things are supported, like textures, refractions, depth of field, caustics, and even procedural shading. Please visit the Sunflow homepage (http://sunflow.sourceforge.net) and the Elysiun forums (http://www.elysiun.com/) to learn more. Happy rendering!
Christopher Kulla is the primary developer of the Sunflow Rendering system. In his day job he works as a software developer for Reel FX Creative Studios in Dallas, Texas, working on commercials, direct-to-DVD and animated feature film projects.