This is because ObjectPosition does not return a valid number for Foliage objects (always 0,0,0). Try using “Per Instance Random”. Or you could try instead try using const3 (0,0,0) Transform(Local->World) instead to get the actual object position, but I think that may also have to be computed via CustomUVs:
FWIW, you can debug the output of nodes like objectposition using a material function called “DebugFloat3Values”. There is also one called “DebugScalarValues” etc. It will actually print out text of the float values of your material expressions. Just make your mesh into a box and hook the debug node up to emissive and you can quickly figure out where this stuff breaks down. Often trying things via CustomUVs will get them to return values when they don’t work in the pixel shader:
There is also a node called SpeedTreeColorVariation that does something similar that works on foliage.