How do I get distance field shadows to work with the foliage tool?

Hi all,

I’ve been struggling with this for a few days now, everywhere I look says it is supported, but no matter what I do I can’t get it to work.

So here is an example of what I mean:


In this example both trees on the left were placed as foliage, the one on the right was placed as a standard static mesh, they are all set to dynamic and the one on the right has distance fields on.
The ones in foliage also have the affect distance field lighting ticked, so they all have it.
They all are being displayed fine in the visualise distance fields mesh (more screenshots bellow)

But as you can see, distance field is working just fine in the standard static mesh, it has a much better self shadow quality then the other 2.

Now my question is, is it possible to get distance fields shadows to work with foliage or is it the best I can hope for?


And here is the same tree on the right, but with Distance Field Indirect Shadow off.
Notice how it looks exactly the same as the foliage ones (that are supposedly using distance field).

As a general rule of thumb, first make sure your project settings have it enabled.
Then, in the mesh, consider trying to check two sided distance field geberation.
Then, check of you have a resolution option set for it. Under Build Settings in the mesh.
Then, show > visualize > mesh distance fields
check if they are built. builbuilding lights which should force it to rebuild if they havent.

Hopefully that gets it to work.
If not,
try this guide

Thanks for the reply.

It is applied in the project, as you can see, the tree on the right has it active, the same tree is being used for foliage and both of them have the distance field mesh properly built as you can see in the screenshot that shows “visualize distance field mesh” activated.
Lighting has been built and rebuilt several times, and like I said, you can clearly see it working for one and not for the others.

And lastly distance field AO is not something I’m interested in, my sky is not going to be dynamic, its stationary, all I want is for the trees in the foliage tool to look like the (same) tree outside of it under the same circumstances.

Read the doc. It gives pointers specific to foliage.

also this

Technically you can sample the global fields in the material, maybe you can force foliage to look the same with that.

Howrver, I really think the issue is the setting on the mesh used for the foliage brush.
what engine version are you running?

I’m using 4.25.1 but the same is true for 4.24, I haven’t tried in earlier versions.

I had read that doc already, like I said, I’m not interested in distance field AO, it may look good for that kind of scene but doesnt for mine, and like I also said, the SAME tree on the right is the same model, the way it looks there is the way I want it to look in the foliage.

I’ve also tried 2 sided distance field mesh before, it doesn’t look good in the normal model and it still doesn’t work for foliage.

Thanks for the video though, I haven’t watched it all yet but it seems full of good info.

But in regards to my problem I’m starting to think that it simply doesn’t work with foliage.
You can try it yourself, with a default scene to be quicker.

Get distance fields activated, get a model (plant or anything else). Place it to your scene, activate Distance field indirect shadows on it and see what it does.
Then drag the same model to foliage, paint single, activate affect indirect lighting on it, paint one next to your original model and see what it does.

Build and see again.

Then switch it on and off on your original model and you will see that when it is off it looks the same as the one in foliage.

My theory so far is that it doesn’t work with foliage at all, what that box does is probably to say that the model will affect the volumetric light map and will affect OTHER models that have it on outside of foliage.

I’ll give it a shot in a blank project when I can, but I have several open projects that use it and they look like they are still making use of it.
They do make full use AODF though. I know it works on those because like the doc says I had to adjust the billboards several times to correct pixel depth artifacts.

oh. Well, give the peocedural tree placement a shot. That could be why I have it working…
instead of painting foliage.

You are turning INDIRECT distance field shadow off. Indirect shadows do nothing in direct light (such as for example being directly lit by the sun).

Your static mesh tree in the first screenshot looks like it is using baked lighting, but all three definitely look like they are casting distance field shadows.

Edit: If you’re looking for confirmation, I tested it and you are correct, there is no option for indirect shadowing and it does not seem to apply by default. Not sure why, but direct shadowing still works

Well turning it off on the foliage doesnt change the look, but it does when turned off on the static mesh, as you can see in that picture they look the same when its turned off on the static mesh.

The baked lighting is not being used by the static mesh with indirect shadow on. unless you mean the volumetric lighting, in which case Id like to see it being used as well by the foliage.
Any idea on how to make the foliage look like the one that is just a normal static mesh actor?

I tested it just before I read your post, you’re correct that foliage has no option for indirect shadowing (unless I’m blind) and it doesn’t work by default. Direct shadowing from distance fields works, DFAO works, I’m not sure why indirect shadowing wouldn’t.

