Render Foam with VisualSPHysics
By default, the foam particles created in VisualSPHysics comprise hexahedrons with their size "hardcoded" based on the fluid particle size. The hexahedrons are duplicated within the overall foam object, one per foam particle, which can result in a large number of meshes within the overall foam object.
However, by re-loading the foam VTK file sequence into Blender as an "Other" type object rather than as a “Foam” type object (options in toolshelf, bottom left), each foam particle is loaded as a single vertex rather than as a hexahedron, resulting in a cloud of vertices representing the foam. It is then possible to use Blender's duplivert or particle system methods to create instances of a single mesh object (such as a cube) at the locations of each of the foam object's vertices. These methods should be computationally efficient and also allow the visual appearance of the foam to be adjusted by scaling the instanced object or changing its shape. The two methods are covered in this article from Blender Stackexchange.
I have run a few foam render comparisons with the Wavemaker file from the examples provided with DualSPHysics, but doubled in width to give more space for foam. The renders were made using Blender 2.79b on Linux, using two GTX 1080ti's for the render. Glass shaders were used for the water and a white emission shader for the foam particles, but not too much time was spent trying for photo realism. There are 891,531 foam particles for the comparisons. This is probably excessive for this particular scene but I wanted to have a large number of particles to show the differences between the methods.
I looked at five scenarios:
The results are:
It can be seen that the duplivert or particle methods for rendering the hexahedrons take a few seconds longer than with the default foam object, but both of these methods use just over half of the memory. This could be of value with a complex scene with a large number of foam particles. The other advantage is that the user could scale the instanced object to suit the scene and choose the shape of the instanced object rather than being limited to a hexahedron. However, a more complex object (such as the spheroid) does result in a memory hit. This is only likely to be used for close-up renders.
To illustrate the results I have attached rendered images of both the hexahedron based and spheroid based foam. At the scale shown there is no noticeable difference in appearance.
But closer up the differences become apparent:
However, by re-loading the foam VTK file sequence into Blender as an "Other" type object rather than as a “Foam” type object (options in toolshelf, bottom left), each foam particle is loaded as a single vertex rather than as a hexahedron, resulting in a cloud of vertices representing the foam. It is then possible to use Blender's duplivert or particle system methods to create instances of a single mesh object (such as a cube) at the locations of each of the foam object's vertices. These methods should be computationally efficient and also allow the visual appearance of the foam to be adjusted by scaling the instanced object or changing its shape. The two methods are covered in this article from Blender Stackexchange.
I have run a few foam render comparisons with the Wavemaker file from the examples provided with DualSPHysics, but doubled in width to give more space for foam. The renders were made using Blender 2.79b on Linux, using two GTX 1080ti's for the render. Glass shaders were used for the water and a white emission shader for the foam particles, but not too much time was spent trying for photo realism. There are 891,531 foam particles for the comparisons. This is probably excessive for this particular scene but I wanted to have a large number of particles to show the differences between the methods.
I looked at five scenarios:
- Foam object as generated by VisualSPHysics within Blender, with default hexehedrons (This is the default method for representing foam).
- Vertices loaded from the saved VTX foam file sequence as "Other" object to give single vertex per foam particle. These vertices set up as dupliverts using a hexehedron as the instanced object (same size as the default hexahedron).
- Vertices loaded from the saved VTX foam file sequence as "Other" object to give single vertex per foam particle. These vertices set up as emitters for particle system using a hexehedron as the instanced object (same size as the default hexahedron).
- Vertices loaded from the saved VTX foam file sequence as "Other" object to give single vertex per foam particle. These vertices set up as dupliverts using a spheroid (cube subdivided once to give 24 faces) as the instanced object (but scaled down compared with the hexahedrons).
- Vertices loaded from the saved VTX foam file sequence as "Other"object to give single vertex per foam particle. These vertices set up as dupliverts using a cube (but scaled down compared with the hexahedrons).
The results are:
It can be seen that the duplivert or particle methods for rendering the hexahedrons take a few seconds longer than with the default foam object, but both of these methods use just over half of the memory. This could be of value with a complex scene with a large number of foam particles. The other advantage is that the user could scale the instanced object to suit the scene and choose the shape of the instanced object rather than being limited to a hexahedron. However, a more complex object (such as the spheroid) does result in a memory hit. This is only likely to be used for close-up renders.
To illustrate the results I have attached rendered images of both the hexahedron based and spheroid based foam. At the scale shown there is no noticeable difference in appearance.
But closer up the differences become apparent: