tylermorganwall / rayrender

A pathtracer for R. Build and render complex scenes and 3D data visualizations directly from R
http://www.rayrender.net
622 stars 43 forks source link

inconsistent shaded area with increasing light source distance #32

Closed bvasunr closed 2 years ago

bvasunr commented 2 years ago

Hi Tyler,

I use rayrender to render shading simulations of panels on crops. I recently updated the package and could not replicate some plots.

Shade projection seems to be inconsistent when the light source moves away. Here is a simple and reproducible example with a post and a light sphere.

light_x = -100 light_y = 100 original

light_x = -1000 light_y = 1000 x10

I expected the shade to be the same as original (1st plot), not disappearing from the ground. The shaded surface decreases with the light source distance from the post.

light_x = -2000 light_y = 2000 x20

I am still not sure this is a real issue, or if I misread the updated documentation. I'll be happy to delete this post if it's not an issue.

I keep exploring the problem.

Full code ```r post_shade <- function(light_x, light_y, light_radius, light_intensity) { generate_ground(depth = 0, material = diffuse(color = "chocolate")) %>% add_object( cube( x = 0, y = 2, z = 0, xwidth = 0.5, zwidth = 0.5, ywidth = 4, material = diffuse(color = "gray15"))) %>% add_object( sphere( x = light_x, z = 0, y = light_y, radius = light_radius, material = light(intensity = light_intensity)) ) %>% render_scene(lookfrom = c(0, 10, 20), lookat = c(0, 0, 0), samples = 100, fov = 30, clamp_value = 10, ambient_light = T) } post_shade(light_x = -100, light_y = 100, light_radius = 1, light_intensity = 5e3) # x 10 post_shade(light_x = -1000, light_y = 1000, light_radius = 10, light_intensity = 1e4) # x 20 post_shade(light_x = -2000, light_y = 2000, light_radius = 20, light_intensity = 1e4) ```
sessionInfo() R version 4.1.2 (2021-11-01) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19044) Matrix products: default locale: [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252 LC_NUMERIC=C [5] LC_TIME=French_France.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] avmotion_0.0.3 furrr_0.2.3 future_1.23.0 testthat_3.1.1 rayrender_0.24.0 forcats_0.5.1 stringr_1.4.0 [8] dplyr_1.0.7 purrr_0.3.4 readr_2.1.1 tidyr_1.1.4 tibble_3.1.6 ggplot2_3.3.5 tidyverse_1.3.1 loaded via a namespace (and not attached): [1] fs_1.5.2 usethis_2.1.5 timezone_0.1 lubridate_1.8.0 devtools_2.4.3 RColorBrewer_1.1-2 [7] httr_1.4.2 rprojroot_2.0.2 tools_4.1.2 backports_1.4.1 utf8_1.2.2 rgdal_1.5-28 [13] R6_2.5.1 rgeos_0.5-9 DBI_1.1.2 colorspace_2.0-2 raster_3.5-11 withr_2.4.3 [19] sp_1.4-6 prettyunits_1.1.1 tidyselect_1.1.1 processx_3.5.2 compiler_4.1.2 cli_3.1.0 [25] rvest_1.0.2 xml2_1.3.3 desc_1.4.0 scales_1.1.1 callr_3.7.0 digest_0.6.29 [31] rmarkdown_2.11 jpeg_0.1-9 pkgconfig_2.0.3 htmltools_0.5.2 sessioninfo_1.2.2 parallelly_1.30.0 [37] solaR_0.46 dbplyr_2.1.1 fastmap_1.1.0 rlang_0.4.12 readxl_1.3.1 rstudioapi_0.13 [43] generics_0.1.1 zoo_1.8-9 jsonlite_1.7.2 rayimage_0.6.2 magrittr_2.0.1 Rcpp_1.0.7 [49] munsell_0.5.0 fansi_0.5.0 lifecycle_1.0.1 terra_1.4-22 stringi_1.7.6 yaml_2.2.1 [55] pkgbuild_1.3.1 grid_4.1.2 parallel_4.1.2 listenv_0.8.0 crayon_1.4.2 lattice_0.20-45 [61] haven_2.4.3 hms_1.1.1 magick_2.7.3 ps_1.6.0 knitr_1.37 pillar_1.6.4 [67] codetools_0.2-18 pkgload_1.2.4 reprex_2.0.1 glue_1.6.0 evaluate_0.14 latticeExtra_0.6-29 [73] remotes_2.4.2 modelr_0.1.8 png_0.1-7 vctrs_0.3.8 tzdb_0.2.0 cellranger_1.1.0 [79] gtable_0.3.0 assertthat_0.2.1 cachem_1.0.6 xfun_0.29 broom_0.7.11 memoise_2.0.1 [85] globals_0.14.0 ellipsis_0.3.2
tylermorganwall commented 2 years ago

Thanks for the bug report! This has been fixed in 78c63a3bd9200fb8b0e8bf6819fe654bebfae60e.