Layer sample in different material?


Just a wild and probably stupid question.
What does the Landscape Layer Sample node actually output?
Landscape material:**

Sphere material:

Obviously the right half of the sphere doesn’t turn white as it’s moved on the painted Layer_04

Is there any way to use the data from the landscape paint in other material?

I did not check but i’m pretty sure that LandscapeLayerSample will output a uniform zero, if used on anything other than landscape.

Disregarding possible modifications to the engine, you have pretty much three options here:

  • Use WorldPositionRG for texture coordinates, both for terrain and the object, you want to blend in.

  • Export out layer weightmaps and re-import them as texture.

  • For the object, use the same material as for the landscape, but instead of using landscape-specific blend nodes, re-create the blending via ordinary lerp/height lerp, based on weightmaps as textures.

As you can probably see, that is pretty lame. Double memory usage for weightmaps and lack of native terrain shader static branching makes this technique pretty terrible.
I would only consider it probably if I was using not more than 4 layers with a channel-packed single splatmap.

  • Render terrain material near the player into a render target

  • Use it in materials of the objects you want to blend in.

Depending on the task, it can be quite effective or not usable at all. Obviously, this will onlywork near the player. To blend a rock, you would actually need to render base color, normals and perhaps roughness, if you are not approximating it from base color. This is probably an instant no-go. For, grass, however, it can be very viable solution, provided that you are using a splatmap texture instead of layer weightmaps.

  • Use WorldPositionRG for texture coordinates, both for terrain and the object, you want to blend in.

  • Allow for up to 4 set of terrain textures to be blended using vertex color RGB in object material

  • Get in terrain’s normal map into your object’s material. Lerp between original mesh normals and terrain normals based on vertex color A.

This approach is versatile enough, but relies on manual work and also has certain performance costs, but it easily usable for large cliffs/props.
It is also expandable to support tri-way mapping(If someone did not vote here, it is your chance:cool:).

I went slightly further and adopted it to blend in small terrain scatters, that were placed with grass system, removing need for vertex colors.
It involved creating a gradient mask from instance pivot in the in the direction of terrain normal. And considering that grass system spawns those props mostly on separate terrain layers, I’ve skipped blending terrain layer textures in props materials. It worked surprisingly well.