Landscape-conformity for large grass patches

I’m quite proud of this so I had to share it. I found some amazing grass but it didn’t suit my rugged terrain very well as the patches were quite large, leaving the edges often floating in the air. I’ve managed to use distance fields to warp the grass so that it conforms to the terrain.

The biggest issue is that I wanted to transform a world coordinate into object space to work out if I was manipulating the bottom of the grass rather than the top. This didn’t work out so well as apparently the transform node in materials doesn’t handle rotation so I couldn’t get an instance-aligned gradient. In the end I used the UV coords which unfortunately means each member of an atlas needs extra work and its own material instance.

Here’s the material:

https://i.imgur.com/gds4uTy.png

This video has the results of the lerp mask as an emissive channel, so you can get an idea of where that mask should sit:

Typically, you can use one of vertex color channels to define top-bottom gradient on on the grass.

TransformVector and TransformPosition material expressions work fine with instanced static meshes in vertex shader, hence you need to pass them through vertex intepolator material expression.

I had no idea VertexInterpolator existed. Thank you!

And less than a minute later I realise only the debug output was failing to transform correctly.