Skip to content

Instantly share code, notes, and snippets.

@tylermorganwall
Last active July 27, 2020 13:39
Show Gist options
  • 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)))
}
@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