Distance Field Flow Map

That is awesome! Love it :).

Mine is available for free at the top of this page. I will update it in the future, so make sure you check this page out frequently.

By combining both techniques you will get the best of both worlds. Meaning the flow maps bend the flow direction and the normal determines the ‘exit wake’. It should naturally slow down the water at the back side of the rocks.

Also if you look at the kite demo river material, you will see it does something similar using the heightmap and normals of the river bank texture so that on a very small scale the water appears to bend around the little pebbles at the shore line. By combining all three layers (DF generated normals with local tiny scene normals and flowmaps) it should be possible to get something really nice. In the scene where the boy falls in the water there is a little hand-crafted flowmap that was made by manually blurring a screen capture of the rock shapes and making a photoshop normal. But you can probably use it for flowmap control ideas.

just to be clear.
if we have different river bottom, it also can affect flow, by this “distance to nearest surface” function?

Unfortunately right now landscape will not generate a distance field. Also any sort of spline mesh will not be able to generate a proper distance field.

It should be possible though to provide either separate geometry for the bottom (without splines), or use a height function or height map for the bottom part. You would need to compute it separately and combine it with the distance function result using Min or Multiply. You could also try to use that result to blend in a flowmap which could be as simple as a blurry normalmap generated from your height data. Sometime next week I may try to play with combining all this stuff.

This is going to be slightly off-topic, but is distance field support planned for splineMeshes at some point in the future? I’ve got a pretty comprehensive spline mesh system for the marketplace on the backburner, so I have a vested interest in that :wink:

Thanks for the feedback Ryan! I will see if I can make some time to make it all look a little better. I already got the flow slightly better behind the rocks but not it gets extremely deformed in tight spots. Will update as soon as I’m happy with a new result.

Could someone explain why using distance to the nearest surface takes up 4 texture samples? Is this always the case with volume textures?

Daniel will have to answer definitively. My guess is that is is either that or the “mips” of the global volume texture.

Are you seeing that from just a single instance of the node, not your multi-sample version?

Just using one of them adds 4 extra samplers, after you can use DistanceFieldGradient and DistanceToNearestSurface as much as you like.

There’s one sampler needed for each clipmap. I can make it 1 in D3D11 but that will probably not make it for 4.9. DistanceToNearestSurface is just a single texture lookup though. (texture lookups affect performance, while texture samplers are the resource you can only have 16 of)

Is there any plan to have control over the global distance resolution? (like a cvar or something) Also individual control over the padding/bandwidth in the static mesh editorfor the indiviual fields would be useful so that can control how far away from the surface that the distance field extents to. Would be nice to have controls similar to the cascaded shadow map to like a res bias.

Does the global field just do a min of all of the fields or does it go through a re-distancing pass to make sure that the values are correct?

r.AOInnerGlobalDFClipmapDistance 2500
r.AOGlobalDFClipmapDistanceExponent 2
r.AOGlobalDFResolution 128

Technically min is the correct union operation so I’m not sure what a ‘re distancing pass’ would be.

But the lower resolution of the global field means the high resolution surfaces are no longer accurately represented so you get rounded corners where they would have been sharp and surfaces smaller than the resolution may disappear entirely etc.

Cheers thats great

The reasons I asked about the min is because of situations where the sdf isn’t accurate (like if it’s been spacially scaled and the values haven’t been). Then the min of one can override the other incorrectly. I assume the sampled static mesh distance fields values are scaled accordingly if the Actor has been scaled before being added to the Global one?

I deal with cases where sdfs have a default positive ambient value so that even if you sample it at a far distance then it will give you a sensible non zero value (ie a value that means ‘outside’ the surface). That probably isn’t an issue for unreal as the 3d textures probably have a correct value for each part of the texture. In my case a small ambient default value might override the actual distance value of another sdf in the compositing stage. In that case we have a solution to rebuild the sdf values based on the 0 interface after compositing.

This looks really cool.
Wasn’t this already in UE3 though, or at least something similar?

Not exactly; UE3 only made use of signed distance fields as a way to store shadowmaps. But that is storing the distance fields as 2d surface like lightmaps. The difference being that instead of storing the light value at each pixel you store the nearest distance to the shadow. The look and limitations of the two methods though is very similar. UE4 still has that same method for stationary directional lights. DFAO stuff uses 3d distance fields (which is the same 3d distance fields being used in this thread).

Technically UE3 also briefly had svogi which is voxelized representation of the world, but it was never released or shown outside of the ue4 version that was temporarily used for the original Elemental Demo. But svogi is very different than distance fields even though some of the uses are similar.

You could achieve a similar effect before using translucency by getting normals from the scene but that version has terrible artifacts since the fluid will not bend ‘around’ a pole, you only see it influenced where the pole’s depths are rendered. But that basic idea is how we typically did water foam edges etc, or the imulsion glowing edges in gears of war.

One thing to note is that if you change these cvars, the global SDF will be garbage until you cause it to be re-updated, typically by reloading the level, or flying really far away and then back.

Can you share this water material? :open_mouth: Or at the very least the normal you used for the waves. It looks amazing.

I’d love to but time is a bit of an issue at the moment. Between a baby, job and side project I’m swamped! I’ll see what I can do.

Thanks a ton! No rush at all, a screenshot of your graph will be enough when and if you get the time. :smiley:

Man I would be interested in that as well! :smiley:

Hi there.
Does this work in 4.9p1?
I tried it and all I get is a purble pulsating material and if I apply the mat instance it gets brown and everything starts to lag…