Implementing Subsurface Scattering

This week I tried to implement a subsurface scattering effect.

That is all 😛

Here is the material function:


Playing with Buoyancy

So I had this prototype buoyancy system back in the UDK days, it only worked with flat water surfaces since I had no idea how to go about getting the height data from material displacement.

Fast forward a couple of years later, I finally figured out how to make this work with ocean waves in UE4.

Special thanks goes to unreal engine forum members ufna (for his VaOcean plugin which taught me about the texture height map approach) and Handkor for his Gerstner waves tutorial.

In my first attempt with UE4 I re-wrote my buoyancy code from unreal script to blueprints. It worked just fine but later on it was starting to suffer from performance due to Gerstner wave calculations so I eventually ended up re-re-writing it in C++.

Fast forward a few more months, I took interest in DotCam’s WIP Weather & Gerstner-Based Ocean Simulation (totally check out his thread if you haven’t already!) so I decided to use my buoyancy system with it, since the ocean shader I was previously using was very simplistic.

After a few days I ended up with this:

Not bad, so how does it work?

This post is already getting pretty long so I’m not going to bore you with too much details but the basic formula for the buoyancy force is pretty simple:

Volume * Fluid Density * -Gravity / Total Test Points * Depth Multiplier

The volume is calculated by Mass / Density.
Density and Fluid Density are float variables that have to be adjusted per object to get the best results (technically you only need to set the Density value since the water’s density is constant but it’s there just in case I decide to use it with a thicker fluid like lava or whatever).
Depth Multiplier is a normalized float (0-1) which is based on the depth and radius of the test point.

More calculations are also needed to simulate the fluid’s resistance by adding linear/angular damping.

Things to try next:
1)Add pushing forces based on the velocity of the waves, currently the movement is happening almost exclusively on the Z axis, which can be rather useful actually for pick ups on the sea that stay in place or for anchored ships for example but I would also like to have a more realistic behavior when it’s needed.

2)Test it with destructible chunks and breakable skeletal meshes!

3) Figure out how to use it with WaveWorks or implement similar FFT method.

BuoyancyTestPoints ship2BuoyancySettings