Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@pratapvardhan pratapvardhan commented Jul 19, 2020

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

@tylermorganwall

This comment has been minimized.

Copy link
Owner Author

@tylermorganwall tylermorganwall commented Jul 19, 2020

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

@dieza

This comment has been minimized.

Copy link

@dieza 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

This comment has been minimized.

Copy link
Owner Author

@tylermorganwall tylermorganwall commented Jul 22, 2020

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

remotes::install_github("tylermorganwall/rayrender")
@ghost

This comment has been minimized.

Copy link

@ghost 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

This comment has been minimized.

Copy link
Owner Author

@tylermorganwall tylermorganwall commented Jul 26, 2020

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

remotes::install_github("tylermorganwall/rayimage")
@dieza

This comment has been minimized.

Copy link

@dieza 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

This comment has been minimized.

Copy link
Owner Author

@tylermorganwall tylermorganwall commented Jul 27, 2020

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