My 18th Century sailing ship simulator Square Rigger will be initially developed within an imaginary proof of concept pacific atol. The atol will act as a confined sandbox to allow me to implement all of the features required for the simulator. Once this is done I can expand the area out into a real world map.

For now however, the challenge of this current sprint is to model some proof of concept sails. These will be implemented as Godot Soft Bodies and I will try to model the action of the wind upon them.

Godot’s soft bodies are only affected by collisions with other bodies and by the effect of gravity. You cannot apply a force to them as far as I can see. My proof of concept Godot soft body sails fall really nicely, but they are not affected by the wind which I apply programmatically as a constant force vector.

In Blender you have the option of a force field which can be used to implement wind, but this option does not exist in Godot to my knowledge.

I want to be able to model the billowing of the sails in the wind. My current way of showing the billowing of the sails is to create a lentil shaped body wind object and move that body against the sail. The sail wraps around the lentil shape emulating the wind filling it. Once I have proven that this approach will work realistically then I can make the lentil shape invisible and and get it to ignore any collisions with anything other than the sail itself.

I’ve been at this approach for a while now and it has been frustrating trying to get to grips with Godot’s rigid bodies and gravity responsiveness settings. I’d been trying to offset my wind lentil shapes such that they affect the soft body sails in a realistic way as the wind increases and decreases and the shape advances into the sail and retreats from it.

Trying to get the rigid body wind lentil / lens shape to interact with the soft body sail in any sensible way was proving difficult.

Originally I’d placed the lentil shape as a node in the root of the scene tree. I decided to revert back to the wind lentil being a child node of the hull again as having the wind lentil shape as an independent object in the whole scene tree was just not working.

This approach appears to have work, but the lentil shape behaves as if it were still the shape and size of the original spherical collision mesh it was created from. The shape appears to ignore its current lens shaped geometry.

Graphic of a ripple equation

After some lengthy experimentation using the collision sphere / wind lentil approach did not work in an acceptable way. A scene with small spheres which are advanced horizontally so that they form a dome pressing on the sail gives a good effect, but the sail collisions are violent and are periodic. This is not good enough and will be a lot of work to tune. I need to find a different approach.

I have avoided shaders for many years, but this might be the way to go. This ripple equation from https://www.benjoffe.com/code/tools/functions3d/examples yields a nice dome effect when applied as a shader.

I applied the ripple equation in a shader on the cube mesh that I have added to the soft body for the sail. I used a cube mesh to avoid a lot of clipping / bleed through that was occurring with a plane mesh. It gives a nice effect.

Soft body modifed by dome shader

If I want make this curve and billowing effect parametric, I have to pass the wind strength into the shader to alter the amount of billow in the sail. In order to do this I need to use set_shader_param. For this to work I need to access the underlying mesh of the soft body. It appears I cannot do this using material override. From a bit of googling lots of people have tried to do the same. There is however a hint in the 2018 Godot soft body documentation for the example of the bouncing ball that I can do this by using a custom mesh.

I tried an accurate (ish) subdivided sail mesh generated in Blender and loaded in to the sail scene as a custom mesh on the SoftBody in order to control the amount of billow in the sail.

A main topsail modelled in Blender

Well that didn’t work out. I’m now abandoning using SoftBody and going with an explicit MeshInstance modifed by a shader instead now.

Sigh…., but on the upside, another bit of Godot knowledge gained.


Today’s featured image is https://pixabay.com/images/id-642520/