Download

Material slope/height mask for valleys only

Hi guys,
I have been stuck on the same problems for a few days now. I created an Auto Landscape Material with slope based masks, and I need to add 1 more feature to it which is masking out valleys only, so I need to find all Concave angles, excluding Convex ones. Please see attached images:

MaskExample_BEFORE.jpg
MaskExample_AFTER.jpg

Using a slope mask, how can I achieve this goal?
Thanks!

What you are trying to do is find the derivative or curvature of the surface and that requires sampling multiple points. I do not think it will be easily possible unless you have a texture of the heightmap (preferably a normal map too) of whatever geometry so that you can sample those offsets. You can basically check the cross products of the neighbor normals and check the Z sign of the result.

You could attempt to do it using ddx,ddy… but I have already lost more than a week of working on that particular problem and the result is quite noisy and unusable.

Much better to run this kind of process offline and import a texture mask. or fake it using an elevation mask combined with it.

Hey Ryan,
I was afraid you’d say that :slight_smile:

My best result so far is to clamp the maximum height, like you suggested. It works pretty good on terrains with very little elevation like in my example, or on terrains where valleys are all at the same elevation level.

I do have the initial heightmap used to generate the landscape, I could use it as an elevation mask. But I was wondering if it’s possible to sample the landscape elevation values directly, since it’s possible to export the landscape as a 16bit heightmap texture, can’t I read it from within my material without having to sample that texture?

Thanks a lot for your help!

No, not currently. You have to make a float HDR texture. You need to be careful when making it since float HDR format has a limited range from around -65k to 65k.

Got it, thanks again for your help Ryan!