Mesh Distance Field in Material Function to produce custom AO

Hey, guys.

As you probably know, DFAO can’t be properly combined with static lighting scenes due to its dependency on movable skylights. There are many forum topics and answer hub questions about this limitation.

Well, I was watching this lighting masterclass video and Jerome Platteaux talks about the possibility of using Distance Field in Material Functions to produce AO. He even shows a node tree at 30:03, but sadly the resolution is not high enough and I couldn’t figure out how to replicate the MF. I’ve been trying to find more info about that in the web but no luck so far.

Have you guys ever tried that approach before? I’m really curious to see how it looks like and experiment with that…

You actually can apply DFAO to static lighting with ‘r.AOApplyToStaticIndirect 1’, however it’s a bit tricky. Both lightmass and DFAO are going to be computing indirect occlusion and you’ll get double shadowing from static geometry. You can then disable bAffectDistanceFieldLighting on the static geometry to prevent this.

You can also compute your own AO from the DistanceToNearestSurface material node as Jerome was talking about, however that only samples the global distance field which is a lot lower resolution than the mesh distance fields that DFAO operates on. To compute approximate AO from a SDF check out this presentation:
starting page 36


I was wondering if someone finally made an implementation of this that could share or write some notes on how to proceed with the material. It will be really helpful because im having a hard time on the matter (i do understand what the quoted paper says, my problem is on how to implement it on a node based shader).