idea is similar to this one
reshade.me/forum/shader-suggestions/1494...ut-white-black-point
but requires buffered previous frame.
Works simple : we check if pixel at same coords hasn't changed or not changed significaly (need some threshold settings for that) from previous frame - this will indicate static object which most likely would be UI. At static scenes there could be glitches, so there has to be some threshold of percentage of static pixels per scene, so lets say if more than 10 of pixels are static most likely it isn't hud so we don't apply masking here. This shader shold not be used globaly and should be used as aid to separate shaders. I'm not sure this can even be done in pure shader so sush thing shold be better implemented as native reshade function that can be used in shaders.