tylermorganwall / rayrender

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

How to get started as someone who has no experience with R #19

Closed define-private-public closed 1 year ago

define-private-public commented 3 years ago

Hi,

IIRC, this rendering is based off the code from the Peter Shirley ray tracing mini-books. I've recently finished running through the books myself. My implementation (I'm be publishing it soon) was much more performant and I'd like to contribute some of the changes to this project. I think it's really cool.

Though, I have next to zero experience with R. I have no idea where to get started. What the path of least resistance to be able to get rayrender up and running (from source)? And do you have any readily available scenes that I can render to do performance comparing?

tylermorganwall commented 3 years ago

I would first install R/RStudio (which has the best dev environment for R currently):

https://www.r-project.org https://rstudio.com

You will have to install RTools if you are on windows to install from source:

https://cran.r-project.org/bin/windows/Rtools/

And then follow the instructions on the README to install rayrender from the latest source:

install.packages("remotes")
remotes::install_github("tylermorganwall/rayrender")
library(rayrender)

There are lots of example scenes in the documentation--see the package website (click functions and then look at individual function docs for examples):

http://www.rayrender.net

define-private-public commented 3 years ago

When this project builds for release, what flags does it supply to the compiler? And what compiler (and version) does it use?

define-private-public commented 3 years ago

I tried doing the remotes::install_github("tylermorganwall/rayrender"), but was met with the following error:

Error: Failed to install 'rayrender' from GitHub:
  (converted from warning) package ‘raster’ is not available (for R version 3.4.4)

I'm running on the R/RStudio for Ubuntu 18.04.

Is there some way to use the rendering engine directly from C++ instead of doing it through R?

tylermorganwall commented 3 years ago

I would download a newer version of R first (at least 3.6.3)—3.4.4 is fairly old at this point. The raster package should be available for newer versions: type install.packages("raster") before trying to install rayrender.

The scene construction routine is tightly coupled to the underlying R C API, so it would be difficult to separate them.

define-private-public commented 3 years ago

Hey, interested in pursuing this again.

On my Windows partition, I was able to get RStudio and rayrender working, along with one of the renders to well, render. Some questions:

  1. If I were to make a change to the source, how would I go about compiling and then getting RStudio to use that version, versus how I installed it as the README says?
  2. Is there a testing suite setup? That way if I make a change, I can verify that it doesn't introduce any new bugs
  3. Along with the testing suite, what is the best way to benchmark a render?
tylermorganwall commented 3 years ago

Glad you got it working!

  1. Clone the package, load it as a project in RStudio, and go to the build menu and select "Clean and Rebuild" for a fresh install. You can then run iterative builds by hitting Ctrl-Shift-B.
  2. I haven't had any formal testing set-up since I haven't had many other contributors, currently I just build all the e. It's not too hard to put one together in R, though: I'll work on that.
  3. If you set verbose = TRUE in render_scene(), it will return an overall breakdown of the rendering time. For a more consistent benchmark, install the microbenchmark package:
install.packages("microbenchmark")
library(microbenchmark)
microbenchmark({
  ...code goes here... 
}, times=10
)
define-private-public commented 3 years ago

Thanks, I'll give that a try next.

The renders that are produced, are they fully deterministic? E.g. If I render one scene at 100x100 pixels, with 10 samples per pixel, then say, render it again. All generated pixels of the second render will match the first one by 100%? Or will there be some differences? What if I do the first render with one core, but then do the second render with 8?

define-private-public commented 3 years ago

I've never used idfiff before, but it seems like something you could easy make a test suite with to compare renders vs. a reference. https://openimageio.readthedocs.io/en/latest/idiff.html

tylermorganwall commented 3 years ago

To make it deterministic, you need to set a seed prior to running your code, e.g.


library(rayrender)
set.seed(1)
generate_cornell() %>% render_scene()

# This should result in the same image
set.seed(1)
generate_cornell() %>% render_scene()

Using a different number of cores will also result in a different image, since each thread will be seeded with its own independent seed.

tylermorganwall commented 3 years ago

The latest commits include a test directory. Install the testthat package (via install.packages("testthat")) and, after implementing your changes, run testthat::test_package("rayrender") to detect any regressions/changes from your local branch. The tests aren't comprehensive, but they should be able to detect any significant changes in behavior.