Skip to content

Instantly share code, notes, and snippets.

@tylermorganwall
Last active July 27, 2020 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylermorganwall/7f31a10f22dc5912cc86b8b312f6f335 to your computer and use it in GitHub Desktop.
Save tylermorganwall/7f31a10f22dc5912cc86b8b312f6f335 to your computer and use it in GitHub Desktop.
Rayshader Render Highquality with Realistic Water
library(rayrender)
library(rayshader)
sizetex = 4000
zval = 100*sinpi(1:360/180)
coordss = expand.grid(x=1:sizetex,y=1:sizetex)
snow_palette = "white"
snow_hs = height_shade(montereybay, texture = snow_palette)
montereybay %>%
sphere_shade(zscale=10, texture = "desert") %>%
add_overlay(generate_altitude_overlay(snow_hs, montereybay, 500, 1200, lower=FALSE)) %>%
add_overlay(generate_line_overlay(monterey_roads_sf, linewidth=5, color="red", heightmap = montereybay,
extent = attr(montereybay,"extent"),height = 6*nrow(montereybay),
width = 6*ncol(montereybay)), alphalayer=0.8, rescale_original = TRUE) %>%
plot_3d(montereybay,triangulate = TRUE,max_error = 1, shadow=FALSE,fov=70)
camvals = do.call(cbind,(tweenr::tween(list(c(-100,50,100),c(-200,300,200)),n=360, ease="cubic-in-out")))
for(i in seq(1,360,by=1)) {
vals = ambient::gen_simplex(coordss[,1],coordss[,2],z=i/30,frequency = 0.1,seed = 1) +
ambient::gen_simplex(coordss[,1],coordss[,2],z=i/30,frequency = 0.1*2,seed = 2)/2 +
ambient::gen_simplex(coordss[,1],coordss[,2],z=i/30,frequency = 0.1*4,seed = 3)/4
vals = scales::rescale(vals,to=c(0,1))
water_bump = matrix(vals,sizetex,sizetex)
render_highquality(light = FALSE, aperture=0.2,
camera_location = as.vector(camvals[i,]),camera_lookat = c(0,30,0),
sample_method = "stratified", cache_filename = "cached", filename=glue::glue("dive{i}"),
environment_light = "kiara_3_morning_4k.hdr",
scene_elements = cube(xwidth=540,zwidth=540,y=2, ywidth=39,
material=dielectric(refraction = 1.33, bump_texture = water_bump,
attenuation = c(1,1,0.3)/2)))
}
@pratapvardhan
Copy link

@tylermorganwall -- attempting to reproduce this gist. What would you suggest undefined variable bigmb be?

@tylermorganwall
Copy link
Author

That should just be montereybay here, it's fixed now

@dieza
Copy link

dieza commented Jul 22, 2020

Trying to reproduce this cool gist, I got this error
Error in dielectric(refraction = 1.33, bump_texture = water_bump, attenuation = c(1, :
unused arguments (bump_texture = water_bump, attenuation = c(1, 1, 0.3)/2)

@tylermorganwall
Copy link
Author

You need to update to the latest version of the rayrender package:

remotes::install_github("tylermorganwall/rayrender")

Copy link

ghost commented Jul 26, 2020

Trying to reproduce and got this error:

Error in rayimage::add_image_overlay(hillshade, overlay, alpha = alphalayer,  : 
  unused argument (rescale_original = rescale_original)

@tylermorganwall
Copy link
Author

You need to update to the latest version of the rayimage package:

remotes::install_github("tylermorganwall/rayimage")

@dieza
Copy link

dieza commented Jul 27, 2020

You need to update to the latest version of the rayrender package:

remotes::install_github("tylermorganwall/rayrender")

Thanks,
Now, I get no errors but I don't see the water yet. I got warnings:
50 identical warnings:
In rayrender::render_scene(scene, lookfrom = lookfrom, ... :
file 'kiara_3_morning_4k.hdr' cannot be found, not using background image.
Cheers

@tylermorganwall
Copy link
Author

That's a HDR image file that you need to download to your computer. Go to hdrihaven.com for free HDR images

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment