I’m aiming to get the background color, is there a way to get whatever color is behind an object ?
You could use holdout as a global material with object/material index for comping effects. If you want to color a pixel of the object, the only way I can think of is using a transparent shader which is then blended. Being a shader, you can’t use the information prior to any shading stages. If you want to do “if pixel behind is white, then use green diffuse”, then no. That is impossible because we don’t have a raytracer object to perform such evals. As far as I know anyway.
Well… for the background color is not that difficult… One just needs to copy the background material into the object’s material, and use it as a texture (as long as we correct the projection vector). I don’t know if in OSL, the trace function with the shade=1 could retrieve a shading color; but for now, Cycles don’t even use the ‘shade’ option, and the only thing one can get from trace() is if it hits something and the hit distance.