rayrender icon indicating copy to clipboard operation
rayrender copied to clipboard

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

Open define-private-public opened this issue 5 years ago • 10 comments

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?

define-private-public avatar Oct 01 '20 01:10 define-private-public

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

tylermorganwall avatar Oct 03 '20 18:10 tylermorganwall

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 avatar Oct 06 '20 13:10 define-private-public

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?

define-private-public avatar Oct 07 '20 22:10 define-private-public

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.

tylermorganwall avatar Oct 28 '20 16:10 tylermorganwall

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?

define-private-public avatar Apr 16 '21 01:04 define-private-public

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
)

tylermorganwall avatar Apr 16 '21 21:04 tylermorganwall

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 avatar Apr 17 '21 01:04 define-private-public

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

define-private-public avatar Apr 17 '21 01:04 define-private-public

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 avatar Apr 17 '21 02:04 tylermorganwall

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.

tylermorganwall avatar Apr 18 '21 00:04 tylermorganwall