You won’t be able to get them to look identical without that (unless you turn it off on your static mesh and accept the flat skylighting). If the tree doesn’t need to moveable then you can just bake down the indirect shadow, but if it does then your best option would be to go with a moveable skylight and use DFAO. The DFAO will help keep the shadowed lighting from being flat, and it will match the static mesh.

Part of why I linked the DFAO.
the other way would be to work some shader magic and sample the distance filed within the material to decide how to darken the base color.

Thanks guys,

I can’t use the distance field ao from the skylight for this one as it doesnt look good in other objects, but I found out from MostHost LA’s link that you can have a shader that will have distance to surface based AO, on the shader. I dont know if you need the DFAO turned on in the skylight for it to work or not, but I will give this one a shot.

If none of it works what I will do is populate the foliage with place holders in max and replace them all in UE, not the best approach, but at least will give me the correct look.

Once again, thanks!

Just an update.

Here is how it looks with DistanceToNearestSurface added to the AO per shader (was a pain to get this to work).
It is not as straight forward to implement and I’m still not sure about the performance cost of this, but at least its looking much better.

The cost depends on how many instructions you added more then anything.
the instancing system should take care of most of the load.

You can test with 1k trees in the scene. Assuming they have proper LODS.

Distance Field Indirect Shadows are stated to not show much, or at all, in brightly lit areas, areas with not enough bounced light, or areas that are directly lit (which I’m assuming means strictly directly lit). What are the material settings for the trees’ leaves?

As you can see in the first screen shot, this is not the case, as the SAME tree can be seen working just fine outside of foliage.
The material is also not relevant as the same happens if you use a cube, for example, with a default white material.

I’m convinced that it doesn’t work, or if it does, it requires some obscure setting to be activated somewhere I don’t know.

I’m not saying it was the case. But a setting has to be turned on for the “Distance Field Indirect Shadow” box to be exposed in the details panel…so it could be associated with something within the distance field functionality that is not currently connected to foliage as it is for separately placed static meshes. It’s definitely a limitation, and was overlooked for foliage. The DistancetoNearestSurface addition to AO looks good, albeit not as defined as the initial static mesh w/ DF Indirect Shadows.

My question is how did the static mesh tree in the 1st screenshot have detailed self-shadowing while it is in brightly lit, direct lighting that has few or any bounces since it was placed in an open area under a stationary skylight. Dynamic Inset Shadow is another option, though not sure if it would apply to foliage too.

If I understood correctly, Distance Field Indirect Shadows doesn’t work for foliage?
I’ve been trying to find a solution all day long(

foliage as a checkbox to accept indirect light that probably all of us turn off first thing when looking at frame costs… it may or may not be on by default.

all meshes have this setting, and it causes havoc with LPVs - still haven’t tried the new stuff in .26 that supposedly moved or removed lpv allowing emissive to just alter the scene, but in .25 where you have to specifically enable it and set up, anything with the setting on will essentially glow much brighter. Because of an absurd amount of light bounce being calculated by default I would assume.

whats that all mean and why do I bring up lpv? Light propagation volume.
the indirect shadowing would 100% rely on volumetric lightmaps in foliage or on a mesh.

if you don’t specifically enable the settings for LPV I’m not sure you actually get the same result with distance field shadows. So maybe this could just work in .26 given they changed the horse mid race on us.

So, really depends on what you are trying to do and what engine version you are on.
as well as if volumetric lightmaps are being used or not (build geometry, and reflection captures at the very least).

I can’t get it to work for foliage either. The checkbox for it is completely missing

I was able to get Distance Field Indirect Shadows working with foliage using C++. This custom code will enable/disable DF Indirect Shadows:

void UGenericHelpers::EnableDFIndirectShadows( AInstancedFoliageActor* Foliage, bool bEnable )
    auto MeshComp = Cast<UInstancedStaticMeshComponent>( Foliage->GetComponentByClass( UInstancedStaticMeshComponent::StaticClass() ) );
    if( MeshComp )
        MeshComp->bCastDistanceFieldIndirectShadow = bEnable; //Enable DFIS
        //Needed For Editor To Update Changed State
        MeshComp->SetVisibility( false, true );
        MeshComp->SetVisibility( true, true );

Simply invoke it from Blueprints Like This: