For doing this type of work programmatically in R, check out the rayshader package:
It has a high-quality pathtracing renderer built-in (https://www.rayrender.net) that only requires a single line of R code to produce results similar to what's offered here (without all the manual work).