Saving, Loading And Partitioning In Krakatoa For CINEMA 4D
Last edited on April 14, 2014 - WORK IN PROGRESS
A fundamental workflow of Krakatoa in all its implementations is the saving of particle data to disk. In the following tutorial, we will go through the basic steps of caching a CINEMA 4D Emitter object to disk using the Thinkbox PRT file format.
Creating The Emitter
- Use the Main Menu bar > Simulate > Particles > Emitter to create a new Emitter.
- Enter 90 degrees in the Rotation > P value to rotate the system to emit up.
- Enter 10,000 in both Birthrate Editor and Birthrate Renderer fields. Note that this is the number of particles per second and that this is the maximum value allowed by CINEMA 4D.
- Click the Emitter tab and change the X-Size and Y-Size to 20cm, and both the Angle-Horizontal and Angle-Vertical values to 10 degrees.
- Use the Main Menu bar > Simulate > Particles > Turbulence to create a new Turbulence object.
- Change the Strength value to 10cm and the Scale value of the Turbulence effect to 35%.
RESULT: Playing back the animation will produce a column of particles with some turbulence added over time.
Rendering The Emitter
- Select the Emitter.
- Use the Main Menu bar > Plugins > Krakatoa > Krakatoa Emitter Source to create a new intermediate object.
RESULT: The Emitter will be connected automatically to the Emitter Object input. All channels but the special BirthPosition channel will be checked by default and would be accessible to Krakatoa.
- Click the light icon and hold down the left mouse button, then select the TargetLight icon and release the mouse button to create a new targeted Spot light.
- Change thge Type from Spot to Parallel Spot.
- Click the Details tab and enter 500cm for Outer Radius, then 400cm for Inner Radius.
- Click the Edit Render Settings icon and switch the Renderer to Krakatoa.
- Render to the Picture Viewer.
RESULT: The particles will be rendered, but there will be not enough particles to produce good volumetric shading or light attenuation.
Baking The Particles To A PRT Sequence
If you step back in time, the simulation of the particles will be completelt lost and replaced with a simple interpolated distribution without any Turbulence effect. Since rendering particles with Motion Blur requires Krakatoa to step backwards in time to acquire scene data like the camera position, rendering an Emitter with Motion Blur enabled will also result in incorrect results:
The solution is to save the Emitter to a PRT sequence containing the major particle data channels including Position and Velocity. This will allows us to render the same particles with Motion Blur and scrub the time line freely in both directions without losing simulation results.
- In the Render Settings dialog, click the Output tab of the Krakatoa renderer.
- Switch the Render To option to Save Particles to File Sequence.
- Expand the Export Channels panel to make sure the necessary channels are checked - by default, Position, Velocity and Color will be checked.
- We can uncheck the Color channel since we don't expect a per-particle color to come from the basic Emitter.
- We can check the ID channel though, as it would allow us to decimate the loaded particles in a consistent way between frames later on.
- We can also check the Age checkbox to save a channel describing how old each particle is.
- Now click the Output entry in the Renderer options tree and switch the Frame Range to All Frames.
- Select the Save entry in the Renderer options tree and pick a path to save to. Krakatoa uses the CINEMA 4D output path for both images and PRT files. You can also use the project folder to store data if the scene is already saved. Saving particle file sequences is roughly equivalent to rendering to image file sequences, except that the output is a 3D data file instead of a 2D image.
- Press SHIFT+R or click the Render the active project to the Picture Viewer icon.
RESULT: Instead of rendering the particles, PRT files will be saved to the specified output folder. Note that empty image files will be created, but they will contain no particles.
Loading The Saved Particles
At this point, we have our particles cached to disk and all we need to do is load them back in CINEMA 4D in place of the live Emitter particles.
- Disable both the Emitter object and the Krakatoa Emitter Source object.
- Use the Main Menu bar > Plugins > Krakatoa > Krakatoa PRT Loader to create a new PRT Loader object.
- Pick the file sequence generated in the previous step.
- Click the Display tab and switch the display mode from Small Points to Velocities to draw lines.
- Scrub the time line - all particles should play back forward and backwards without problems.
- In the Render Settings dialog, switch the Krakatoa > Render To option from Save Particles to File Sequence to Viewer.
- Render the particles - the result should be identical to the "live" rendering of the Emitter.
- Switch to the Options tab and expand the Motion Blur panel.
- Check the Enable Motion Blur option.
- Slide the Particle Segments value to 16 - this will render 16 motion blur passes.
- Slide the Shutter Angle to 360 degrees to produce a full frame motion blur.
- Re-render the particles to the Picture Viewer.
RESULT: The particles will now be blurred correctly according to the saved Velocity channel.
Note that you cannot render with Motion Blur in the viewport as it is not supported by CINEMA 4D. You must use the Picture Viewer to preview Motion Blur effects!
Repopulating The Particles To Increase The Count
A simple way to create more particles from the low-count Emitter would be by adding a Repopulate tag to the PRT Loader.
- Select the PRT Loader object.
- Right-click and select Krakatoa Tags > Repopulate (orange icon).
- Leave all settings at their defaults and render frame 90.
RESULT: New particles 266K particles will be seeded around the original approximately 30K particles, but the result will be rather grainy.
- Change the Subdivision value from 0 to 1. This will create approximately 8 times more particles (because each voxel will be subdivided once along each axis, for 2x2x2 = 8 sub-voxels).
- Also slide the Density Falloff Start value from 0 to 1 - this will produce a linear Density falloff from the position of the particle to the Fill Radius distance of 10cm, producing a less thick cloud.
- Render frame 90 again and compare
RESULT: About 2.1 million particles will be seeded around the original particles.
Partitioning The Particles To Increase The Count
Another approach to increasing the particle count is the so-called Partitioning - saving of the same simulation multiple times using slightly different initial conditiions in order to produce a combined point cloud that is equivalent to simulating more particles at once.
Since the Emitter can only generate up to 10,000 particles per second, the only way to create 100,000 or 1,000,000 particles without using render-time Repopulation would be to save the same simulation 10 or even 100 times.
- Save the scene to give it a name.
- Disable the PRT Loader and re-enable the Emitter and Krakatoa Emitter Source objects.
- Switch to the Output tab.
- Switch to Save Particles to File Sequence mode.
- Expand the Partitioning panel and check the option Save Multiple Partitions
- Leave the settings at their defaults - 10 partitions, Increment Emission Random Seed on.
- Under the Save Particles panel. with the option Batch Render Job selected, click on the Submit Saving Job Or Partitioning Job button.
RESULT: The scene will be saved 10 times with incremented Emitter random seed and these scenes will be sent to the Render Queue for processing:
Loading The Partitions
- Select the existing PRT Loader
- Pick any file from the newly partitioned sequences to replace the previous single sequence.
- Check the option Load Additional Partitions.
- Change the Partitions to Load to 10 (out of 10 Partitions Found)
- Switch the Render Settings > Output tab dialog back to Viewer and re-render:
RESULT: Since we added 10 times more particles, the rendering image appears significantly more dense and the shadow is also a lot darker.
- In the Options tab of the Render Settings dialog, change the Final Pass Density Exponent from -1 to -2 to compensate for the 10 times higher particle count.
- Then re-render the image
RESULT: The shadow is back to approximately the same result as in the previous renders:
Combining Partitioning And Repopulation
Enabling the Repopulation tag will produce a lot more particles from a denser cloud, resulting in a significantly better distribution: