Best way to do triplanar projection on landscape master materials?

@Frenetic made the best points. Texture packing is always the best option (for example, if you find you never use the metallic and occlusion channels of your ORM, maybe you can pack the roughness map into the Albedo’s alpha). And switches are powerful, since they prevent unused logic from even running. If you have something in a material not every instance needs, use a switch and enable it only for the instances which require it.

A simple mistake I’ve seen often is not reusing logic. If you run the same material function twice, it will execute twice, even if it has the same inputs. Instead, execute logic once and use it everywhere you can. For my landscape material, I determine the world-projected UVs once, and reuse it for every texture which I needed projected (use named reroutes if you like, I think it makes things a little easier to understand).

If you notice a material function seems particularly expensive, take a look inside. Often times material functions can be bloated to support multiple use cases. This means it’s possibly performing operations which are unnecessary for your use case. Recreate the function, cutting out all parts which you don’t need.

Also, something with a more selective use case is the Vertex Shader. I frequently work with stylized assets, so I can take advantage of this regularly, perhaps you can as well. There’s two types of shaders: Pixel and Vertex. Pixel shaders run for every pixel on screen (this is how textures can be displayed on your mesh) and they’re the default shader method for the engine. Vertex shaders, on the other hand, run for every vertex of your mesh. They can’t achieve nearly the same detail of a pixel shader, but it can be incredibly more performant. So, if you don’t need the detail, you can move portions of your material onto the vertex shader instead of the pixel shader (typically via the VertexInterpolator node). You should probably look up some more in-depth tutorials on this, I’m not exactly an expert. :slight_smile:

With most other techniques, it’s up to you to determine if the gain in performance is worth the cost in quality (things like texture size, as an example). Optimization, more than anything, is about balancing what you’re willing to accept in quality vs. what you’re willing to accept in efficiency.

1 Like