Yes, you could manipulate the gradients manually of any layer using the previous code snippet or you could also use hooks (via register_hook), which might be cleaner especially if you are using multiple layers.