Download

Using Material Functions with Landscapes

Good Afternoon

So I have been creating my Landscape Materials with a simple Landscape Layer Blend node so I have the ability to draw them on where I see fit. But we all know how massive they can get. So I discovered that I can create a Material Function, add a whole material network to it and save it, that way I can add one node to another material to represent another whole material. Now I see I can add a Material Layer Blend node to blend these functions together.

My question is, is there a way to do hook these Material Functions and Material Layer Blends to a Landscape Blend node for a Landscape Material. When I try it says “Material Attributes are not compatible with float.”

If you want to use Functions, then instead of using the “Landscape layer blend” node, you will use individual “Landscape layer sample” nodes. Those output a 0-1 alpha value for the layer that you can use as the alpha for one of the blend functions such as “MatLayerBlend_Standard”.

Ok I figured out how to get that to work.

I saw in another post that I will also need to convert all my material Coordinates to Landscape Coordinates and that I had to “plug your Landscape Coordinates into your material function, by adding a parameter in the material function for the UVs of every texture in that function.” Is that correct? Could anyone give a screen shot example of this? Because when I do it my sizing is totally off so want to make sure I have things set up right.

In reality, I am taking already made materials for basic ground stuff, and converting them to Material Functions to use in a Landscape Material.

Could you expand on this approach, Ryan, or perhaps link to an example? I ran into the same issue, and solved it differently. I would like to know if my approach is incorrect.

Material functions by default output materials (material attrs) that can be used in MatLayerBlend nodes. My base layer uses the MatLayerBlend_Standard node to slope-blend materials from functions that produce rock, grass, and sand.

But I also wanted to be able to paint those same layers manually, for touch up, and also to paint in other layers for effect. The LandscapeLayerBlend node takes textures as inputs, and isn’t compatible with material attrs. I could use BreakMaterialAttributes nodes to get the textures, but that seemed really messy. So what I did instead was to have each of the material functions have secondary outputs that returned the generated textures. So the material attributes result goes to the MatLayerBlend nodes, and the texture outputs go to the LandscapeLayerBlend nodes.

Is there a way to use the LandscapeLayerSample node to simplify this?

Thanks!

Well, actually, Material Function put out whatever type of data you connect to the output. When I connect a scalar to an output, its a scalar.
If you want the function to return a complete material, you have to use the “MakeMaterialAttributes” node within the function and wire that to an output.

That’s a good point and thanks for clarifying it. I should have said that the material functions I learned from were wired up to output material attributes, and that’s the pattern I followed.

Ok…

So I have the two Material Functions created and attached to a Material Layer Blend. But the Landscape Coordinates are not working, as seen in picture 1 (even though the Texture Sample is correct). If you look at pictures 2 and 3, it shows that each of them connected directly to the Material Attributes node functions just fine. What am I missing?

Heres the pictures again unattached.

b9d8d466a9f837580aaf92bd9ccc12f4b0c06edc.jpegc01acf4bf90c5f9a86a972b1c6da9eded1541c0c.jpeg46512205f566e59564772e2c0a8087883dd0bf8e.jpeg

If you want to use your material functions, you cannot have parameters inside them. You need to use function inputs.
These will the nshow up as input pins of the function node when you grad it into your material graph.

The reason why material functions cannot have paramters inside them is to prevent ambiguities if a function is used multiple times in one material graph.

So here is a quick example of material function use…

This is a function that lets you specify a mask channel, a tint color and a boolean to enable or disable (set to black) the output:

Func1.jpg

This function is used several times in another function. See, no parameters yet. Only the red input nodes.
this function has two outputs. One for the diffuse and one for the combined alpha. It basically blends 4 colors based on a mask texture onto a background color:

Func2.jpg

And in the material, finally, the parameters are set up:

d5679b10921cfb8b17c5de45796d48fda97133eb.jpeg

Now I can create material instances, or create double blend where I lerp two of these nodes together, etc…

