Grass displacement using mesh distance fields issue.

So i’m using this setup i found in a tutorial to make my grass move when the player walks through it but I have a pretty big issue with how it looks.

The grass deforms very harshly i guess? Id like it to be more smooth and not cause the blades of grass to become misshapen as seen here but im unsure what can be done as im very new to material stuff like this.

image

This is the material setup. Im also using the simple wind function. Any advice would be very appreciated.

1 Like

You can’t without knowing what you are doing.
Your model and model data is mainly at fault.

And then your vertex paint RGBA selection makes even less sense.

And you aren’t “bending” anything, you are literally pushing vertices away in a questionable direction.

The turorial you got this from is probably bad either way - or uses a specific mesh you don’t have.
Or paints foliage without a random direction - possibly.

Also, distance fields arent a great way to get this going - though easier than other alternatives for a beginner…

All i can really say is that the vertex color thing is just to keep the bottom of the grass from moving. Are there any other ways of going about this that youd suggest?

I saw another one where it would get the world position of the player and use that to move the grass but im unsure how id get that to work with multiple actors.

The vertex color is wrong. You probably have only 1 channel defining what moves or doesn’t move. Adding in other channels can skew results / behave erratically.

You can do whatever you want to do if you know what you are doing or you invent a new thing for it.

A good way to handle deformations is using render targets and vector field data.

Its just that you have to learn the material pipeline or HLSL and the caviats of the engine you want to use to get your peoject running with it.
Different engine, different requirements or techniques.

In theory, mesh distance fields act like a render target with vector fields of which you have no control of the shape of (and they cost you a ton more than a render target would too).
The problem is the way they are utilized makes little to no sense.

Youd have to first determine if they actually return a normalized value that correctly represents direction - if they don’t, you have to make them return the correct value.

With that value, if you times 1000 * vertexnormalws and apply it to a single plane material you should see the plane start to move in the correct direction by remaining 1 meter away from the direction the object Face Normal is pointing (its really not face normal based with distance fields, they are an approximation to begin with but its easier to visualize/explain).

Now if you apply that code/value to the verts of a grass clump (particularly with vertex paint reducing the effect) you have the top verticies moving away by 1 meter while the bottom doesn’t move at all.

Does that seem like an accurate description of what you want to happen?
No.
And therein lies the bigger problem…

The system you took/or tutorial is an approximation.
Most tutorials/shaders are

With a lot of work, you can get to where items move like this

Instead of this

And

If you cant even spot the difference, then stick to the bad code you had above and dont give it a second thought.

1 Like