tylermorganwall / rayshader

R Package for 2D and 3D mapping and data visualization
https://www.rayshader.com/
2.05k stars 211 forks source link

Feature request: a solidalpha argument to plot_3d #74

Closed jsta closed 2 years ago

jsta commented 5 years ago

There is a wateralpha argument but for some bathymetry applications it would be nice to "see through" the land. I can get part of the way there by "cutting out" the land but this requires some careful manipulations (https://twitter.com/tylermorganwall/status/1074652024187351041?s=20). Is it possible to set a solidalpha?

jsta commented 5 years ago

I added this feature in my branch on the linked PR. Compare the lake on the left with solidalpha = 1 (the current default) against the lake on the right with solidalpha=0.1

tex <- create_texture("#AFEEEE", "#B0C4DE", "#B0E2FF", "#B2DFEE", "#BCD2EE")
rmat %>%
  sphere_shade(texture = tex) %>%
  plot_3d(rmat, water = TRUE, waterdepth = maxdepth,
          zscale = 0.2, solidcolor = "white", solidalpha = 0.1,
          shadow = FALSE, solidlinecolor = "white", phi = 20)

solidalpha

tylermorganwall commented 5 years ago

Can you provide the rmat sample dataset? I'm a little confused about the need to see through the ground and the above image is a little too small for me to see what's going on.

jsta commented 5 years ago

Sure, here is a reproducible example. It's not the same rmat as above but it illustrates the issue I'm having where I want to see lake bathymetry but having opaque land blocks me from seeing it.

library(rayshader)

rmat <- read.csv(url("https://docs.google.com/spreadsheets/d/e/2PACX-1vT4ePN6nkzKFkqCnlentHkKx-3Ugn7uIy486bMoqtazW9R9SIiipJ1if7-YgzIAcm1d4O1oNq_eSP8x/pub?gid=556110853&single=true&output=csv"))
rmat <- as.matrix(rmat)

tex <- create_texture("#AFEEEE", "#B0C4DE", "#B0E2FF", "#B2DFEE", "#BCD2EE")

sphere_shade(rmat, texture = tex) %>%
  plot_3d(rmat, water = TRUE, waterdepth = 152.997,
          zscale = 0.4, solidcolor = "white", solidalpha = 0.4,
          shadow = FALSE, solidlinecolor = "white", phi = 20)

sphere_shade(rmat, texture = tex) %>%
  plot_3d(rmat, water = TRUE, waterdepth = 152.997,
          zscale = 0.4, solidcolor = "white", solidalpha = 1,
          shadow = FALSE, solidlinecolor = "white", phi = 20)

solidalpha

tylermorganwall commented 2 years ago

I don't think this feature would work well with the limitations of rgl and multiple transparent layers.