How can I apply different physical materials on a single material?

Hi everybody, I created a material I’m using for a small sized planet. Now I need to apply different physical materials to it but I don’t know how to do this. I’ve found I need to use layers and physical material output but I don’t understand how to use it. Please help.
Here an image of my material blueprint:

Thanks.

There’s lots of tutorials

1 Like

Thanks for the reply. I found the video quite useful, I used the method from 18:20 and I recreated the planet material using different layers but now I have the same problem as before because I don’t know where to set physical materials to the different layers. I can’t do it in the Material Layer, same in the Material Layer Blend and the Material itself with the Material Attributes Layers node. Any ideas?

1 Like

Thanks again for your answer but I still don’t get it. I watched a lot of videos about layered materials but I never found anything about physical material assignment.
I know how to use physical materials on a basic material but now I need to apply different multiple physical materials to a single layered material. I have the main material with Material Attribute Layers, I have Material Layers and Material Layer Blends.
I have one base texture blended with a second one using a “clouds” texture as Lerp Alpha.
I have the poles texture blended using a Function based on distance from vertical center.
I have a 4th texture blended based on the radial distance from the object center.
How can I assign a physical material to each of the single layers?

I haven’t tested it AT ALL, but I’m assuming you specify the physical material in each material layer, because that’s basically a material. Either that, or it may be in the slot part of the main material, once you’ve put it all together.

Sorry I don’t have more info.

Hi - I just looked at this again, and as far as I can see, it’s not possible to specify physical materials for the layers in a material layer blend.

Is this for footsteps, or similar?

I’m assuming you’ll need to use landscape layers, then.

Yes it is for footsteps and stuff, but I’m not using a Landscape because the “terrain” is a Static Mesh in the shape of a planet. Can I use the Landscape Layers in this case too?
Or is there a way I can do what I need and make a line trace detect the different surfaces?

1 Like

You have to try all these things, I’m afraid. I can’t recommend a route from memory.

I also have a spherical planet, with footsteps, but it doesn’t have layers, it just a normal blended material.

I’m doing a line trace, but to get the material back, it’s a whole thing with something I ripped out of Niagara.

It might be easier now, I don’t know…

I’m assuming you already had to write a special pawn. Everything’s going to need to be custom :wink:

An option may be to use Physical Material Masks. This post covers how it works (as it doesn’t appear properly documented):

It will probably depend how your material is structured how useful it can be (as in can it relate to a static look up). The usage basically resolves to the raycast hit mapping to the UVs of the mask and returning the index of the physical material.

1 Like

Ok I managed to use Physical Material Masks with colors (the material is simple so I can do it with just red, green and blue) in the master material but I noticed that the Physical Material Mask doesn’t seem to work on material instances. Is this normal or am I doing something wrong?

Yeah looking at the code it’s not implemented for instances (not sure why), it does seem like a big limitation.
Code wise it doesn’t look like a big change to add support in the engine.

1 Like

Maybe I found a way. I created the spots for grass/dirt in different colors painting on the planet mesh in Blender, then I imported the image as the Physical Material Mask and used it as the mask and also as the lerp Alpha for grass/dirt textures. Ok I need to create a lot of master materials (this is crazy imho) but the real problem is that now the Engine crashes everytime I open the map or the blueprint where the mesh with the material using Physical Material Mask is present.

When it crashed was the message in the log something like this:

Registering a texture to the compile manager from inside a texture postcompilation is not supported and usually indicate that the previous async operation wasn’t completed

If it is I got the same issue when I was trying out some changes. If you are working off source the apparent fix is to wrap the MaskTexture access in GenerateMaskData with a PreEdit & PostEditChange in \Runtime\Engine\Private\PhysicsEngine\PhysicalMaterialMask.cpp due to where it gets called in the post load flow. Just replace the function with the below.

void UPhysicalMaterialMask::GenerateMaskData(TArray<uint32>& OutMaskData, int32& OutSizeX, int32& OutSizeY) const
{
	OutMaskData.Empty();

#if WITH_EDITOR

	if (MaskTexture)
	{
		// Avoid any issue with the async texture compilation (even though no texture data is changed)
		MaskTexture->PreEditChange(nullptr);

		uint8* TextureData = MaskTexture->Source.LockMip(0);
		if (TextureData)
		{
			const int32 TextureDataSize = MaskTexture->Source.CalcMipSize(0);

			if (TextureDataSize > 0)
			{
				OutSizeX = MaskTexture->Source.GetSizeX();
				OutSizeY = MaskTexture->Source.GetSizeY();

				ETextureSourceFormat TextureDataSourceFormat = MaskTexture->Source.GetFormat();
				switch (TextureDataSourceFormat)
				{
				case TSF_BGRA8:
				{
					MaskDataGenerator<uint8, 2, 1, 0, 3> MaskDataGen(OutSizeX, OutSizeY, TextureData);
					MaskDataGen.GenerateMask(OutMaskData);
					break;
				}

				case TSF_RGBA16:
				{
					MaskDataGenerator<uint16, 0, 1, 2, 3> MaskDataGen(OutSizeX, OutSizeY, TextureData);
					MaskDataGen.GenerateMask(OutMaskData);
					break;
				}

				default:
					check(0);
					break;
				}
			}
		}

		MaskTexture->Source.UnlockMip(0);

		MaskTexture->PostEditChange();
	}
#endif // WITH_EDITOR

	if (OutMaskData.Num() == 0)
	{
		OutSizeX = 0;
		OutSizeY = 0;
	}
}

I’ve submitted the fix to Epic, but no guarantee when it will get rolled in. I’ve also submit the changes for physical material masks working with material instances.

If it is the same crash you can work it without a code change if you disable the async texture compilation in the editor. This obviously may slow down things a bit, so only use if you need to.

You can toggle this in the editor preferences:

Or you can disable temporarily via the console:
Editor.AsyncTextureCompilation 0

And reenable with:
Editor.AsyncTextureCompilation 1

4 Likes

Thanks for your answers, I’ll try as soon as I can and let you know if it worked. I don’t remember the crash message but I will check it next time this happens.