Can someone give me a practical rundown of how the Landscape Layer Switch is used?
This is just a way to give you more control over which specific parts of your material are compiled for each shader permutation based on layer usage. Much of this will happen automatically so most users probably shouldn’t worry about this, but this would give you the ability to make sure certain effects are restricted to only certain layers. In general though, its possible to structure the material so that this optimization happens automatically but there are edge cases that can be more difficult to ensure that happens for.
Personally I do not use this much since everything I do in each landscape layer tends to be entirely within that layer.
If you are struggling to worry how to use this, I would suggest you may not need to worry about it. All the examples I keep thinking of are handled by doing the instructions within the layer. It may be only useful for more advanced cases where you do things that prevent the compiler from optimizing them but right now Im struggling to come up with a good example.
It feels like this is a misfeature, as it kind of implies that it is doing a dynamic branch optimization to skip work in areas where the blend weight is zero, which would be extremely useful but is not the case. Same thing with the falsely named “Dynamic Branch” node, which even claims to use branching in its documentation, but doesn’t.
I have no idea whats up with “Dynamic Branch”. Looks to just be a material function wrapping around a standard IF statement which is pointless.
We have an internal goal of at some point soon trying to clarify the difference between true code supported material nodes and material functions.
To harp on the issue a little more, we really need some way to branch in materials. Real branching, with dependent nodes placed inside the if block in the generated HLSL. It is very common to have expensive computations and texture lookups that are only applied to a portion of a mesh, especially with landscapes. Even more common is having material effects that you want to turn on and off with a uniform parameter. I know these techniques have pitfalls, but there are those of us who understand them and can make good decisions about when to use them. Your engine shaders make extensive use of them, for example.
I’ve already underlined importance of dynamic flow control for landscapes in this thread. You can use dynamic branching to a limited extent within custom node, if you are not willing to go outside of material editor.
As for LandscapeLayerSwitch, its intended usage is to skip code, if the layer in question is not present on landscape component. As Ryan mentioned, in most cases such optimization will be performed automatically, so this node is not widely used, but occasionally you might need to mess with it.
FWIW, the request to make IF statements support actual branching has been in Jira for a while but is currently marked as backlogged.
Rendering engineer note on jira:
“Currently there is no actual branch support in the material translator, the if node is purely a ternary operator during compile. Adding actual branch support will be non-trivial for it to function as intended, but is definitely needed.”
Good to know, added my vote.
Personally, I would like to see the If node behave exactly the same as an if statement in HLSL, with all computations in the right scope, letting the compiler decide based on its optimization heuristics. Then it would really make sense to have the explicit Dynamic Branch node, and people who actually want a blend can just use Lerp. That would fit best with the experience shader programmers have built up over the years.
Thanks for info on the ticket Ryan. I’ve actually had no doubts that implementing it would be a painful process. Gotta mark what goes under if statement and what stays outside somehow.
Anyway, just in case anyone else from The Staff is reading this, I’ll repeat the suggestion about allowing a matrix output from custom node, that gets broken down into 4 pins in material editor. Might be less work-demanding than implementation of branching by nodes.
Could you give me an example of one of these edge cases, something that could be used between layers and how this switch node fixes it? idm if the compiler takes care fo it
It might be due to my knowledge but I don’t think I’ve come across something like you’ve explained, pretty much backs up your claim haha
Just this topic got too far out of my skill range and I’d like to be able to leave with a better idea of whats going on