tylermorganwall / rayshader

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

render_highquality() results in black image [BUG] #264

Open ctotti opened 1 year ago

ctotti commented 1 year ago

Describe the bug I'm following an youtube florida tutorial. The height_shade(), plot_3d() and render_camera() functions all run without problem. When I get to render_highquality() though, it runs and it seems to work fine, but when I check my folder the saved test_plot.png image is completely black, and it doesn't generate any erros on the Console.

I alread tried reinstalling rayshader with both devtools and remotes, but so far when I run my code I keep running into the same issue.

Session Info R version 4.2.2 (2022-10-31 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045)

rayimage 0.9.1 2023-01-27 [1] Github (tylermorganwall/rayimage@0d24441) rayrender 0.29.4 2023-01-27 [1] Github (tylermorganwall/rayrender@e1f8951) rayshader * 0.34.5 2023-01-27 [1] Github (tylermorganwall/rayshader@03dd1d3)

library(rayshader)

# code :
render_highquality(
  filename = 'Images_render/test_plot.png',
  width = 270,
  height = 270,
  interactive = FALSE)
tylermorganwall commented 1 year ago

Did you post the full code? Calling render_highquality() without plot_3d() first will not produce any images, as there is no scene to render.

E.g. what does the following produce:

volcano |>
  sphere_shade() |>
  plot_3d(volcano)

render_highquality()
ctotti commented 1 year ago

Sorry, I didn't post the full code before. I'll attach it bellow, but yes I used plot_3d(). I ran your code and it generates an error message:

Error in rayrender::render_scene(scene, lookfrom = lookfrom, lookat = camera_lookat, : Must specify a minimum width/height of 3 or more pixels

So I tried specifying the width and height inside of render_highquality() like I did before, and the result was also a black image.

Note: The first part of the code (plot_3d() and render_camera()) plots without problem. The error only occurs to the render_highquality() function.

Edit: I ran the volcano test code again and this time it ran without any problems. But I still get the same error when trying to render_highquality() the mat data.

Full code:


swatchplot(c1)

texture <- colorRampPalette(c1, bias = 2)(256)
swatchplot(texture)

mat |>
  height_shade(texture = texture) |>
  plot_3d(heightmap = mat,
          zscale = 100,       
          shadowdepth = 0,    
          solid = FALSE)

render_camera(                
  theta = -20,                
  phi = 45,                  
  zoom = .8
)

render_highquality(
  filename = 'Images_render/test_plot.png',
  width = 270,
  height = 270,
  interactive = FALSE)
ctotti commented 1 year ago

Hi! This is a quick update with the solution that I found that worked for me. I still don't know why I was getting that error, BUT I found that if I take the render_camera() function out of the equation and instead use the theta, phi and zoom arguments inside of the plot_3d() function, then both plot_3d() and render_highquality() work without any problems and it renders just fine.

I'll show the code bellow. I also just wanted to thank you for taking your time to answer here, I appreciate it!


mat %>%
  height_shade(texture = texture) %>%
  plot_3d(heightmap = mat,
          zscale = 100 / 2,            
          solid = FALSE,
          shadowdepth = 0,
          theta = -20, 
          phi = 45, 
          zoom = .8)                   

outfile <- "Images_render/final_plot6.png"

{
  start_time <- Sys.time()
  cat(crayon::cyan(start_time), "\n")
  if (!file.exists(outfile)) {
    png::writePNG(matrix(1), target = outfile)
  }
  render_highquality(width = 1080,
                     height = 1080,
                     filename = outfile,
                     samples = 360,
                     interactive = FALSE,
                     lightdirection = 280,
                     lightaltitude = c(20, 80),
                     lightcolor = c(c1[2], "white"),
                     lightintensity = c(600, 100))
  end_time <- Sys.time()
  diff <- end_time - start_time
  cat(crayon::cyan(diff), "\n")
  }