library(quadmesh)
library(ggplot2)
library(raster)
## Loading required package: sp
r <- raster::raster(volcano %/% 10)

tb <- as.data.frame(r, xy = TRUE)
#png("file.png", width = 100, height = 100)
ggplot(tb, aes(x, y, fill = layer))+ geom_raster() + 
  theme_dark() + 

  theme(plot.background = element_rect(fill = "black"))

#dev.off()
ggsave("file.png")
## Saving 7 x 5 in image
r <- raster::setExtent(r, raster::extent(0, nrow(r), 0, ncol(r)))
b <- raster::brick("file.png")

## set all white to black
towhite <- function(x) {
  x[x == 255] <- 0
  x
}
values(b) <- towhite(values(b))

r1 <- aggregate(b, fact = 8, method = "ngb")
v <- values(r1)
r1 <- raster::setValues(r1[[1]], (v[,1]+ v[,2]^2 + v[,2]^3)  / 2^24)
rgl::rgl.clear()
## Warning in rgl.init(initValue, onlyNULL): RGL: unable to open X11 display
## Warning: 'rgl_init' failed, running with rgl.useNULL = TRUE
rgl::shade3d(quadmesh(r1, texture = b), lit = FALSE)
## writing texture image to /tmp/Rtmp3vgWBc/file14df1cad4b40.png
rgl::aspect3d(1, 1, 0.2)
rgl::rglwidget()