Debugging "failed to compile material"

I’m tinkering with landscapes and I’ve found that, with a specific combination of landscape materials, I get the error “failed to compile material”. Now, I actually know why this is happening - it’s because I have too many landscape materials at once, and this produces a shader that is too complicated to run, in some manner. But I’d really like to have better diagnostic results so I can see what, precisely, is causing the issue. Multiple questions along those lines:

  • Is there any way to preview a specific set of layer blends within the material editor itself? It seems to just default to “first layer is 100% intense” which makes it hard to see what I’m doing.

  • Is there any way to find out, in detail, why a shader failed to compile?

  • Alternatively, is there any way to retrieve the shader code of the shader that failed to compile, so I can diagnose it by hand?

Hey ZorbaTHut -

Currently there is no way to preview as you are requesting but that functionality is coming down the pipeline as I write to you. If the shader fails to compile (assuming that you have not added any Custom HLSL scripting) you should get a notice in the Material Editor’s Output log window, let me know if you are in fact not getting this notices.

Thank You

Eric Ketchum

I get a message, but only the first time a material fails to compile (which isn’t very handy in the case of terrain), and it’s not a useful message. It’s just “failed to compile lol sux to be you”, paraphrased.

I might be a little confused as to what you are seeing, but in scripting it is common practice to stop compiling at the first error and return that and the next time you compile assuming that error has been fixed and there re more errors you will get the next one in the pipeline.

Eric Ketchum

Keep in mind I’m not writing a shader when this happens. I edit the landscape shader and that “compiles” fine. The error occurs when I paint a set of elements on the land that it doesn’t like. It attempts to compile the shader, fails, and then apparently caches the failure - if I don’t see the failure the first time it happens, I’m never given a chance to see it again.

And even with that failure I don’t get any kind of a useful diagnostic message, it just says, and I quote, “LogShaderCompilers:Warning: Failed to compile Material /Game/Landscapes/Materials/M_LandscapeMaterial.M_LandscapeMaterial for platform PCD3D_SM5, Default Material will be used in game.” I got this by painting a tiny patch of rock in an area in my level - no material editor involved.

I won’t get that error again unless I modify the shader or unless I clear the entire shader cache. The only way I knew where to look for it was that I spent half an hour trying to figure out why it was refusing to render a chunk of my terrain properly.

Hey ZorbaTHut -

This may be an edge case that we have not come across before, is there anyway you can screenshot your entire landscape material (including functions) for us to test this.

Thank You

Eric Ketchum

It’s based directly off the Landscape example, just with another two textures, one of which has a real roughness and split-apart height texture. (Which I should probably merge into the base and normal just to save on texture lookups, but haven’t yet.)

I was able to retrieve the actual build errors and it was complaining about more than 16 texture samplers. By my count this is doable with 12, which is within limits, but I’m assuming the engine is doing some magic stuff in the background that require a few more.

That said, “stats” tells me it’s using five texture samplers, which is completely impossible for any interesting mixing - I’m assuming that it is assuming the “soil” layer is at full opacity, which lets it optimize away essentially the entire shader. In this one case.

Hey ZorbaTHut -

Thank You for the clarification. I understand your issue much more clearly now. Any material can only use a total of 16 Texture Samplers but 3 of those are reserved for lighting information (depending on your shader model you are using). With the picture you have above I am seeing 11 individual samplers which should be within the realm of doable.

What I would do to really test this and see as you go exactly what the errors are, open the Output log in the editor then slowly paint each layer on the landscape and allow each to compile or not. You can see the compile error in detail in the output log (which you can scroll back through as well). Once you get a compile error look at that particular branch of the material and see if anything is amiss in the material setup (most likely a height blend issue, if there is one) In the past, simply painting the landscape with each layer one time allowed the whole shader to compile and removed compilation issues.

Thank You

Eric Ketchum

Each individual layer renders fine. Painting Grass, Soil, Cobblestone, and RockyCliffs on together causes an error:

LogShaderCompilers:Warning: Failed to compile Material /Game/Landscapes/Materials/M_LandscapeMaterial.M_LandscapeMaterial for platform PCD3D_SM5, Default Material will be used in game.
LogShaders:Warning: warning X3206: implicit truncation of vector type
LogShaders:Warning: error X4510: maximum ps_5_0 sampler register index (16) exceeded

(That’s all the layers except for the middle layer in the screenshot.)

Removing any of those component layers brings it back to functionality again.

Hey ZorbaTHut -

I checked with my colleagues and need to correct myself, with landscapes in the engine before v 4.6 Preview you are allowed a maximum of 13 texture samplers (3 of which are reserved for lighting models so really only 10 unique textures). This means your material with all the different layers painted at one spot exceed the shaders computation capacity.

Assuming you set up your materials correctly you should be able to use this setup in 4.6 Preview or later with no problems.

Thank You

Eric Ketchum

Hi, I have the same problem with 4.8 preview. Can you help me please?

Hi vinz243 -

Since this particular issue was dealing with pre-4.6 builds of the engine, can you post a new question and include screenshots of the errors you are receiving and the complete material setup.

Thank You

Eric Ketchum