Blender use object as mask for texturing?

duck-fs8.png-GwSHlF14806CTZ7-md

Texture Coordinates > Gradient Texture > Color Ramp > Mix (Fac)

This behaves a bit unpredictable (could be 2.8 issue).

raca2.md.jpg

Edit: ^ Scrot lost.