Material color based on visibility

Unfortunately, I’m not a C++ programmer. I’ll try the regular forum as well (intead of answerhub) Thank you anyway for your help.