So: Materials have parameters, function have inputs :wink:

Hope that helps :slight_smile:

PS … In case MF_Grass, etc are your functions… lemme see them … (just found them in your screenshot :rolleyes:)

I did use a Function Input in the same place for both my functions in order to have a spot to plug in the Landscape Coord node.

f6385de308cbcc967989c1f57bcf1a5cee337913.jpeg

Or is there no way to use this method on a Landscape? All I want to do is blend multiple materials together like I do Textures.

Blending whole functions is the ideal way to do landscapes. It is what we did for the Kite demo cinematic level.

You can have parameters inside functions as long as you understand that they will all be controlled by the same parameters if you use the function more than once. For me it is pretty normal to add a bunch of prefixes to the parameters in a function and name them according to each layer I make. Sometimes I’d rather rename a bunch of parameters once rather than have to hook up scalarparams to each material where a function is used but it just depends. ie “TilingRock_01_Scale”.

Your blending example above looked like it was working just fine, but possibly the scale of your mask was wrong or the values were not going to black or white meaning you saw more of a blend between the textures.

Try using the material function “CheckerPattern” instead of your alpha. Set the size to something you big like 1000 and hook it up to your blend alpha.

Ryan, I dont think you are seeing my issue. My issue is the landscape Coordinates get removed from my Material Function Nodes once they hit the Material Blend Node. My alpha was the exact scale I wanted it to be. But I will show you again with what you requested.

1_Grass.JPGc999f78dab8a18a78e5ece7c4f769edfbb3bc8d4.jpeg9f02b4835b17fe797d57d47c5aac1a16c53f6166.jpeg

Now I have my landscape Coordinate Node set at 630, and since the “overall resolution” of the landscape is 631X631 then (as shown in figures 1 and 2) my Grass and Dirt Materials should be taking up the entire landscape. But as seen in figure 3, as soon as the same information gets passed through the Blend node, it removes it. Is this a bug? How do I get around this issue?

I am unable to reproduce this issue here. For simplicity, try setting your Alpha to 0 or 1. Nothing about the MatLayerBlend function should alter the coordinates.

On the right is the landscape.

Landscape_Coords_01.JPG

Landscape_Coords_02.JPG

My landscape is the default 505 resolution and I entered 505 as MappingScale for the landscape coordinate node.

What version of the editor are you using? I am testing in the upcoming 4.8 build right now. There is a chance this was broken in your version but has since been fixed in a newer version. Setting alpha to 0 or 1 will narrow it down though.

I was using 4.7.4 right now but will update tonight.

I tried putting the Alphas to 0 and 1 will no change. Ill let you know what the version change does.

ebdcc59a34fcf1794baefba7f1ca4a4c19b52a2f.jpegeba462eea72c8ded335ba586662b5f10e2b8bfc3.jpeg

Well I just updated to 4.7.6 and it is still broken.

Also doesn’t work in 4.6.1 either.

If this is fixed in 4.8 is there an eta on its release?

Ok well I downloaded the 4.8 preview and this is still broken for me. Is there anything wrong with my function? I made a real quick one to show you and tested it.
b2066d44675a54bb8a022fd055574bee33374e80.jpeg

ohhhh I had no idea you were using custom UVs. It is because MatLayerBlend_Standard does not even blend customUVs, only the most basic channels.

Try hooking up your landscape coords to custom UVs on the final material input node itself. That means do not use MaterailAttributes as the final pin. My guess is that its being lost somehow by the attributes nodes.

Also, with your above setup, it will give crazy results if your landsacpe coords are scaled differently in any functions. In order to blend between two textures with different tiling, you still need the coordinates for the entire area for each layer, not a final blend of all the coordinates like that setup would create. Otherwise the textures will drastically change scale and warp as they transition to eachother.

Could you give me a few screen shots for an example so I can wrap my head around it? Show me how my function should be set up very basically and how to blend the two in a landscape material? Im much more a visual learner :slight_smile: Thanks Ryan.