I'm trying to find a way to fetch the active view layer name or render engine via a driver in shader nodes, the idea would be to use this as a way to customize the shader depending on the view layer or engine.
I tried making a Context type variable fetching the active view layer's name, which, judging from the absence of red marking or errors in the console, lets me think at least that part works.
Then I use the expression 1.0 if view_layer_name == "ViewLayer_004" else 0.0, and though it still doesn't give any error, it still doesn't return 1 when the current active layer is in fact ViewLayer_004.
I have a similar result when trying to access the active scene's render engine:
Using Depsgraph to access the active view_layer directly in the expression depsgraph.view_layer.name == "ViewLayer" kinda works, but not reliably: It seems the depsgraph's updates are a bit unpredictable, i have times when it doesn't update the driven value when switching layer (the below screenshot was taken from ViewLayer, yet the value is still 0).
And most importantly: when running a regular render (single frame or animation), it seems to never update after the first layer render:
Whereas manually rendering each layer using their render layer nodes does work, but that's not a realistic solution:






depsgraphdriver namespace variable rather than creating a custom one. Like in this answer $\endgroup$