Constant color?

Trying to find a way to make an object material that is a constant color but not Emission as it doesn’t maintain any shadows. I don’t want to composite anything in post.

The pic attached just an illustration where a character will be leaning over a surface. Ideally, the background should be the same as the surface with the constant color …

Use an emission shader and connect a light path -> is camera ray into the strength of the emission shader.

Constant color but with shadows ?
In Eevee you can extract shadows using shaderToRgb node and multiply that over a color then plugged to a emission shader.
It’s broadly the same technique as this tutorial but with an emission instead of the transparent node :

It will be quite dependent on the lighting… unfortunatly I’m not sure there is a better way to do this without relying on renderlayers and compositing…

Thanks for the suggestions.