You might find the CustomMaterial class useful for this (API doc, examples). Maybe something like below for example.