Grass Tool spawns below Landscape

Hi,

I’ve followed the [Grass Tool][1] tutorial and used it for my landscape. The grass spawns in a very grid like fashion and sometimes spawns below the landscape and looks like this:

A closeup of the grass below the landscape.

I’ve tried several options for the grass type, with jittering, scaling etc. but I always get the same results. What am I missing?

I did some more testing and realised this behaviour is only evident because I used a high scale factor for the landscape (2500 times for x and y. I need to do this because in my heightmap 1 pixel represents 25 meters).

I looked at the Unreal Source and found something in the file [LandscapeGrass.cpp][1]. The z values of the grass meshes are computed with bilinear interpolation:

OutLocation->Z = DrawScale.Z * FMath::Lerp(
	FMath::Lerp(Sample11, Sample21, LerpX),
	FMath::Lerp(Sample12, Sample22, LerpX),
	LerpY);

which is not the correct way to compute the z coordinates within arbitrary four vertices. For landscapes with a high vertex count the difference is minimal but with my landscape the problems mentioned in the original post arise. I changed the code to this:

FVector P11 = { (float)X1, (float)Y1, Sample11 };
FVector P12 = { (float)X1, (float)Y2, Sample12 };
FVector P21 = { (float)X2, (float)Y1, Sample21 };
FVector P22 = { (float)X2, (float)Y2, Sample22 };

float Z;
if (LerpX > LerpY) 
{
	FVector N = FVector::CrossProduct(P22 - P21, P11 - P21);
	Z = P21.Z - ((TestX - P21.X) * N.X + (TestY - P21.Y) * N.Y) / N.Z;
}
else
{
	FVector N = FVector::CrossProduct(P22 - P12, P11 - P12);
	Z = P12.Z - ((TestX - P12.X) * N.X + (TestY - P12.Y) * N.Y) / N.Z;
}

OutLocation->Z = DrawScale.Z * Z;

Which fixed the grass position.

Without my changes the scene looks like this:

The grass spawns either below the landscape. Or sometimes above (not visible here). With my changes the same scene looks like this:

Am I still missing something? Or is this a bug in the landscape grass node?

Cheers

1 Like

Definitely something that should be looked at by Epic, any feedback?

Did you somehow extend the said file, or recompiled your own version of the engine?

@bneukom : could you make a bug report at Unreal Engine Bug Submission Form - Formstack so this will get fixed for everyone?

I had to recompile the engine and replaced the code as mentioned in my reply above.

Are you facing the same problem? @eyoli

thank you.

Not yet since I am not using upscaled landscape, but if this is a bug it needs to be fixed and the best way for this is to report it into the bug tracking system.

Mhmm, I’m facing a slightly different issue where my grass spawns WAY above the actual landscape. Tried everything, can’t figure out the cause.

this may be due to your grass mesh. Make sure in your modeler it has its coordinates at 0,0,0 and make sure you applied all transforms. Same goes for rotation/scaling.

Sometimes it also spawned above for me. Is it always the same distance above the landscape or does it vary (as in my screenshots)?

Was always the same space from the landscape, i tried messing with the Z scaling, somewhat hacky fix for it but it’s still not giving 100% proper result.

i have this same bug, i was stumped for a couple of days until I stumbled across this post , video for reference… bug report, foliage spawns underneath landscape on scaled plane - YouTube